0

I'm a complete noob so bear with me please -

Currently users can add markers and my plan is to use the ondraw event to get the marker lat/lng and store that in mongodb, however i don't know how to get the individual markerID - ._leaflet_id returns same id for every marker. But if i generate id for the marker using something like Date.now() how can i fetch that id from db if a user clicks on a marker? Each marker needs to be unique since each one will have a different redirect for onclick().

Thank you

kboul
  • 13,836
  • 5
  • 42
  • 53

1 Answers1

0

I had a similar issue sometime back. What I did was create a table with [unique key id] and another column as markerJson,

var marker = new L.Marker([0, 0]);
// Get the GeoJSON object
var geojson = marker.toGeoJSON();

which has the following

{
    "type":"Feature",
    **"properties":{},**
    "geometry":{
        "type":"Point",
        "coordinates":[0,0]
    }
}

Save the above json in markerjson Column created above. You can see in the json above the properties feature "properties":{}, does the logic from db fetch and append the [unique key id] to properties "properties":{} e.g "properties":{unique-key_id:28}, now user can access the unique id from properties.


But in the case above on creating an event, the create event has properties{} feature, just append _leaflet_id to properties with the generated Id with Date.now().

wazz
  • 4,953
  • 5
  • 20
  • 34
dfire
  • 1
  • 1