How to add one leaf marker to several groups?

I add markers to layer groups:

var lGroup1 = new L.FeatureGroup(),
    lGroup2 = new L.FeatureGroup(),
    lGroup3 = new L.FeatureGroup();

new compMarker([50.07045,8.24660]).bindPopup('<p>Something</p>').addTo(lGroup1).on('click', onClick);
new compMarker([50.07045,8.24660]).bindPopup('<p>Something</p>').addTo(lGroup2).on('click', onClick);
new compMarker([50.07045,8.24660]).bindPopup('<p>Something</p>').addTo(lGroup3).on('click', onClick);

As you can see, I am adding the same marker (identical content) to the three layers. Is there a way to do this without creating three identical markers? I would like to add one, but in several groups of layers.

I already tried this with no luck:

new compMarker([50.07045,8.24660]).bindPopup('<p>Something</p>').addTo(lGroup1,lGroup2,lGroup3).on('click', onClick);

Any help would be greatly appreciated!

+4
source share

Source: https://habr.com/ru/post/1627035/


All Articles