Skip to content

Commit

Permalink
more patch/checks
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Oct 13, 2023
1 parent 018fff5 commit 747f336
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions addon/services/leaflet-contextmenu-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,42 @@ export default class LeafletContextmenuManagerService extends Service {
* @param {Array} contextmenuItems - An array of context menu items to bind.
*/
rebindContextMenu(layer, contextmenuItems = []) {
const registry = this.findRegistryByLayer(layer);
// make sure layer is instance of leaflet
if (!(layer instanceof L.Layer)) {
return;
}

later(
this,
() => {
if (typeof layer.unbindContextMenu === 'function') {
layer.unbindContextMenu().bindContextMenu({
contextmenu: true,
contextmenuItems,
});
} else {
// just bind
layer.bindContextMenu({
contextmenu: true,
contextmenuItems,
});
}
const registry = this.findRegistryByLayer(layer);

// if found registry update layer and contextmenu api
if (registry) {
registry.layer = layer;
registry.contextmenuApi = layer.contextmenu;
}
},
300
);
if (registry) {
later(
this,
() => {
try {
if (typeof layer.unbindContextMenu === 'function') {
layer.unbindContextMenu().bindContextMenu({
contextmenu: true,
contextmenuItems,
});
} else {
// just bind
layer.bindContextMenu({
contextmenu: true,
contextmenuItems,
});
}
} catch (error) {
// silence
}

// if found registry update layer and contextmenu api
if (registry) {
registry.layer = layer;
registry.contextmenuApi = layer.contextmenu;
}
},
300
);
}
}
}

0 comments on commit 747f336

Please sign in to comment.