ol-contextmenu 5.1.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.d.ts +10 -2
- package/dist/ol-contextmenu.css +2 -2
- package/dist/ol-contextmenu.iife.js +3 -3
- package/dist/ol-contextmenu.js +92 -76
- package/dist/ol-contextmenu.umd.cjs +3 -3
- package/dist/types.d.ts +7 -6
- package/package.json +12 -12
package/dist/main.d.ts
CHANGED
|
@@ -2,7 +2,12 @@ import type { Pixel } from 'ol/pixel';
|
|
|
2
2
|
import type { Coordinate } from 'ol/coordinate';
|
|
3
3
|
import OlMap from 'ol/Map';
|
|
4
4
|
import Control from 'ol/control/Control';
|
|
5
|
-
import
|
|
5
|
+
import BaseEvent from 'ol/events/Event';
|
|
6
|
+
import { EventsKey } from 'ol/events';
|
|
7
|
+
import { Types as ObjectEventTypes } from 'ol/ObjectEventType';
|
|
8
|
+
import { CombinedOnSignature, EventTypes as OlEventTypes, OnSignature } from 'ol/Observable';
|
|
9
|
+
import { ObjectEvent } from 'ol/Object';
|
|
10
|
+
import { ContextMenuEvent, CustomEventTypes, Item, MenuEntry, Options } from './types';
|
|
6
11
|
export default class ContextMenu extends Control {
|
|
7
12
|
protected map: OlMap;
|
|
8
13
|
protected container: HTMLDivElement;
|
|
@@ -16,6 +21,9 @@ export default class ContextMenu extends Control {
|
|
|
16
21
|
protected opened: boolean;
|
|
17
22
|
protected items: Item[];
|
|
18
23
|
protected menuEntries: Map<string, MenuEntry>;
|
|
24
|
+
on: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, EventsKey> & OnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}` | ObjectEventTypes | `${CustomEventTypes.CLOSE}` | OlEventTypes, EventsKey>;
|
|
25
|
+
once: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, EventsKey> & OnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}` | ObjectEventTypes | `${CustomEventTypes.CLOSE}` | OlEventTypes, EventsKey>;
|
|
26
|
+
un: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, void> & OnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, void> & CombinedOnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}` | ObjectEventTypes | `${CustomEventTypes.CLOSE}` | OlEventTypes, void>;
|
|
19
27
|
options: Options;
|
|
20
28
|
constructor(opts?: Partial<Options>);
|
|
21
29
|
clear(): void;
|
|
@@ -34,7 +42,7 @@ export default class ContextMenu extends Control {
|
|
|
34
42
|
protected removeListeners(): void;
|
|
35
43
|
protected removeMenuEntry(id: string): void;
|
|
36
44
|
protected handleContextMenu(evt: MouseEvent): void;
|
|
37
|
-
protected openMenu(): void;
|
|
45
|
+
protected openMenu(evt: MouseEvent): void;
|
|
38
46
|
protected getMenuEntriesLength(): number;
|
|
39
47
|
protected positionContainer(): void;
|
|
40
48
|
protected handleMapMove(): void;
|
package/dist/ol-contextmenu.css
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.1.
|
|
3
|
+
* ol-contextmenu - v5.1.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: Sat
|
|
5
|
+
* Built: Sat Nov 12 2022 12:41:10 GMT-0300 (Brasilia Standard Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
.ol-ctx-menu-container{position:absolute;padding:8px;background:#fff;color:#222;font-size:13px;border-radius:5px;box-shadow:#0003 3px 3px 5px;box-sizing:border-box}.ol-ctx-menu-container div,.ol-ctx-menu-container span,.ol-ctx-menu-container a,.ol-ctx-menu-container img,.ol-ctx-menu-container ul,.ol-ctx-menu-container li{margin:0;padding:0;border:0;font:inherit;font-size:100%;vertical-align:baseline}.ol-ctx-menu-container a img{border:none}.ol-ctx-menu-container *,.ol-ctx-menu-container *:before,.ol-ctx-menu-container *:after{box-sizing:inherit}.ol-ctx-menu-container.ol-ctx-menu-hidden{opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container ul{list-style:none}.ol-ctx-menu-container li{position:relative;line-height:20px;padding:2px 5px;white-space:nowrap}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;background-color:#333;color:#eee}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{border:1px solid #eee;padding:8px;top:0;opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{position:absolute;top:7px;right:10px;content:"";display:inline-block;width:.6em;height:.6em;border-right:.3em solid #222;border-top:.3em solid #222;transform:rotate(45deg)}.ol-ctx-menu-container li.ol-ctx-menu-submenu:hover:after{border-color:#eee}.ol-ctx-menu-container:not(.ol-ctx-menu-hidden) li.ol-ctx-menu-submenu:hover .ol-ctx-menu-container{opacity:1;visibility:visible;transition-delay:0s}.ol-ctx-menu-container li.ol-ctx-menu-separator{padding:0}.ol-ctx-menu-container li.ol-ctx-menu-separator hr{border:0;height:1px;background-image:linear-gradient(to left,rgba(0,0,0,0),rgba(0,0,0,.75),rgba(0,0,0,0))}.ol-ctx-menu-icon{text-indent:20px;background-size:20px auto;background-repeat:no-repeat;background-position:left center}.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABaUlEQVQ4T72U7VHCQBCGn90GtAMuNGCswFiBWIFQgWMFxg6wArECsQKhArEBiB1Qwa1zgQn5IAYcxv13k71n3919L8KJQ07M47+BzgG9TRfZ/JBuWhS6BJFHRJICYrZGZIz3z5Ct2+B7gG6I6kt+wewdkQVwjtkAkR5mC8yu26A1oItR/cTsOweQBdgutD8G7jGm2PJ2n8oqUKIpIjd4HxTM8gvaT/F+AlmWnyWaIXKF95eNguFzTYFhNsdWu9kFgFlaFMANUH3D8wDLoLgSTSD2il8NCe2ZXQBxWDGwxmyUzzOMBZ7wy7Qb2K0wQfXjMOBuhlFpZtNty5sFaTQBuTusZdymeqs1SpYKcO9HkE3KbTd9WFijMHJQ5hBNEAYNq5Qd0dhyke0GiE4QzjqfW23mHT8Hl4DG4Lce3FPE7AtbBSdsbNqpoJLgYkRnNeUV+xwJDHTnUEkxHGbhBXUs5TjJjew/KPy94g+NRaIVRYmMXwAAAABJRU5ErkJggg==)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABc0lEQVQ4T71U21ECQRDsJgGdvQDECMQIxAjECMQILCPwzAAjECIQI0AiEDPQAPaWCBhrcKHuCUcV5f7dY3v6tUscefHIePhfwBBCF8CZqRCReRs1tQxDCH1VfQLQz4EsSY4AvIjIsgm8AhhCGKrqa9zwrqoLAKckB5HtguR1E2gBMITQU9VPAD8GICIGtl3e+xHJBwBT59xtHcsCYJZlUwA3kcGHbfDep51OZywi3/acZZm9vyJ5WR5o38uACmDunNt6ZwAkUxFZDwghDFT1jeSjiJinhVUBVNVJkiTDKO8CQA+AsbNQ7s1Ps0VVn5MkSfcCtmBoDZi1Bdx4eJ7zbBolrwPy3o9J3rWSHPs3A1BbjVKlYBaIyDgvu9LDXDU2RTZmXVW1oKyLxRD+OrkOrJLy5mVM0iaftDhuhVbsvBzMglzKUNW6IV/OOWtCM8MmVvEkmbwt83LaB19fdgOtVquUZJeknaDdobTwbOcvBzPcN/AXH1DFFWP7u9oAAAAASUVORK5CYII=)}.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABU0lEQVQ4T72U7VECMRRFz3sNaAdkacC1AtcKxApcKnCsQOwAK3CtQKxAqEBsANYOqCDPyTIC+8WCw5jfybn33dxEOPGSE/P4b6BzQG89RT47ZJoWhy5B5BGRZAMxWyEyxvtnyFdt8AagS1F9KQ6YvSMyB84xGyDSw2yO2XUbtAJ0MaqfmH0XAPIA2y7tj4F7jAm2uG1yWQZKNEHkBu+Dg2njWBJNEbnC+8uaIFRuWfuG2QxbbrOrUd0A1Tc8D7AIjkur7DAAsVf8MiWMZ3ZR2m02LPIMscATfjHqBnY7TFD9OAy4zTCCPG/MUKMM5O6wkXFr9dZq7FQqqHk/hDzbFa73cFONTZFDdRyiCcKg5rrSiLaXkiI6RjjrfG6VzDs+B5eAxuDXeYpmNRGzL2wZ/wof+du4GNFpBVqqz5HA4MM5VEYYDrOs+1I6Q9u/4Q8O9wN/AGgWjBVqQjjgAAAAAElFTkSuQmCC)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABYklEQVQ4T72U4VHCQBCF36tA91KAWIFYgViBWIFYgWMFYgdYgVCBWAFSgdiBFpAsFWSdxcDkQoBkhnF/ZjbfvX377ogjF4/Mw/8CVbUD4MynEJF5k2lqFapqz8yeAPRKkCXJEYAXEVnugm8BVXVgZq/FD+9mtgBwSrJfqF2QvN4FjYCq2jWzTwA/DhARh20qTdMRyQcA0xDCbZ3KCJhl2RTATaHgo+6HLMv8+xXJy+qB3l8FGoB5CKHsXcRV1b6ZvZF8FBH3NKotoJlNkiQZFONdlLtJ3rufbouZPSdJMjwIbKDQEzBrClx7eC4i33Uepmk6JnnXaOQifzMAtdGoRApugYiMI1uqKkrRWAfZo9MxM1+UZzFewl8mN4nYdVM83L7BkwbXLUrF3sfBLQDQBbDy08x8vOohXyEE71lVq9emuEk+3gZa3XYroCvwFyjP8yHJDsnxwaU08GxvS2uFhw78BbzWrxXgMbsHAAAAAElFTkSuQmCC)}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.1.
|
|
3
|
+
* ol-contextmenu - v5.1.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: Sat
|
|
5
|
+
* Built: Sat Nov 12 2022 12:41:10 GMT-0300 (Brasilia Standard Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var ContextMenu=function(
|
|
8
|
+
var ContextMenu=function(m,h){"use strict";var H=Object.defineProperty;var U=(m,h,f)=>h in m?H(m,h,{enumerable:!0,configurable:!0,writable:!0,value:f}):m[h]=f;var r=(m,h,f)=>(U(m,typeof h!="symbol"?h+"":h,f),f);const S=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(m);var b=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(b||{}),d=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(d||{});class C extends h.MapBrowserEvent{constructor(s){super(s.type,s.map,s.originalEvent)}}const k={width:150,scrollAt:4,eventType:b.CONTEXTMENU,defaultItems:!0,items:[]},p="ol-ctx-menu",a={namespace:p,container:`${p}-container`,separator:`${p}-separator`,submenu:`${p}-submenu`,hidden:`${p}-hidden`,icon:`${p}-icon`,zoomIn:`${p}-zoom-in`,zoomOut:`${p}-zoom-out`,unselectable:"ol-unselectable"},A=[{text:"Zoom In",classname:`${a.zoomIn} ${a.icon}`,callback:(n,s)=>{const e=s.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${a.zoomOut} ${a.icon}`,callback:(n,s)=>{const e=s.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var N={exports:{}};function x(){}x.prototype={on:function(n,s,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:s,ctx:e}),this},once:function(n,s,e){var t=this;function i(){t.off(n,i),s.apply(e,arguments)}return i._=s,this.on(n,i,e)},emit:function(n){var s=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,i=e.length;for(t;t<i;t++)e[t].fn.apply(e[t].ctx,s);return this},off:function(n,s){var e=this.e||(this.e={}),t=e[n],i=[];if(t&&s)for(var o=0,c=t.length;o<c;o++)t[o].fn!==s&&t[o].fn._!==s&&i.push(t[o]);return i.length?e[n]=i:delete e[n],this}},N.exports=x;var T=N.exports.TinyEmitter=x;const y=new T;function v(n){const s=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)s.append(e.firstChild);return s}function _(n){const s=document.importNode(n),e=n.offsetWidth;s.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=v("<span>Foo</span>"),i=v("<span>Foo</span>"),o=document.createElement("li"),c=document.createElement("li");o.append(t),c.append(i),s.append(o),s.append(c),n.parentNode?.append(s);const E=s.offsetHeight/2;return n.parentNode?.removeChild(s),E}function $(n,s,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof s!="string"&&"text"in s){const E=`<span>${s.text}</span>`,M=v(E),l=document.createElement("li");return s.classname=s.classname||"",s.icon&&(s.classname===""?s.classname=a.icon:s.classname.includes(a.icon)===!1&&(s.classname+=` ${a.icon}`),l.setAttribute("style",`background-image:url(${s.icon})`)),l.id=t,l.className=s.classname,l.append(M),n.append(l),y.emit(d.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in s?s.callback:null,data:"data"in s?s.data:null},l),l}const i=`<li id="${t}" class="${a.separator}"><hr></li>`,o=v(i);n.append(o);const c=n.lastChild;return y.emit(d.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},c),c}function L(n,s,e){s.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const i=$(n,t,!0);i.classList.add(a.submenu);const o=document.createElement("ul");o.classList.add(a.container),o.style.width=`${e}px`,i.append(o),L(o,t.items,e)}else $(n,t)})}const F="";function w(n,s){if(!n)throw new Error(s)}class D extends S.default{constructor(e={}){w(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});r(this,"map");r(this,"container");r(this,"coordinate",[]);r(this,"pixel",[]);r(this,"contextMenuEventListener");r(this,"entryCallbackEventListener");r(this,"mapMoveListener");r(this,"lineHeight",0);r(this,"disabled");r(this,"opened");r(this,"items",[]);r(this,"menuEntries",new Map);r(this,"options");this.options={...k,...e};const i=document.createElement("ul");t.append(i),t.style.width=`${this.options.width}px`,t.classList.add(a.container,a.unselectable,a.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return A}countItems(){return this.menuEntries.size}extend(e){w(Array.isArray(e),"@param `items` should be an Array."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(a.hidden),this.dispatchEvent(d.CLOSE)}isOpen(){return this.opened}updatePosition(e){w(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){const e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){const e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,this.map.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.map.on("movestart",()=>{this.handleMapMove()}),y.on(d.ADD_MENU_ENTRY,(i,o)=>{this.handleAddMenuEntry(i,o)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:_(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),y.off(d.ADD_MENU_ENTRY)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new C({type:d.BEFOREOPEN,map:this.map,originalEvent:e})),!this.disabled&&(this.options.eventType===b.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(a.hidden),this.dispatchEvent(new C({type:d.OPEN,map:this.map,originalEvent:e})))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=i.w;const c=l=>Array.from(l.children).filter(g=>g.tagName==="LI"&&g.classList.contains(a.submenu));let E=0;const M=(l,g)=>{E+=1,c(l).forEach(O=>{const I=g>=i.w?i.w-8:(i.w+8)*-1,u=O.querySelector(`ul.${a.container}`),z=Math.round(this.lineHeight*Array.from(u.children).filter(P=>P.tagName==="LI").length);u.style.left=`${I}px`,u.style.right="auto",u.style.top=t.h>=z+i.h?"0":`-${u.offsetHeight-25}px`,u.style.bottom="auto",u.style.zIndex=String(E),c(u).length>0&&M(u,g-i.w)})};M(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,i=this.menuEntries.get(t.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return D}(ol.control.Control,ol);
|
package/dist/ol-contextmenu.js
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.1.
|
|
3
|
+
* ol-contextmenu - v5.1.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: Sat
|
|
5
|
+
* Built: Sat Nov 12 2022 12:41:10 GMT-0300 (Brasilia Standard Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var r = (s, t, e) => (
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
var k = Object.defineProperty;
|
|
9
|
+
var T = (s, t, e) => t in s ? k(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
10
|
+
var r = (s, t, e) => (T(s, typeof t != "symbol" ? t + "" : t, e), e);
|
|
11
|
+
import O from "ol/control/Control";
|
|
12
|
+
import { MapBrowserEvent as D } from "ol";
|
|
13
|
+
var M = /* @__PURE__ */ ((s) => (s.CONTEXTMENU = "contextmenu", s.CLICK = "click", s.DBLCLICK = "dblclick", s))(M || {}), d = /* @__PURE__ */ ((s) => (s.BEFOREOPEN = "beforeopen", s.OPEN = "open", s.CLOSE = "close", s.ADD_MENU_ENTRY = "add-menu-entry", s))(d || {});
|
|
14
|
+
class x extends D {
|
|
15
|
+
constructor(t) {
|
|
16
|
+
super(t.type, t.map, t.originalEvent);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const _ = {
|
|
14
20
|
width: 150,
|
|
15
21
|
scrollAt: 4,
|
|
16
22
|
eventType: M.CONTEXTMENU,
|
|
17
23
|
defaultItems: !0,
|
|
18
24
|
items: []
|
|
19
|
-
},
|
|
20
|
-
namespace:
|
|
21
|
-
container: `${
|
|
22
|
-
separator: `${
|
|
23
|
-
submenu: `${
|
|
24
|
-
hidden: `${
|
|
25
|
-
icon: `${
|
|
26
|
-
zoomIn: `${
|
|
27
|
-
zoomOut: `${
|
|
25
|
+
}, u = "ol-ctx-menu", a = {
|
|
26
|
+
namespace: u,
|
|
27
|
+
container: `${u}-container`,
|
|
28
|
+
separator: `${u}-separator`,
|
|
29
|
+
submenu: `${u}-submenu`,
|
|
30
|
+
hidden: `${u}-hidden`,
|
|
31
|
+
icon: `${u}-icon`,
|
|
32
|
+
zoomIn: `${u}-zoom-in`,
|
|
33
|
+
zoomOut: `${u}-zoom-out`,
|
|
28
34
|
unselectable: "ol-unselectable"
|
|
29
|
-
},
|
|
35
|
+
}, L = [
|
|
30
36
|
{
|
|
31
37
|
text: "Zoom In",
|
|
32
38
|
classname: `${a.zoomIn} ${a.icon}`,
|
|
@@ -52,7 +58,7 @@ const O = {
|
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
];
|
|
55
|
-
var
|
|
61
|
+
var C = { exports: {} };
|
|
56
62
|
function b() {
|
|
57
63
|
}
|
|
58
64
|
b.prototype = {
|
|
@@ -79,34 +85,34 @@ b.prototype = {
|
|
|
79
85
|
off: function(s, t) {
|
|
80
86
|
var e = this.e || (this.e = {}), n = e[s], i = [];
|
|
81
87
|
if (n && t)
|
|
82
|
-
for (var o = 0,
|
|
88
|
+
for (var o = 0, c = n.length; o < c; o++)
|
|
83
89
|
n[o].fn !== t && n[o].fn._ !== t && i.push(n[o]);
|
|
84
90
|
return i.length ? e[s] = i : delete e[s], this;
|
|
85
91
|
}
|
|
86
92
|
};
|
|
87
|
-
|
|
88
|
-
var
|
|
89
|
-
const
|
|
90
|
-
function
|
|
93
|
+
C.exports = b;
|
|
94
|
+
var I = C.exports.TinyEmitter = b;
|
|
95
|
+
const E = new I();
|
|
96
|
+
function g(s) {
|
|
91
97
|
const t = document.createDocumentFragment(), e = document.createElement("div");
|
|
92
98
|
for (e.innerHTML = s; e.firstChild; )
|
|
93
99
|
t.append(e.firstChild);
|
|
94
100
|
return t;
|
|
95
101
|
}
|
|
96
|
-
function
|
|
102
|
+
function z(s) {
|
|
97
103
|
const t = document.importNode(s), e = s.offsetWidth;
|
|
98
104
|
t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;
|
|
99
|
-
const n =
|
|
100
|
-
o.append(n),
|
|
101
|
-
const
|
|
102
|
-
return s.parentNode?.removeChild(t),
|
|
105
|
+
const n = g("<span>Foo</span>"), i = g("<span>Foo</span>"), o = document.createElement("li"), c = document.createElement("li");
|
|
106
|
+
o.append(n), c.append(i), t.append(o), t.append(c), s.parentNode?.append(t);
|
|
107
|
+
const p = t.offsetHeight / 2;
|
|
108
|
+
return s.parentNode?.removeChild(t), p;
|
|
103
109
|
}
|
|
104
|
-
function
|
|
110
|
+
function w(s, t, e = !1) {
|
|
105
111
|
const n = `_${Math.random().toString(36).slice(2, 11)}`;
|
|
106
112
|
if (typeof t != "string" && "text" in t) {
|
|
107
|
-
const
|
|
108
|
-
return t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = a.icon : t.classname.includes(a.icon) === !1 && (t.classname += ` ${a.icon}`),
|
|
109
|
-
|
|
113
|
+
const p = `<span>${t.text}</span>`, f = g(p), l = document.createElement("li");
|
|
114
|
+
return t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = a.icon : t.classname.includes(a.icon) === !1 && (t.classname += ` ${a.icon}`), l.setAttribute("style", `background-image:url(${t.icon})`)), l.id = n, l.className = t.classname, l.append(f), s.append(l), E.emit(
|
|
115
|
+
d.ADD_MENU_ENTRY,
|
|
110
116
|
{
|
|
111
117
|
id: n,
|
|
112
118
|
isSubmenu: e,
|
|
@@ -114,14 +120,14 @@ function L(s, t, e = !1) {
|
|
|
114
120
|
callback: "callback" in t ? t.callback : null,
|
|
115
121
|
data: "data" in t ? t.data : null
|
|
116
122
|
},
|
|
117
|
-
|
|
118
|
-
),
|
|
123
|
+
l
|
|
124
|
+
), l;
|
|
119
125
|
}
|
|
120
|
-
const i = `<li id="${n}" class="${a.separator}"><hr></li>`, o =
|
|
126
|
+
const i = `<li id="${n}" class="${a.separator}"><hr></li>`, o = g(i);
|
|
121
127
|
s.append(o);
|
|
122
|
-
const
|
|
123
|
-
return
|
|
124
|
-
|
|
128
|
+
const c = s.lastChild;
|
|
129
|
+
return E.emit(
|
|
130
|
+
d.ADD_MENU_ENTRY,
|
|
125
131
|
{
|
|
126
132
|
id: n,
|
|
127
133
|
isSubmenu: e,
|
|
@@ -129,27 +135,27 @@ function L(s, t, e = !1) {
|
|
|
129
135
|
callback: null,
|
|
130
136
|
data: null
|
|
131
137
|
},
|
|
132
|
-
|
|
133
|
-
),
|
|
138
|
+
c
|
|
139
|
+
), c;
|
|
134
140
|
}
|
|
135
141
|
function v(s, t, e) {
|
|
136
142
|
t.forEach((n) => {
|
|
137
143
|
if (typeof n != "string" && "items" in n && Array.isArray(n.items)) {
|
|
138
|
-
const i =
|
|
144
|
+
const i = w(s, n, !0);
|
|
139
145
|
i.classList.add(a.submenu);
|
|
140
146
|
const o = document.createElement("ul");
|
|
141
147
|
o.classList.add(a.container), o.style.width = `${e}px`, i.append(o), v(o, n.items, e);
|
|
142
148
|
} else
|
|
143
|
-
|
|
149
|
+
w(s, n);
|
|
144
150
|
});
|
|
145
151
|
}
|
|
146
|
-
function
|
|
152
|
+
function y(s, t) {
|
|
147
153
|
if (!s)
|
|
148
154
|
throw new Error(t);
|
|
149
155
|
}
|
|
150
|
-
class
|
|
156
|
+
class R extends O {
|
|
151
157
|
constructor(e = {}) {
|
|
152
|
-
|
|
158
|
+
y(typeof e == "object", "@param `opts` should be object type!");
|
|
153
159
|
const n = document.createElement("div");
|
|
154
160
|
super({ element: n });
|
|
155
161
|
r(this, "map");
|
|
@@ -165,7 +171,7 @@ class P extends T {
|
|
|
165
171
|
r(this, "items", []);
|
|
166
172
|
r(this, "menuEntries", /* @__PURE__ */ new Map());
|
|
167
173
|
r(this, "options");
|
|
168
|
-
this.options = { ...
|
|
174
|
+
this.options = { ..._, ...e };
|
|
169
175
|
const i = document.createElement("ul");
|
|
170
176
|
n.append(i), n.style.width = `${this.options.width}px`, n.classList.add(
|
|
171
177
|
a.container,
|
|
@@ -177,13 +183,7 @@ class P extends T {
|
|
|
177
183
|
this.handleEntryCallback(o);
|
|
178
184
|
}, this.mapMoveListener = () => {
|
|
179
185
|
this.handleMapMove();
|
|
180
|
-
}, this.disabled = !1, this.opened = !1
|
|
181
|
-
p.ADD_MENU_ENTRY,
|
|
182
|
-
(o, l) => {
|
|
183
|
-
this.handleAddMenuEntry(o, l);
|
|
184
|
-
},
|
|
185
|
-
this
|
|
186
|
-
);
|
|
186
|
+
}, this.disabled = !1, this.opened = !1;
|
|
187
187
|
}
|
|
188
188
|
clear() {
|
|
189
189
|
for (const e of this.menuEntries.keys())
|
|
@@ -197,26 +197,26 @@ class P extends T {
|
|
|
197
197
|
this.disabled = !0;
|
|
198
198
|
}
|
|
199
199
|
getDefaultItems() {
|
|
200
|
-
return
|
|
200
|
+
return L;
|
|
201
201
|
}
|
|
202
202
|
countItems() {
|
|
203
203
|
return this.menuEntries.size;
|
|
204
204
|
}
|
|
205
205
|
extend(e) {
|
|
206
|
-
|
|
206
|
+
y(Array.isArray(e), "@param `items` should be an Array."), v(
|
|
207
207
|
this.container.firstElementChild,
|
|
208
208
|
e,
|
|
209
209
|
this.options.width
|
|
210
210
|
);
|
|
211
211
|
}
|
|
212
212
|
closeMenu() {
|
|
213
|
-
this.opened = !1, this.container.classList.add(a.hidden), this.dispatchEvent(
|
|
213
|
+
this.opened = !1, this.container.classList.add(a.hidden), this.dispatchEvent(d.CLOSE);
|
|
214
214
|
}
|
|
215
215
|
isOpen() {
|
|
216
216
|
return this.opened;
|
|
217
217
|
}
|
|
218
218
|
updatePosition(e) {
|
|
219
|
-
|
|
219
|
+
y(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
|
|
220
220
|
}
|
|
221
221
|
pop() {
|
|
222
222
|
const e = Array.from(this.menuEntries.keys()).pop();
|
|
@@ -233,29 +233,39 @@ class P extends T {
|
|
|
233
233
|
if (super.setMap(e), e) {
|
|
234
234
|
this.map = e, this.map.getViewport().addEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.map.on("movestart", () => {
|
|
235
235
|
this.handleMapMove();
|
|
236
|
-
}),
|
|
236
|
+
}), E.on(
|
|
237
|
+
d.ADD_MENU_ENTRY,
|
|
238
|
+
(i, o) => {
|
|
239
|
+
this.handleAddMenuEntry(i, o);
|
|
240
|
+
},
|
|
241
|
+
this
|
|
242
|
+
), this.items = this.options.defaultItems ? this.options.items.concat(L) : this.options.items, v(
|
|
237
243
|
this.container.firstElementChild,
|
|
238
244
|
this.items,
|
|
239
245
|
this.options.width
|
|
240
246
|
);
|
|
241
247
|
const n = this.getMenuEntriesLength();
|
|
242
|
-
this.lineHeight = n > 0 ? this.container.offsetHeight / n :
|
|
248
|
+
this.lineHeight = n > 0 ? this.container.offsetHeight / n : z(this.container);
|
|
243
249
|
} else
|
|
244
250
|
this.removeListeners(), this.clear();
|
|
245
251
|
}
|
|
246
252
|
removeListeners() {
|
|
247
|
-
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1);
|
|
253
|
+
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), E.off(d.ADD_MENU_ENTRY);
|
|
248
254
|
}
|
|
249
255
|
removeMenuEntry(e) {
|
|
250
256
|
const n = document.getElementById(e);
|
|
251
257
|
n?.remove(), n?.removeEventListener("click", this.entryCallbackEventListener), this.menuEntries.delete(e);
|
|
252
258
|
}
|
|
253
259
|
handleContextMenu(e) {
|
|
254
|
-
this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
260
|
+
this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(
|
|
261
|
+
new x({
|
|
262
|
+
type: d.BEFOREOPEN,
|
|
263
|
+
map: this.map,
|
|
264
|
+
originalEvent: e
|
|
265
|
+
})
|
|
266
|
+
), !this.disabled && (this.options.eventType === M.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => {
|
|
267
|
+
this.openMenu(e);
|
|
268
|
+
}), e.target?.addEventListener(
|
|
259
269
|
"pointerdown",
|
|
260
270
|
(n) => {
|
|
261
271
|
this.opened && (n.stopPropagation(), this.closeMenu());
|
|
@@ -263,8 +273,14 @@ class P extends T {
|
|
|
263
273
|
{ once: !0 }
|
|
264
274
|
));
|
|
265
275
|
}
|
|
266
|
-
openMenu() {
|
|
267
|
-
this.menuEntries.size !== 0 && (this.opened = !0, this.positionContainer(), this.container.classList.remove(a.hidden)
|
|
276
|
+
openMenu(e) {
|
|
277
|
+
this.menuEntries.size !== 0 && (this.opened = !0, this.positionContainer(), this.container.classList.remove(a.hidden), this.dispatchEvent(
|
|
278
|
+
new x({
|
|
279
|
+
type: d.OPEN,
|
|
280
|
+
map: this.map,
|
|
281
|
+
originalEvent: e
|
|
282
|
+
})
|
|
283
|
+
));
|
|
268
284
|
}
|
|
269
285
|
getMenuEntriesLength() {
|
|
270
286
|
return Array.from(this.menuEntries).filter(
|
|
@@ -280,18 +296,18 @@ class P extends T {
|
|
|
280
296
|
h: Math.round(this.lineHeight * this.getMenuEntriesLength())
|
|
281
297
|
}, o = n.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w;
|
|
282
298
|
this.container.style.left = `${o}px`, this.container.style.top = n.h >= i.h ? `${this.pixel[1] - 10}px` : `${this.pixel[1] - i.h}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", n.w -= i.w;
|
|
283
|
-
const
|
|
299
|
+
const c = (l) => Array.from(l.children).filter(
|
|
284
300
|
(m) => m.tagName === "LI" && m.classList.contains(a.submenu)
|
|
285
301
|
);
|
|
286
|
-
let
|
|
287
|
-
const f = (
|
|
288
|
-
|
|
289
|
-
const
|
|
302
|
+
let p = 0;
|
|
303
|
+
const f = (l, m) => {
|
|
304
|
+
p += 1, c(l).forEach((A) => {
|
|
305
|
+
const N = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = A.querySelector(
|
|
290
306
|
`ul.${a.container}`
|
|
291
307
|
), $ = Math.round(
|
|
292
|
-
this.lineHeight * Array.from(h.children).filter((
|
|
308
|
+
this.lineHeight * Array.from(h.children).filter((S) => S.tagName === "LI").length
|
|
293
309
|
);
|
|
294
|
-
h.style.left = `${
|
|
310
|
+
h.style.left = `${N}px`, h.style.right = "auto", h.style.top = n.h >= $ + i.h ? "0" : `-${h.offsetHeight - 25}px`, h.style.bottom = "auto", h.style.zIndex = String(p), c(h).length > 0 && f(h, m - i.w);
|
|
295
311
|
});
|
|
296
312
|
};
|
|
297
313
|
f(this.container.firstElementChild, n.w);
|
|
@@ -315,5 +331,5 @@ class P extends T {
|
|
|
315
331
|
}
|
|
316
332
|
}
|
|
317
333
|
export {
|
|
318
|
-
|
|
334
|
+
R as default
|
|
319
335
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.1.
|
|
3
|
+
* ol-contextmenu - v5.1.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: Sat
|
|
5
|
+
* Built: Sat Nov 12 2022 12:41:10 GMT-0300 (Brasilia Standard Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control")):typeof define=="function"&&define.amd?define(["ol/control/Control"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control))})(this,function(l){"use strict";var
|
|
8
|
+
(function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control"),require("ol")):typeof define=="function"&&define.amd?define(["ol/control/Control","ol"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control,l.ol))})(this,function(l,c){"use strict";var H=Object.defineProperty;var U=(l,c,f)=>c in l?H(l,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[c]=f;var a=(l,c,f)=>(U(l,typeof c!="symbol"?c+"":c,f),f);const S=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(l);var x=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(x||{}),p=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(p||{});class w extends c.MapBrowserEvent{constructor(s){super(s.type,s.map,s.originalEvent)}}const T={width:150,scrollAt:4,eventType:x.CONTEXTMENU,defaultItems:!0,items:[]},m="ol-ctx-menu",r={namespace:m,container:`${m}-container`,separator:`${m}-separator`,submenu:`${m}-submenu`,hidden:`${m}-hidden`,icon:`${m}-icon`,zoomIn:`${m}-zoom-in`,zoomOut:`${m}-zoom-out`,unselectable:"ol-unselectable"},A=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,s)=>{const e=s.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,s)=>{const e=s.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var N={exports:{}};function b(){}b.prototype={on:function(n,s,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:s,ctx:e}),this},once:function(n,s,e){var t=this;function i(){t.off(n,i),s.apply(e,arguments)}return i._=s,this.on(n,i,e)},emit:function(n){var s=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,i=e.length;for(t;t<i;t++)e[t].fn.apply(e[t].ctx,s);return this},off:function(n,s){var e=this.e||(this.e={}),t=e[n],i=[];if(t&&s)for(var o=0,u=t.length;o<u;o++)t[o].fn!==s&&t[o].fn._!==s&&i.push(t[o]);return i.length?e[n]=i:delete e[n],this}},N.exports=b;var k=N.exports.TinyEmitter=b;const y=new k;function v(n){const s=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)s.append(e.firstChild);return s}function _(n){const s=document.importNode(n),e=n.offsetWidth;s.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=v("<span>Foo</span>"),i=v("<span>Foo</span>"),o=document.createElement("li"),u=document.createElement("li");o.append(t),u.append(i),s.append(o),s.append(u),n.parentNode?.append(s);const E=s.offsetHeight/2;return n.parentNode?.removeChild(s),E}function $(n,s,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof s!="string"&&"text"in s){const E=`<span>${s.text}</span>`,M=v(E),h=document.createElement("li");return s.classname=s.classname||"",s.icon&&(s.classname===""?s.classname=r.icon:s.classname.includes(r.icon)===!1&&(s.classname+=` ${r.icon}`),h.setAttribute("style",`background-image:url(${s.icon})`)),h.id=t,h.className=s.classname,h.append(M),n.append(h),y.emit(p.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in s?s.callback:null,data:"data"in s?s.data:null},h),h}const i=`<li id="${t}" class="${r.separator}"><hr></li>`,o=v(i);n.append(o);const u=n.lastChild;return y.emit(p.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},u),u}function L(n,s,e){s.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const i=$(n,t,!0);i.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,i.append(o),L(o,t.items,e)}else $(n,t)})}const F="";function C(n,s){if(!n)throw new Error(s)}class D extends S.default{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});a(this,"map");a(this,"container");a(this,"coordinate",[]);a(this,"pixel",[]);a(this,"contextMenuEventListener");a(this,"entryCallbackEventListener");a(this,"mapMoveListener");a(this,"lineHeight",0);a(this,"disabled");a(this,"opened");a(this,"items",[]);a(this,"menuEntries",new Map);a(this,"options");this.options={...T,...e};const i=document.createElement("ul");t.append(i),t.style.width=`${this.options.width}px`,t.classList.add(r.container,r.unselectable,r.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return A}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(p.CLOSE)}isOpen(){return this.opened}updatePosition(e){C(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){const e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){const e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,this.map.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.map.on("movestart",()=>{this.handleMapMove()}),y.on(p.ADD_MENU_ENTRY,(i,o)=>{this.handleAddMenuEntry(i,o)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:_(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),y.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new w({type:p.BEFOREOPEN,map:this.map,originalEvent:e})),!this.disabled&&(this.options.eventType===x.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new w({type:p.OPEN,map:this.map,originalEvent:e})))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=i.w;const u=h=>Array.from(h.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const M=(h,g)=>{E+=1,u(h).forEach(O=>{const I=g>=i.w?i.w-8:(i.w+8)*-1,d=O.querySelector(`ul.${r.container}`),z=Math.round(this.lineHeight*Array.from(d.children).filter(P=>P.tagName==="LI").length);d.style.left=`${I}px`,d.style.right="auto",d.style.top=t.h>=z+i.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(E),u(d).length>0&&M(d,g-i.w)})};M(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,i=this.menuEntries.get(t.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return D});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Coordinate } from 'ol/coordinate';
|
|
2
|
-
import
|
|
3
|
-
import { Map as OlMap } from 'ol';
|
|
4
|
-
import BaseEvent from 'ol/events/Event';
|
|
2
|
+
import { Map as OlMap, MapBrowserEvent } from 'ol';
|
|
5
3
|
export declare enum EventTypes {
|
|
6
4
|
CONTEXTMENU = "contextmenu",
|
|
7
5
|
CLICK = "click",
|
|
@@ -13,9 +11,12 @@ export declare enum CustomEventTypes {
|
|
|
13
11
|
CLOSE = "close",
|
|
14
12
|
ADD_MENU_ENTRY = "add-menu-entry"
|
|
15
13
|
}
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
export declare class ContextMenuEvent extends MapBrowserEvent<MouseEvent> {
|
|
15
|
+
constructor(options: {
|
|
16
|
+
type: `${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`;
|
|
17
|
+
map: OlMap;
|
|
18
|
+
originalEvent: MouseEvent;
|
|
19
|
+
});
|
|
19
20
|
}
|
|
20
21
|
export declare type CallbackObject = {
|
|
21
22
|
coordinate: Coordinate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ol-contextmenu",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Custom Context Menu for Openlayers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/ol-contextmenu.umd.cjs",
|
|
@@ -45,24 +45,24 @@
|
|
|
45
45
|
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@swc/core": "^1.3.
|
|
49
|
-
"@swc/jest": "^0.2.
|
|
50
|
-
"@types/jest": "^29.
|
|
51
|
-
"eslint": "^8.
|
|
48
|
+
"@swc/core": "^1.3.15",
|
|
49
|
+
"@swc/jest": "^0.2.23",
|
|
50
|
+
"@types/jest": "^29.2.2",
|
|
51
|
+
"eslint": "^8.27.0",
|
|
52
52
|
"eslint-config-jwalker": "^7.9.2",
|
|
53
53
|
"eslint-config-prettier": "^8.5.0",
|
|
54
|
-
"eslint-plugin-jest": "^27.
|
|
54
|
+
"eslint-plugin-jest": "^27.1.5",
|
|
55
55
|
"eslint-plugin-prettier": "^4.2.1",
|
|
56
56
|
"identity-obj-proxy": "^3.0.0",
|
|
57
|
-
"jest": "^29.
|
|
58
|
-
"jest-environment-jsdom": "^29.
|
|
57
|
+
"jest": "^29.3.1",
|
|
58
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
59
59
|
"ol": "^7.1.0",
|
|
60
60
|
"prettier": "^2.7.1",
|
|
61
61
|
"rimraf": "^3.0.2",
|
|
62
|
-
"typescript": "^4.8.
|
|
63
|
-
"vite": "^3.
|
|
64
|
-
"vite-plugin-banner": "^0.
|
|
65
|
-
"vite-plugin-dts": "^1.
|
|
62
|
+
"typescript": "^4.8.4",
|
|
63
|
+
"vite": "^3.2.3",
|
|
64
|
+
"vite-plugin-banner": "^0.6.1",
|
|
65
|
+
"vite-plugin-dts": "^1.7.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"ol": "^7.1.0"
|