[Leaflet Mobile Plugin] How to change location of markers dynamically?

Forge Component
(0)
Published on 12 Oct (5 days ago) by Vincent Koning
0 votes
Published on 12 Oct (5 days ago) by Vincent Koning

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.

Do you mean by dragging the marker ?

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

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.

Solution

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