79
Views
5
Comments
Solved
[Leaflet Mobile Plugin] How to change location of markers dynamically?
Question
Forge component by Diogo Pires
2
Published on 12 Oct 2019

Hello.

Is it possible to change location of a marker dynamically (by an event)? I didn't find changeMarker of deleteMarkr functions in the plugin.

Solution

Stefano Valente wrote:

Do you mean by dragging the marker ?


I mean by changing lat, lon parameters of marker.

I found out in the documentation to the LeafletJS library that there is a method setLatLon of the object Marker. 

First careate js script text:

"var myLatLonObject = L.latLng(" + EncodeJavaScript(MyLocation.Latitude) +", " + EncodeJavaScript(MyLocation.Longitude) + "); " +
EncodeJavaScript(MyPositionMarkerName) + ".setLatLng(myLatLonObject);"

Second run this script by eval($parameters.Script);


Is works.

Rank: #238

Do you mean by dragging the marker ?

Rank: #735

You can delete the previously created marker, before creating a new  one by adding below code in AddMarker


If(DeleteOldMarker, (EncodeJavaScript(LeafletMapName) + ".removeLayer("+EncodeJavaScript(Marker.Name) +");"),"")

You can also use the Hide and Show actions

I'll try to free up some time this weekend and update the component to include this function :)