Changing instance of Feature on click

60 Views Asked by At

Im trying to find a way to change the instance of a Leaflet geoJson Feature after it is added to the map.

This is what I want to achieve:

Importing data with L.GeoJson and I am using pointToLayer to change the marker to L.CircleMarker

Now I want

layer.on('click', function (e) {
   e.target //Do something here to change it from L.CircleMarker to L.Marker
});

Any idea how to achieve this?

1

There are 1 best solutions below

2
On
var group = L.geoJSON(); // Your geojson group on importing
layer.on('click', function (e) {
   var circlemarker = e.target //Do something here to change it from L.CircleMarker to L.Marker
   var marker = L.marker(circlemarker.getLatLng()).addTo(group);
   marker.feature = circlemarker.feature
   circlemarker.removeFrom(group)
   // Then add the same events to the layer as in pointToLayer
});