ol-contextmenu 5.1.4 → 5.1.5
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/README.md +1 -3
- package/dist/helpers/dom.d.ts +2 -2
- package/dist/ol-contextmenu.css +2 -2
- package/dist/ol-contextmenu.iife.js +8 -0
- package/dist/ol-contextmenu.js +167 -166
- package/dist/ol-contextmenu.umd.cjs +3 -3
- package/dist/types.d.ts +9 -9
- package/package.json +22 -19
- package/dist/vite-env.d.ts +0 -1
package/README.md
CHANGED
|
@@ -21,9 +21,7 @@ A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires**
|
|
|
21
21
|
|
|
22
22
|
## Demo
|
|
23
23
|
|
|
24
|
-
[
|
|
25
|
-
|
|
26
|
-
[JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/)
|
|
24
|
+
[JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/).
|
|
27
25
|
|
|
28
26
|
## How to use it?
|
|
29
27
|
|
package/dist/helpers/dom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Item } from '../types';
|
|
2
2
|
export declare function createFragment(html: string): DocumentFragment;
|
|
3
3
|
export declare function getLineHeight(container: HTMLDivElement): number;
|
|
4
|
-
export declare function addMenuEntry(parentNode: HTMLUListElement, item: Item, isSubmenu?: boolean): HTMLLIElement;
|
|
5
|
-
export declare function addMenuEntries(container: HTMLUListElement, items: Item[], menuWidth: number): void;
|
|
4
|
+
export declare function addMenuEntry(parentNode: HTMLUListElement, item: Item, isSubmenu?: boolean, isInsideSubmenu?: boolean): HTMLLIElement;
|
|
5
|
+
export declare function addMenuEntries(container: HTMLUListElement, items: Item[], menuWidth: number, isInsideSubmenu?: boolean): 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.5
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Sat Mar 11 2023 15:05:27 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)}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* ol-contextmenu - v5.1.5
|
|
4
|
+
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
+
* Built: Sat Mar 11 2023 15:05:27 GMT-0300 (Brasilia Standard Time)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
var ContextMenu=function(f,h){"use strict";var U=Object.defineProperty;var F=(f,h,u)=>h in f?U(f,h,{enumerable:!0,configurable:!0,writable:!0,value:u}):f[h]=u;var a=(f,h,u)=>(F(f,typeof h!="symbol"?h+"":h,u),u);var u=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(u||{}),p=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(p||{});class A extends h.MapBrowserEvent{constructor(t){super(t.type,t.map,t.originalEvent)}}const k={width:150,scrollAt:4,eventType:u.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"},N=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var x={},T={get exports(){return x},set exports(n){x=n}};function L(){}L.prototype={on:function(n,t,e){var s=this.e||(this.e={});return(s[n]||(s[n]=[])).push({fn:t,ctx:e}),this},once:function(n,t,e){var s=this;function i(){s.off(n,i),t.apply(e,arguments)}return i._=t,this.on(n,i,e)},emit:function(n){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),s=0,i=e.length;for(s;s<i;s++)e[s].fn.apply(e[s].ctx,t);return this},off:function(n,t){var e=this.e||(this.e={}),s=e[n],i=[];if(s&&t)for(var o=0,l=s.length;o<l;o++)s[o].fn!==t&&s[o].fn._!==t&&i.push(s[o]);return i.length?e[n]=i:delete e[n],this}},T.exports=L;var O=x.TinyEmitter=L;const y=new O;function v(n){const t=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)t.append(e.firstChild);return t}function D(n){const t=document.importNode(n),e=n.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const s=v("<span>Foo</span>"),i=v("<span>Foo</span>"),o=document.createElement("li"),l=document.createElement("li");o.append(s),l.append(i),t.append(o),t.append(l),n.parentNode?.append(t);const E=t.offsetHeight/2;return n.parentNode?.removeChild(t),E}function S(n,t,e=!1,s=!1){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof t!="string"&&"text"in t){const b=`<span>${t.text}</span>`,g=v(b),c=document.createElement("li");t.classname=t.classname||"",t.icon&&(t.classname===""?t.classname=r.icon:t.classname.includes(r.icon)===!1&&(t.classname+=` ${r.icon}`),c.setAttribute("style",`background-image:url(${t.icon})`)),c.id=i,c.className=t.classname,c.append(g),n.append(c);const $={id:i,isSubmenu:e,isInsideSubmenu:s,isSeparator:!1,callback:"callback"in t?t.callback:null,data:"data"in t?t.data:null};return y.emit(p.ADD_MENU_ENTRY,$,c),c}const o=`<li id="${i}" class="${r.separator}"><hr></li>`,l=v(o);n.append(l);const E=n.lastChild,M={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return y.emit(p.ADD_MENU_ENTRY,M,E),E}function w(n,t,e,s){t.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const o=S(n,i,!0);o.classList.add(r.submenu);const l=document.createElement("ul");l.classList.add(r.container),l.style.width=`${e}px`,o.append(l),w(l,i.items,e,!0)}else S(n,i,!1,s)})}const R="";function C(n,t){if(!n)throw new Error(t)}class I extends f{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const s=document.createElement("div");super({element:s});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={...k,...e};const i=document.createElement("ul");s.append(i),s.style.width=`${this.options.width}px`,s.classList.add(r.container,r.unselectable,r.hidden),this.container=s,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}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 N}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),w(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(N):this.options.items,w(this.container.firstElementChild,this.items,this.options.width);const s=this.getMenuEntriesLength();this.lineHeight=s>0?this.container.offsetHeight/s:D(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 s=document.getElementById(e);s?.remove(),s?.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 A({type:p.BEFOREOPEN,map:this.map,originalEvent:e})),!this.disabled&&(this.options.eventType===u.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",s=>{this.opened&&(s.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new A({type:p.OPEN,map:this.map,originalEvent:e}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],s={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i=this.getMenuEntriesLength(),o={w:this.container.offsetWidth,h:Math.round(this.lineHeight*i)},l=s.w>=o.w?this.pixel[0]+5:this.pixel[0]-o.w;this.container.style.left=`${l}px`,this.container.style.top=s.h>=o.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-o.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",s.w-=o.w;const E=g=>Array.from(g.children).filter(c=>c.tagName==="LI"&&c.classList.contains(r.submenu));let M=0;const b=(g,c)=>{M+=1,E(g).forEach(_=>{const z=c>=o.w?o.w-8:(o.w+8)*-1,d=_.querySelector(`ul.${r.container}`),P=Math.round(this.lineHeight*Array.from(d.children).filter(H=>H.tagName==="LI").length);d.style.left=`${z}px`,d.style.right="auto",d.style.top=s.h>=P+o.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(M),E(d).length>0&&b(d,c-o.w)})};b(this.container.firstElementChild,s.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const s=e.currentTarget,i=this.menuEntries.get(s.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,s){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&s.addEventListener("click",this.entryCallbackEventListener,!1)}}return I}(ol.control.Control,ol);
|
package/dist/ol-contextmenu.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.1.
|
|
3
|
+
* ol-contextmenu - v5.1.5
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Sat Mar 11 2023 15:05:27 GMT-0300 (Brasilia Standard Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
var
|
|
14
|
-
class
|
|
15
|
-
constructor(
|
|
16
|
-
super(
|
|
8
|
+
var O = Object.defineProperty;
|
|
9
|
+
var D = (n, t, e) => t in n ? O(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
10
|
+
var a = (n, t, e) => (D(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
11
|
+
import I from "ol/control/Control";
|
|
12
|
+
import { MapBrowserEvent as _ } from "ol";
|
|
13
|
+
var x = /* @__PURE__ */ ((n) => (n.CONTEXTMENU = "contextmenu", n.CLICK = "click", n.DBLCLICK = "dblclick", n))(x || {}), d = /* @__PURE__ */ ((n) => (n.BEFOREOPEN = "beforeopen", n.OPEN = "open", n.CLOSE = "close", n.ADD_MENU_ENTRY = "add-menu-entry", n))(d || {});
|
|
14
|
+
class C extends _ {
|
|
15
|
+
constructor(t) {
|
|
16
|
+
super(t.type, t.map, t.originalEvent);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const z = {
|
|
20
20
|
width: 150,
|
|
21
21
|
scrollAt: 4,
|
|
22
|
-
eventType:
|
|
22
|
+
eventType: x.CONTEXTMENU,
|
|
23
23
|
defaultItems: !0,
|
|
24
24
|
items: []
|
|
25
25
|
}, u = "ol-ctx-menu", r = {
|
|
@@ -32,166 +32,167 @@ const _ = {
|
|
|
32
32
|
zoomIn: `${u}-zoom-in`,
|
|
33
33
|
zoomOut: `${u}-zoom-out`,
|
|
34
34
|
unselectable: "ol-unselectable"
|
|
35
|
-
},
|
|
35
|
+
}, A = [
|
|
36
36
|
{
|
|
37
37
|
text: "Zoom In",
|
|
38
38
|
classname: `${r.zoomIn} ${r.icon}`,
|
|
39
|
-
callback: (
|
|
40
|
-
const e =
|
|
39
|
+
callback: (n, t) => {
|
|
40
|
+
const e = t.getView();
|
|
41
41
|
e.animate({
|
|
42
42
|
zoom: Number(e.getZoom()) + 1,
|
|
43
43
|
duration: 700,
|
|
44
|
-
center:
|
|
44
|
+
center: n.coordinate
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
text: "Zoom Out",
|
|
50
50
|
classname: `${r.zoomOut} ${r.icon}`,
|
|
51
|
-
callback: (
|
|
52
|
-
const e =
|
|
51
|
+
callback: (n, t) => {
|
|
52
|
+
const e = t.getView();
|
|
53
53
|
e.animate({
|
|
54
54
|
zoom: Number(e.getZoom()) - 1,
|
|
55
55
|
duration: 700,
|
|
56
|
-
center:
|
|
56
|
+
center: n.coordinate
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
];
|
|
61
|
-
var
|
|
61
|
+
var M = {}, P = {
|
|
62
62
|
get exports() {
|
|
63
|
-
return
|
|
63
|
+
return M;
|
|
64
64
|
},
|
|
65
|
-
set exports(
|
|
66
|
-
|
|
65
|
+
set exports(n) {
|
|
66
|
+
M = n;
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
-
function
|
|
69
|
+
function L() {
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
on: function(
|
|
73
|
-
var
|
|
74
|
-
return (
|
|
75
|
-
fn:
|
|
71
|
+
L.prototype = {
|
|
72
|
+
on: function(n, t, e) {
|
|
73
|
+
var s = this.e || (this.e = {});
|
|
74
|
+
return (s[n] || (s[n] = [])).push({
|
|
75
|
+
fn: t,
|
|
76
76
|
ctx: e
|
|
77
77
|
}), this;
|
|
78
78
|
},
|
|
79
|
-
once: function(
|
|
80
|
-
var
|
|
79
|
+
once: function(n, t, e) {
|
|
80
|
+
var s = this;
|
|
81
81
|
function i() {
|
|
82
|
-
|
|
82
|
+
s.off(n, i), t.apply(e, arguments);
|
|
83
83
|
}
|
|
84
|
-
return i._ =
|
|
84
|
+
return i._ = t, this.on(n, i, e);
|
|
85
85
|
},
|
|
86
|
-
emit: function(
|
|
87
|
-
var
|
|
88
|
-
for (
|
|
89
|
-
e[
|
|
86
|
+
emit: function(n) {
|
|
87
|
+
var t = [].slice.call(arguments, 1), e = ((this.e || (this.e = {}))[n] || []).slice(), s = 0, i = e.length;
|
|
88
|
+
for (s; s < i; s++)
|
|
89
|
+
e[s].fn.apply(e[s].ctx, t);
|
|
90
90
|
return this;
|
|
91
91
|
},
|
|
92
|
-
off: function(
|
|
93
|
-
var e = this.e || (this.e = {}),
|
|
94
|
-
if (
|
|
95
|
-
for (var o = 0,
|
|
96
|
-
|
|
97
|
-
return i.length ? e[
|
|
92
|
+
off: function(n, t) {
|
|
93
|
+
var e = this.e || (this.e = {}), s = e[n], i = [];
|
|
94
|
+
if (s && t)
|
|
95
|
+
for (var o = 0, l = s.length; o < l; o++)
|
|
96
|
+
s[o].fn !== t && s[o].fn._ !== t && i.push(s[o]);
|
|
97
|
+
return i.length ? e[n] = i : delete e[n], this;
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
var
|
|
102
|
-
const
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
for (e.innerHTML =
|
|
106
|
-
|
|
107
|
-
return
|
|
100
|
+
P.exports = L;
|
|
101
|
+
var H = M.TinyEmitter = L;
|
|
102
|
+
const g = new H();
|
|
103
|
+
function y(n) {
|
|
104
|
+
const t = document.createDocumentFragment(), e = document.createElement("div");
|
|
105
|
+
for (e.innerHTML = n; e.firstChild; )
|
|
106
|
+
t.append(e.firstChild);
|
|
107
|
+
return t;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return (a = s.parentNode) == null || a.removeChild(n), m;
|
|
109
|
+
function U(n) {
|
|
110
|
+
const t = document.importNode(n), e = n.offsetWidth;
|
|
111
|
+
t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;
|
|
112
|
+
const s = y("<span>Foo</span>"), i = y("<span>Foo</span>"), o = document.createElement("li"), l = document.createElement("li");
|
|
113
|
+
o.append(s), l.append(i), t.append(o), t.append(l), n.parentNode?.append(t);
|
|
114
|
+
const p = t.offsetHeight / 2;
|
|
115
|
+
return n.parentNode?.removeChild(t), p;
|
|
117
116
|
}
|
|
118
|
-
function
|
|
119
|
-
const
|
|
120
|
-
if (typeof
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
id: t,
|
|
126
|
-
isSubmenu: e,
|
|
127
|
-
isSeparator: !1,
|
|
128
|
-
callback: "callback" in n ? n.callback : null,
|
|
129
|
-
data: "data" in n ? n.data : null
|
|
130
|
-
},
|
|
131
|
-
a
|
|
132
|
-
), a;
|
|
133
|
-
}
|
|
134
|
-
const i = `<li id="${t}" class="${r.separator}"><hr></li>`, o = g(i);
|
|
135
|
-
s.append(o);
|
|
136
|
-
const c = s.lastChild;
|
|
137
|
-
return E.emit(
|
|
138
|
-
p.ADD_MENU_ENTRY,
|
|
139
|
-
{
|
|
140
|
-
id: t,
|
|
117
|
+
function N(n, t, e = !1, s = !1) {
|
|
118
|
+
const i = `_${Math.random().toString(36).slice(2, 11)}`;
|
|
119
|
+
if (typeof t != "string" && "text" in t) {
|
|
120
|
+
const E = `<span>${t.text}</span>`, m = y(E), c = document.createElement("li");
|
|
121
|
+
t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = r.icon : t.classname.includes(r.icon) === !1 && (t.classname += ` ${r.icon}`), c.setAttribute("style", `background-image:url(${t.icon})`)), c.id = i, c.className = t.classname, c.append(m), n.append(c);
|
|
122
|
+
const w = {
|
|
123
|
+
id: i,
|
|
141
124
|
isSubmenu: e,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
125
|
+
isInsideSubmenu: s,
|
|
126
|
+
isSeparator: !1,
|
|
127
|
+
callback: "callback" in t ? t.callback : null,
|
|
128
|
+
data: "data" in t ? t.data : null
|
|
129
|
+
};
|
|
130
|
+
return g.emit(d.ADD_MENU_ENTRY, w, c), c;
|
|
131
|
+
}
|
|
132
|
+
const o = `<li id="${i}" class="${r.separator}"><hr></li>`, l = y(o);
|
|
133
|
+
n.append(l);
|
|
134
|
+
const p = n.lastChild, f = {
|
|
135
|
+
id: i,
|
|
136
|
+
isSubmenu: !1,
|
|
137
|
+
isInsideSubmenu: !1,
|
|
138
|
+
isSeparator: !0,
|
|
139
|
+
callback: null,
|
|
140
|
+
data: null
|
|
141
|
+
};
|
|
142
|
+
return g.emit(d.ADD_MENU_ENTRY, f, p), p;
|
|
148
143
|
}
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
if (typeof
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
144
|
+
function b(n, t, e, s) {
|
|
145
|
+
t.forEach((i) => {
|
|
146
|
+
if (typeof i != "string" && "items" in i && Array.isArray(i.items)) {
|
|
147
|
+
const o = N(n, i, !0);
|
|
148
|
+
o.classList.add(r.submenu);
|
|
149
|
+
const l = document.createElement("ul");
|
|
150
|
+
l.classList.add(r.container), l.style.width = `${e}px`, o.append(l), b(l, i.items, e, !0);
|
|
156
151
|
} else
|
|
157
|
-
|
|
152
|
+
N(n, i, !1, s);
|
|
158
153
|
});
|
|
159
154
|
}
|
|
160
|
-
function
|
|
161
|
-
if (!
|
|
162
|
-
throw new Error(
|
|
155
|
+
function v(n, t) {
|
|
156
|
+
if (!n)
|
|
157
|
+
throw new Error(t);
|
|
163
158
|
}
|
|
164
|
-
class
|
|
159
|
+
class Y extends I {
|
|
165
160
|
constructor(e = {}) {
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
super({ element:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.options = { ...
|
|
161
|
+
v(typeof e == "object", "@param `opts` should be object type!");
|
|
162
|
+
const s = document.createElement("div");
|
|
163
|
+
super({ element: s });
|
|
164
|
+
a(this, "map");
|
|
165
|
+
a(this, "container");
|
|
166
|
+
a(this, "coordinate", []);
|
|
167
|
+
a(this, "pixel", []);
|
|
168
|
+
a(this, "contextMenuEventListener");
|
|
169
|
+
a(this, "entryCallbackEventListener");
|
|
170
|
+
a(this, "mapMoveListener");
|
|
171
|
+
a(this, "lineHeight", 0);
|
|
172
|
+
a(this, "disabled");
|
|
173
|
+
a(this, "opened");
|
|
174
|
+
a(this, "items", []);
|
|
175
|
+
a(this, "menuEntries", /* @__PURE__ */ new Map());
|
|
176
|
+
a(this, "options");
|
|
177
|
+
this.options = { ...z, ...e };
|
|
183
178
|
const i = document.createElement("ul");
|
|
184
|
-
|
|
179
|
+
s.append(i), s.style.width = `${this.options.width}px`, s.classList.add(
|
|
185
180
|
r.container,
|
|
186
181
|
r.unselectable,
|
|
187
182
|
r.hidden
|
|
188
|
-
), this.container =
|
|
183
|
+
), this.container = s, this.contextMenuEventListener = (o) => {
|
|
189
184
|
this.handleContextMenu(o);
|
|
190
185
|
}, this.entryCallbackEventListener = (o) => {
|
|
191
186
|
this.handleEntryCallback(o);
|
|
192
187
|
}, this.mapMoveListener = () => {
|
|
193
188
|
this.handleMapMove();
|
|
194
|
-
}, this.disabled = !1, this.opened = !1
|
|
189
|
+
}, this.disabled = !1, this.opened = !1, window.addEventListener(
|
|
190
|
+
"beforeunload",
|
|
191
|
+
() => {
|
|
192
|
+
this.removeListeners();
|
|
193
|
+
},
|
|
194
|
+
{ once: !0 }
|
|
195
|
+
);
|
|
195
196
|
}
|
|
196
197
|
clear() {
|
|
197
198
|
for (const e of this.menuEntries.keys())
|
|
@@ -205,26 +206,26 @@ class B extends O {
|
|
|
205
206
|
this.disabled = !0;
|
|
206
207
|
}
|
|
207
208
|
getDefaultItems() {
|
|
208
|
-
return
|
|
209
|
+
return A;
|
|
209
210
|
}
|
|
210
211
|
countItems() {
|
|
211
212
|
return this.menuEntries.size;
|
|
212
213
|
}
|
|
213
214
|
extend(e) {
|
|
214
|
-
|
|
215
|
+
v(Array.isArray(e), "@param `items` should be an Array."), b(
|
|
215
216
|
this.container.firstElementChild,
|
|
216
217
|
e,
|
|
217
218
|
this.options.width
|
|
218
219
|
);
|
|
219
220
|
}
|
|
220
221
|
closeMenu() {
|
|
221
|
-
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(
|
|
222
|
+
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(d.CLOSE);
|
|
222
223
|
}
|
|
223
224
|
isOpen() {
|
|
224
225
|
return this.opened;
|
|
225
226
|
}
|
|
226
227
|
updatePosition(e) {
|
|
227
|
-
|
|
228
|
+
v(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
|
|
228
229
|
}
|
|
229
230
|
pop() {
|
|
230
231
|
const e = Array.from(this.menuEntries.keys()).pop();
|
|
@@ -241,105 +242,105 @@ class B extends O {
|
|
|
241
242
|
if (super.setMap(e), e) {
|
|
242
243
|
this.map = e, this.map.getViewport().addEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.map.on("movestart", () => {
|
|
243
244
|
this.handleMapMove();
|
|
244
|
-
}),
|
|
245
|
-
|
|
245
|
+
}), g.on(
|
|
246
|
+
d.ADD_MENU_ENTRY,
|
|
246
247
|
(i, o) => {
|
|
247
248
|
this.handleAddMenuEntry(i, o);
|
|
248
249
|
},
|
|
249
250
|
this
|
|
250
|
-
), this.items = this.options.defaultItems ? this.options.items.concat(
|
|
251
|
+
), this.items = this.options.defaultItems ? this.options.items.concat(A) : this.options.items, b(
|
|
251
252
|
this.container.firstElementChild,
|
|
252
253
|
this.items,
|
|
253
254
|
this.options.width
|
|
254
255
|
);
|
|
255
|
-
const
|
|
256
|
-
this.lineHeight =
|
|
256
|
+
const s = this.getMenuEntriesLength();
|
|
257
|
+
this.lineHeight = s > 0 ? this.container.offsetHeight / s : U(this.container);
|
|
257
258
|
} else
|
|
258
259
|
this.removeListeners(), this.clear();
|
|
259
260
|
}
|
|
260
261
|
removeListeners() {
|
|
261
|
-
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1),
|
|
262
|
+
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), g.off(d.ADD_MENU_ENTRY);
|
|
262
263
|
}
|
|
263
264
|
removeMenuEntry(e) {
|
|
264
|
-
const
|
|
265
|
-
|
|
265
|
+
const s = document.getElementById(e);
|
|
266
|
+
s?.remove(), s?.removeEventListener("click", this.entryCallbackEventListener), this.menuEntries.delete(e);
|
|
266
267
|
}
|
|
267
268
|
handleContextMenu(e) {
|
|
268
|
-
var t;
|
|
269
269
|
this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(
|
|
270
|
-
new
|
|
271
|
-
type:
|
|
270
|
+
new C({
|
|
271
|
+
type: d.BEFOREOPEN,
|
|
272
272
|
map: this.map,
|
|
273
273
|
originalEvent: e
|
|
274
274
|
})
|
|
275
|
-
), !this.disabled && (this.options.eventType ===
|
|
275
|
+
), !this.disabled && (this.options.eventType === x.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => {
|
|
276
276
|
this.openMenu(e);
|
|
277
|
-
}),
|
|
277
|
+
}), e.target?.addEventListener(
|
|
278
278
|
"pointerdown",
|
|
279
|
-
(
|
|
280
|
-
this.opened && (
|
|
279
|
+
(s) => {
|
|
280
|
+
this.opened && (s.stopPropagation(), this.closeMenu());
|
|
281
281
|
},
|
|
282
282
|
{ once: !0 }
|
|
283
283
|
));
|
|
284
284
|
}
|
|
285
285
|
openMenu(e) {
|
|
286
|
-
this.
|
|
287
|
-
new
|
|
288
|
-
type:
|
|
286
|
+
this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent(
|
|
287
|
+
new C({
|
|
288
|
+
type: d.OPEN,
|
|
289
289
|
map: this.map,
|
|
290
290
|
originalEvent: e
|
|
291
291
|
})
|
|
292
|
-
)
|
|
292
|
+
);
|
|
293
293
|
}
|
|
294
294
|
getMenuEntriesLength() {
|
|
295
295
|
return Array.from(this.menuEntries).filter(
|
|
296
|
-
([, e]) => e.isSeparator === !1
|
|
296
|
+
([, e]) => e.isSeparator === !1 && e.isSubmenu === !1 && e.isInsideSubmenu === !1
|
|
297
297
|
).length;
|
|
298
298
|
}
|
|
299
299
|
positionContainer() {
|
|
300
|
-
const e = this.map.getSize() || [0, 0],
|
|
300
|
+
const e = this.map.getSize() || [0, 0], s = {
|
|
301
301
|
w: e[0] - this.pixel[0],
|
|
302
302
|
h: e[1] - this.pixel[1]
|
|
303
|
-
}, i = {
|
|
303
|
+
}, i = this.getMenuEntriesLength(), o = {
|
|
304
304
|
w: this.container.offsetWidth,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
305
|
+
// a cheap way to recalculate container height
|
|
306
|
+
// since offsetHeight is like cached
|
|
307
|
+
h: Math.round(this.lineHeight * i)
|
|
308
|
+
}, l = s.w >= o.w ? this.pixel[0] + 5 : this.pixel[0] - o.w;
|
|
309
|
+
this.container.style.left = `${l}px`, this.container.style.top = s.h >= o.h ? `${this.pixel[1] - 10}px` : `${this.pixel[1] - o.h}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", s.w -= o.w;
|
|
310
|
+
const p = (m) => Array.from(m.children).filter(
|
|
311
|
+
(c) => c.tagName === "LI" && c.classList.contains(r.submenu)
|
|
310
312
|
);
|
|
311
|
-
let
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
const
|
|
313
|
+
let f = 0;
|
|
314
|
+
const E = (m, c) => {
|
|
315
|
+
f += 1, p(m).forEach((S) => {
|
|
316
|
+
const $ = c >= o.w ? o.w - 8 : (o.w + 8) * -1, h = S.querySelector(
|
|
315
317
|
`ul.${r.container}`
|
|
316
|
-
),
|
|
317
|
-
this.lineHeight * Array.from(h.children).filter((
|
|
318
|
+
), k = Math.round(
|
|
319
|
+
this.lineHeight * Array.from(h.children).filter((T) => T.tagName === "LI").length
|
|
318
320
|
);
|
|
319
|
-
h.style.left = `${
|
|
321
|
+
h.style.left = `${$}px`, h.style.right = "auto", h.style.top = s.h >= k + o.h ? "0" : `-${h.offsetHeight - 25}px`, h.style.bottom = "auto", h.style.zIndex = String(f), p(h).length > 0 && E(h, c - o.w);
|
|
320
322
|
});
|
|
321
323
|
};
|
|
322
|
-
|
|
324
|
+
E(this.container.firstElementChild, s.w);
|
|
323
325
|
}
|
|
324
326
|
handleMapMove() {
|
|
325
327
|
this.closeMenu();
|
|
326
328
|
}
|
|
327
329
|
handleEntryCallback(e) {
|
|
328
|
-
var c;
|
|
329
330
|
e.preventDefault(), e.stopPropagation();
|
|
330
|
-
const
|
|
331
|
+
const s = e.currentTarget, i = this.menuEntries.get(s.id);
|
|
331
332
|
if (!i)
|
|
332
333
|
return;
|
|
333
334
|
const o = {
|
|
334
335
|
coordinate: this.coordinate,
|
|
335
336
|
data: i.data
|
|
336
337
|
};
|
|
337
|
-
this.closeMenu(),
|
|
338
|
+
this.closeMenu(), i.callback?.(o, this.map);
|
|
338
339
|
}
|
|
339
|
-
handleAddMenuEntry(e,
|
|
340
|
-
this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" &&
|
|
340
|
+
handleAddMenuEntry(e, s) {
|
|
341
|
+
this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" && s.addEventListener("click", this.entryCallbackEventListener, !1);
|
|
341
342
|
}
|
|
342
343
|
}
|
|
343
344
|
export {
|
|
344
|
-
|
|
345
|
+
Y as default
|
|
345
346
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v5.1.
|
|
3
|
+
* ol-contextmenu - v5.1.5
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: Sat Mar 11 2023 15:05:27 GMT-0300 (Brasilia Standard Time)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(c
|
|
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 U=Object.defineProperty;var F=(l,c,d)=>c in l?U(l,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[c]=d;var a=(l,c,d)=>(F(l,typeof c!="symbol"?c+"":c,d),d);var d=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(d||{}),m=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(m||{});class A extends c.MapBrowserEvent{constructor(t){super(t.type,t.map,t.originalEvent)}}const T={width:150,scrollAt:4,eventType:d.CONTEXTMENU,defaultItems:!0,items:[]},f="ol-ctx-menu",r={namespace:f,container:`${f}-container`,separator:`${f}-separator`,submenu:`${f}-submenu`,hidden:`${f}-hidden`,icon:`${f}-icon`,zoomIn:`${f}-zoom-in`,zoomOut:`${f}-zoom-out`,unselectable:"ol-unselectable"},N=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var x={},k={get exports(){return x},set exports(n){x=n}};function L(){}L.prototype={on:function(n,t,e){var s=this.e||(this.e={});return(s[n]||(s[n]=[])).push({fn:t,ctx:e}),this},once:function(n,t,e){var s=this;function i(){s.off(n,i),t.apply(e,arguments)}return i._=t,this.on(n,i,e)},emit:function(n){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),s=0,i=e.length;for(s;s<i;s++)e[s].fn.apply(e[s].ctx,t);return this},off:function(n,t){var e=this.e||(this.e={}),s=e[n],i=[];if(s&&t)for(var o=0,h=s.length;o<h;o++)s[o].fn!==t&&s[o].fn._!==t&&i.push(s[o]);return i.length?e[n]=i:delete e[n],this}},k.exports=L;var O=x.TinyEmitter=L;const y=new O;function v(n){const t=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)t.append(e.firstChild);return t}function D(n){const t=document.importNode(n),e=n.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const s=v("<span>Foo</span>"),i=v("<span>Foo</span>"),o=document.createElement("li"),h=document.createElement("li");o.append(s),h.append(i),t.append(o),t.append(h),n.parentNode?.append(t);const E=t.offsetHeight/2;return n.parentNode?.removeChild(t),E}function S(n,t,e=!1,s=!1){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof t!="string"&&"text"in t){const b=`<span>${t.text}</span>`,g=v(b),u=document.createElement("li");t.classname=t.classname||"",t.icon&&(t.classname===""?t.classname=r.icon:t.classname.includes(r.icon)===!1&&(t.classname+=` ${r.icon}`),u.setAttribute("style",`background-image:url(${t.icon})`)),u.id=i,u.className=t.classname,u.append(g),n.append(u);const $={id:i,isSubmenu:e,isInsideSubmenu:s,isSeparator:!1,callback:"callback"in t?t.callback:null,data:"data"in t?t.data:null};return y.emit(m.ADD_MENU_ENTRY,$,u),u}const o=`<li id="${i}" class="${r.separator}"><hr></li>`,h=v(o);n.append(h);const E=n.lastChild,M={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return y.emit(m.ADD_MENU_ENTRY,M,E),E}function w(n,t,e,s){t.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const o=S(n,i,!0);o.classList.add(r.submenu);const h=document.createElement("ul");h.classList.add(r.container),h.style.width=`${e}px`,o.append(h),w(h,i.items,e,!0)}else S(n,i,!1,s)})}const R="";function C(n,t){if(!n)throw new Error(t)}class I extends l{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const s=document.createElement("div");super({element:s});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");s.append(i),s.style.width=`${this.options.width}px`,s.classList.add(r.container,r.unselectable,r.hidden),this.container=s,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}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 N}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),w(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(m.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(m.ADD_MENU_ENTRY,(i,o)=>{this.handleAddMenuEntry(i,o)},this),this.items=this.options.defaultItems?this.options.items.concat(N):this.options.items,w(this.container.firstElementChild,this.items,this.options.width);const s=this.getMenuEntriesLength();this.lineHeight=s>0?this.container.offsetHeight/s:D(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),y.off(m.ADD_MENU_ENTRY)}removeMenuEntry(e){const s=document.getElementById(e);s?.remove(),s?.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 A({type:m.BEFOREOPEN,map:this.map,originalEvent:e})),!this.disabled&&(this.options.eventType===d.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",s=>{this.opened&&(s.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new A({type:m.OPEN,map:this.map,originalEvent:e}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],s={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i=this.getMenuEntriesLength(),o={w:this.container.offsetWidth,h:Math.round(this.lineHeight*i)},h=s.w>=o.w?this.pixel[0]+5:this.pixel[0]-o.w;this.container.style.left=`${h}px`,this.container.style.top=s.h>=o.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-o.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",s.w-=o.w;const E=g=>Array.from(g.children).filter(u=>u.tagName==="LI"&&u.classList.contains(r.submenu));let M=0;const b=(g,u)=>{M+=1,E(g).forEach(_=>{const z=u>=o.w?o.w-8:(o.w+8)*-1,p=_.querySelector(`ul.${r.container}`),P=Math.round(this.lineHeight*Array.from(p.children).filter(H=>H.tagName==="LI").length);p.style.left=`${z}px`,p.style.right="auto",p.style.top=s.h>=P+o.h?"0":`-${p.offsetHeight-25}px`,p.style.bottom="auto",p.style.zIndex=String(M),E(p).length>0&&b(p,u-o.w)})};b(this.container.firstElementChild,s.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const s=e.currentTarget,i=this.menuEntries.get(s.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,s){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&s.addEventListener("click",this.entryCallbackEventListener,!1)}}return I});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import OlMap from 'ol/Map';
|
|
2
1
|
import type { Coordinate } from 'ol/coordinate';
|
|
3
|
-
import MapBrowserEvent from 'ol
|
|
2
|
+
import { Map as OlMap, MapBrowserEvent } from 'ol';
|
|
4
3
|
export declare enum EventTypes {
|
|
5
4
|
CONTEXTMENU = "contextmenu",
|
|
6
5
|
CLICK = "click",
|
|
@@ -19,33 +18,34 @@ export declare class ContextMenuEvent extends MapBrowserEvent<MouseEvent> {
|
|
|
19
18
|
originalEvent: MouseEvent;
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
|
-
export
|
|
21
|
+
export type CallbackObject = {
|
|
23
22
|
coordinate: Coordinate;
|
|
24
23
|
data: unknown;
|
|
25
24
|
};
|
|
26
|
-
export
|
|
27
|
-
export
|
|
25
|
+
export type ItemSeparator = '-';
|
|
26
|
+
export type SingleItem = {
|
|
28
27
|
text: string;
|
|
29
28
|
classname?: string;
|
|
30
29
|
icon?: string;
|
|
31
30
|
callback: (object: CallbackObject, map: OlMap) => void;
|
|
32
31
|
data?: unknown;
|
|
33
32
|
};
|
|
34
|
-
export
|
|
33
|
+
export type MenuEntry = {
|
|
35
34
|
id: string;
|
|
36
35
|
isSubmenu: boolean;
|
|
36
|
+
isInsideSubmenu: boolean;
|
|
37
37
|
isSeparator: boolean;
|
|
38
38
|
callback: SingleItem['callback'] | null;
|
|
39
39
|
data: unknown;
|
|
40
40
|
};
|
|
41
|
-
export
|
|
41
|
+
export type ItemWithNested = {
|
|
42
42
|
text: string;
|
|
43
43
|
classname?: string;
|
|
44
44
|
icon?: string;
|
|
45
45
|
items: Item[];
|
|
46
46
|
};
|
|
47
|
-
export
|
|
48
|
-
export
|
|
47
|
+
export type Item = SingleItem | ItemSeparator | ItemWithNested;
|
|
48
|
+
export type Options = {
|
|
49
49
|
width: number;
|
|
50
50
|
scrollAt: number;
|
|
51
51
|
eventType: `${EventTypes}`;
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ol-contextmenu",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.5",
|
|
4
4
|
"description": "Custom Context Menu for Openlayers",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"main": "./dist/ol-contextmenu.umd.cjs",
|
|
7
|
+
"browser": "./dist/ol-contextmenu.iife.js",
|
|
7
8
|
"module": "./dist/ol-contextmenu.js",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
@@ -13,7 +14,8 @@
|
|
|
13
14
|
},
|
|
14
15
|
"./ol-contextmenu.css": {
|
|
15
16
|
"import": "./dist/ol-contextmenu.css",
|
|
16
|
-
"require": "./dist/ol-contextmenu.css"
|
|
17
|
+
"require": "./dist/ol-contextmenu.css",
|
|
18
|
+
"style": "./dist/ol-contextmenu.css"
|
|
17
19
|
}
|
|
18
20
|
},
|
|
19
21
|
"files": [
|
|
@@ -38,32 +40,33 @@
|
|
|
38
40
|
"dev": "vite",
|
|
39
41
|
"build": "rimraf ./dist && vite build",
|
|
40
42
|
"preview": "vite preview",
|
|
41
|
-
"lint": "eslint
|
|
43
|
+
"lint": "eslint .",
|
|
42
44
|
"lint:fix": "npm run lint -- --fix",
|
|
43
45
|
"test": "jest",
|
|
44
46
|
"prepublishOnly": "npm run lint && npm test && npm run build",
|
|
45
47
|
"prepare": "husky install"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@swc/core": "^1.3.
|
|
50
|
+
"@swc/core": "^1.3.39",
|
|
49
51
|
"@swc/jest": "^0.2.24",
|
|
50
|
-
"@types/jest": "^29.
|
|
51
|
-
"eslint": "^8.
|
|
52
|
-
"eslint-config-jwalker": "^
|
|
53
|
-
"eslint-config-prettier": "^8.
|
|
54
|
-
"eslint-plugin-jest": "^27.1
|
|
52
|
+
"@types/jest": "^29.4.0",
|
|
53
|
+
"eslint": "^8.36.0",
|
|
54
|
+
"eslint-config-jwalker": "^8.0.0",
|
|
55
|
+
"eslint-config-prettier": "^8.7.0",
|
|
56
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
55
57
|
"eslint-plugin-prettier": "^4.2.1",
|
|
56
|
-
"husky": "^8.0.
|
|
58
|
+
"husky": "^8.0.3",
|
|
57
59
|
"identity-obj-proxy": "^3.0.0",
|
|
58
|
-
"jest": "^29.
|
|
59
|
-
"jest-environment-jsdom": "^29.
|
|
60
|
-
"ol": "^7.
|
|
61
|
-
"prettier": "^2.8.
|
|
62
|
-
"rimraf": "^
|
|
63
|
-
"
|
|
64
|
-
"
|
|
60
|
+
"jest": "^29.5.0",
|
|
61
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
62
|
+
"ol": "^7.3.0",
|
|
63
|
+
"prettier": "^2.8.4",
|
|
64
|
+
"rimraf": "^4.4.0",
|
|
65
|
+
"sass": "^1.59.2",
|
|
66
|
+
"typescript": "^4.9.5",
|
|
67
|
+
"vite": "^4.1.4",
|
|
65
68
|
"vite-plugin-banner": "^0.7.0",
|
|
66
|
-
"vite-plugin-dts": "^1.
|
|
69
|
+
"vite-plugin-dts": "^2.1.0"
|
|
67
70
|
},
|
|
68
71
|
"peerDependencies": {
|
|
69
72
|
"ol": "^7.1.0"
|
package/dist/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|