How to pass custom data in leaflet markers/circle markers using javascript

Recently I came across the situation where I had multiple circle markers at same position on map.

Then How can I identify that which marker is clicked when I click on that position on map ?

So I thought cant we pass some custom data with markers & I found way of doing it.

We just have to extend the CircleMarker/ Marker.

Bellow is the way to do it.

var customCircleMarker = L.CircleMarker.extend({
   options: { 
      customPro1: '',
      customPro2: ''
   }
});

Here I am extending circlemarker & adding two new options customPro1 & customPro2.

Now instead to creating circlemarker we will create instance of customCircleMarker & will add it to map.

var myMarker = new customCircleMarker(myPoint, { 
    title: 'unselected',
    radius: 20,
    customPro1: 'some value',
    customPro2: 'some other value'
});
myMarker.addTo(map);

Same can be done for Markers also.

admin