I see (at least) four ways of achieving this, none of them being really clean:
The (default) L.SVG
vector renderer applies the interactive
option only when a vector is added to the renderer. Thus, removing and re-adding the polygon should do the trick.
leafletGeoJsonLayer.on('click', function (e) {
e.layer.options.interactive = false;
leafletGeoJsonLayer.removeLayer(e.layer).addLayer(e.layer);
}
The (non-default) L.Canvas
renderer checks for the interactive
option at every pointer interaction. Thus, telling your GeoJSON vectors to draw inside a L.Canvas
should do the trick.
var canvasRenderer = L.canvas();
var leafletGeoJsonLayer = L.geoJson({
style: function() {
return { renderer: canvasRenderer, /* etc */ };
}
});
The (default) L.SVG
vector renderer relies on an internal addInteractiveTarget
/removeInteractiveTarget
logic to dispatch leaflet-decorated events to the appropriate objects. It's possible to manually detach the SVG DOM node for the polygon for this logic, by reading the code of the L.SVG
renderer regarding removing a vector layer and using an undocumented private property of vector layers:
leafletGeoJsonLayer.on('click', function (e) {
e.layer.removeInteractiveTarget(e.layer._path);
}
The path will still dispatch pointer events, but they'll be detached from the Leaflet logic, and thus ignored by any event handlers set up for the GeoJSON
group.
Assuming a SVG renderer, since paths are actually DOM nodes (and the target of the original DOM events), it's possible to update their CSS properties. For this problem specifically, the pointer-events
CSS property is of interest.
leafletGeoJsonLayer.on('click', function (e) {
e.originalEvent.target.style.pointerEvents = 'none';
}
That should be equivalent to
leafletGeoJsonLayer.on('click', function (e) {
e.layer._path.style.pointerEvents = 'none';
}