Skip to content

Commit 9a12952

Browse files
authored
Monkey-patch _featureGroup.addLayer in markerClusterGroup to disable pm (#1249)
1 parent 979ad36 commit 9a12952

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

python/jupyter_leaflet/src/layers/MarkerCluster.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,29 @@ export class LeafletMarkerClusterView extends LeafletLayerView {
7171

7272
create_obj() {
7373
const options = this.get_options();
74-
this.obj = L.markerClusterGroup(options);
74+
75+
// Intercept the creation of the cluster group to disable leaflet.pm
76+
// (so that GeomanDrawControl will not be able to edit it)
77+
const clusterGroup = L.markerClusterGroup(options);
78+
const originalAddLayer = (clusterGroup as any)._featureGroup.addLayer;
79+
(clusterGroup as any)._featureGroup.addLayer = function (layer: L.Layer) {
80+
if (
81+
// A cluster "bubble" is a marker with a child count
82+
layer instanceof L.Marker &&
83+
typeof (layer as any).getChildCount === 'function'
84+
) {
85+
(layer as any).pmIgnore = true;
86+
// Disable the leaflet.pm functionality for the cluster bubble
87+
if ((layer as any).pm) {
88+
(layer as any).pm.disable();
89+
delete (layer as any).pm;
90+
}
91+
}
92+
93+
return originalAddLayer.call(this, layer);
94+
};
95+
this.obj = clusterGroup;
96+
7597
this.marker_views = new ViewList(
7698
this.add_layer_model,
7799
this.remove_layer_view,

0 commit comments

Comments
 (0)