SINTEF-9012 / PruneCluster

Fast and realtime marker clustering for Leaflet
MIT License
552 stars 131 forks source link

Is it possible to add an id to the Markers. #174

Open TZAdvantage opened 5 years ago

TZAdvantage commented 5 years ago

I tried to find how to do it but could not find a solution.

I got my particular use working by adding an id property in the icon options.

    {
         id: vehicle.id
    }

and adding this to the code in ProcessView:

    creationMarker.addTo(map);
    //*** TZAdvantage add id attribute to icon.
    if (creationMarker._icon) {
         creationMarker._icon.id = creationMarker.options.icon.options.id;
    }

Am i overlooking something?

raph-tr commented 4 years ago

hi, here is how i do it :

$.each( data, function( key, val ) {
    var marker = new PruneCluster.Marker(
                        val.latLng[0],val.latLng[1] ,
                        {
                            id: key,
                            cat: 'site',
                            name : val.name
                        }
                    );
    sitesCluster.RegisterMarker(marker);
});
map.addLayer(sitesCluster);

according to https://github.com/SINTEF-9012/PruneCluster#add-custom-data-to-marker-object hope it helps

raph-tr commented 4 years ago

hmm, by "marker" do you mean the JS marker object (my first thought) or the icon on the map ?? if it is the second choice then my previous answer is not relevant...

lkgamor commented 3 years ago

You can try this approach too..

const marker = new PruneCluster.Marker(lat, lng, { popup: somePopup, icon: someIcon }); marker.data.id = key;