diff --git a/README.md b/README.md index 505f01a..3d735be 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ contextmenu.on('open', function (evt) { - `defaultItems`: `true`; Whether the default items (which are: Zoom In/Out) are enabled - `width`: `150`; The menu's width - `items`: `[]`; An array of object|string +- `hideOnMove`: `true`; Whether the context menu should hide when the map moves as a result of user iteraction or programmatically. ## Methods diff --git a/src/constants.ts b/src/constants.ts index 4aab0fb..b2bb000 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -6,6 +6,7 @@ export const DEFAULT_OPTIONS: Options = { eventType: EventTypes.CONTEXTMENU, defaultItems: true, items: [], + hideOnMove: true, }; const NAMESPACE = 'ol-ctx-menu'; diff --git a/src/main.ts b/src/main.ts index 82cb9fe..ab040f4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -399,7 +399,9 @@ export default class ContextMenu extends Control { } protected handleMapMove() { - this.closeMenu(); + if (this.options.hideOnMove) { + this.closeMenu(); + } } protected handleEntryCallback(evt: MouseEvent) { diff --git a/src/types.ts b/src/types.ts index c911e21..7937c7e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,4 +64,5 @@ export type Options = { eventType: `${EventTypes}`; defaultItems: boolean; items: Item[]; + hideOnMove?: boolean; };