124
Views
5
Comments
Solved
[Leaflet Mobile Plugin] How to change location of markers dynamically?
Question
leaflet-mobile-plugin
Mobile icon
Forge asset by Leaflet Mobile

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.

UserImage.jpg
Vyacheslav Buzivskyy
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.

2020-09-01 10-42-42
Stefano Valente

Do you mean by dragging the marker ?

UserImage.jpg
Vyacheslav Buzivskyy
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.

2019-11-05 11-01-40
Preeti Kumari

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) +");"),"")
2020-09-21 08-42-47
Vincent Koning

You can also use the Hide and Show actions

2020-09-21 08-42-47
Vincent Koning

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

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.