Source: https://maps.vietmap.vn/docs/sdk-web-gl/marker/example-marker/methods-marker/ # Methods ## addTo(map) Add marker to the map. ```js marker.addTo(map); ``` **** ## getLngLat() Get the current coordinates of the marker. This method useful when you want to click on a point on the map to display the marker and the coordinates of that location. ```js const marker = new vietmapGl.Marker({ draggable: true, color: '#25A18E', }) .setLngLat([106.675477, 10.758898]) .addTo(map); marker.on('dragend', () => { const lngLat = marker.getLngLat(); const longitude = lngLat.lng.toFixed(6); const latitude = lngLat.lat.toFixed(6); console.log('Kinh độ:', longitude); console.log('Vĩ độ:', latitude); }); ``` **** ## setLngLat() Set the marker to the specified location. ```js marker.setLngLat([106.67547751224498, 10.758898464351262]) ``` **** #### remove() Remove the marker from the map. ```js marker.remove(); ``` **** ## setElement Change the DOM element used as the marker. Allows you to customize the marker interface using `HTML` elements. ```js const markerElementEnd = document.createElement('div'); markerElementEnd.className = 'custom-marker-end'; const newMarkerEnd = new vietmapGl.Marker({ element: markerElementEnd, anchor: 'bottom', }) .setLngLat([endCoordinates.lng, endCoordinates.lat]) .addTo(mapRef.current); setMarkerEnd(newMarkerEnd); ``` **** ## getElement Get the current DOM element used as the marker. `HTMLElement`: element **** #### setDraggable(draggable: boolean): this Allow dragging and dropping the marker on the map. When draggable is true, you can drag and drop the marker on the map. ```js marker.setDraggable(true); ``` **** ## isDraggable() Check if the marker is in draggable mode. Returns true if the marker can be dragged. ```js const draggable = marker.isDraggable(); console.log(draggable); ``` **** ## on(event: string, handler: Function): this Assign an event handler to the marker. This allows you to perform actions when interacting with the marker. **Parameter** - event: The name of the event - handler: The function that will be called when the event occurs. ```js marker.on('dragend', () => { const lngLat = marker.getLngLat(); console.log('Longitude:', longitude); console.log('Latitude:', latitude); }); ``` **** ## off(event: string, handler: Function): this Remove the event handler assigned to the marker. **Parameter** - event: The name of the event - handler: The function that will be called when the event occurs. ```js const handleClick = () => { console.log('Click Marker'); }; marker.on('click', handleClick); marker.off('click', handleClick); ``` **** ## setRotation(rotation: number): this Allow setting the rotation of the marker when displayed on the map. ```js marker.setRotation(45); // Calculated in degrees ``` **** ## getRotation(): number Get the current rotation of the marker displayed on the map. ```js const rotation = marker.getRotation(); console.log(rotation); ```