Basic TerraDraw setup
Firstly, we can setup Terra Draw without any UI interaction.
Open +page.svelte, add the following codes in the <script> tag section just under the other imports.
import { TerraDraw, TerraDrawRectangleMode } from 'terra-draw'
import { TerraDrawMapLibreGLAdapter } from 'terra-draw-maplibre-gl-adapter';
let draw: TerraDraw | undefined;
Then update the existing onMount() method to also intialize the TerraDraw library after the MapLibre map is created.
onMount(() => {
draw = new TerraDraw({
adapter: new TerraDrawMapLibreGLAdapter({ map }),
modes: [new TerraDrawRectangleMode()],
});
map.once('load', () => {
draw.start();
draw.setMode("rectangle");
})
})
You can draw a rectangle polygon on the map like below.
