Create a draggable marker

Drag the Marker to a new location on a map and populate its coordinates in a display.

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const coordinates = document.getElementById('coordinates');
const map = new Map({
    container: 'map',
    style: MapStyle.STREETS,
    center: [0, 0],
    zoom: 2
});

const marker = new maptilersdk.Marker({
    draggable: true
})
    .setLngLat([0, 0])
    .addTo(map);

function onDragEnd() {
    const lngLat = marker.getLngLat();
    coordinates.style.display = 'block';
    coordinates.innerHTML =
        'Longitude: ' + lngLat.lng + '<br />Latitude: ' + lngLat.lat;
}

marker.on('dragend', onDragEnd);
Create a draggable point

Create a draggable point

Examples

Create a draggable point and display its map coordinates.

Animate a point along a route

Animate a point along a route

Examples

Smoothly animate a point along a route using Turf.

Animate a point

Animate a point

Examples

Animate a point position using GeoJSON frame updates.

Display a popup on click

Display a popup on click

Examples

Display a popup when a user clicks a symbol.

Was this helpful?