ol-contextmenu 4.0.0 → 5.0.0-alpha

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.
@@ -1,114 +1 @@
1
-
2
- /*!
3
- * ol-contextmenu - v4.0.0
4
- * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Wed Nov 20 2019 13:29:37 GMT-0300 (Brasilia Standard Time)
6
- */
7
- .ol-ctx-menu-container {
8
- position: absolute;
9
- padding: 8px;
10
- background: #fff;
11
- color: #222;
12
- font-size: 13px;
13
- border-radius: 5px;
14
- box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
15
- box-sizing: border-box;
16
- }
17
- .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 {
18
- margin: 0;
19
- padding: 0;
20
- border: 0;
21
- font: inherit;
22
- font-size: 100%;
23
- vertical-align: baseline;
24
- }
25
- .ol-ctx-menu-container a img {
26
- border: none;
27
- }
28
- .ol-ctx-menu-container *,
29
- .ol-ctx-menu-container *::before,
30
- .ol-ctx-menu-container *::after {
31
- box-sizing: inherit;
32
- }
33
- .ol-ctx-menu-container.ol-ctx-menu-hidden {
34
- opacity: 0;
35
- visibility: hidden;
36
- -webkit-transition: visibility 0s linear 300ms, opacity 300ms;
37
- transition: visibility 0s linear 300ms, opacity 300ms;
38
- }
39
- .ol-ctx-menu-container ul {
40
- list-style: none;
41
- }
42
- .ol-ctx-menu-container li {
43
- position: relative;
44
- line-height: 20px;
45
- padding: 2px 5px;
46
- }
47
- .ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover {
48
- cursor: pointer;
49
- background-color: #333;
50
- color: #eee;
51
- }
52
- .ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container {
53
- border: 1px solid #eee;
54
- padding: 8px;
55
- top: 0;
56
- opacity: 0;
57
- visibility: hidden;
58
- -webkit-transition: visibility 0s linear 300ms, opacity 300ms;
59
- transition: visibility 0s linear 300ms, opacity 300ms;
60
- }
61
- .ol-ctx-menu-container li.ol-ctx-menu-submenu:hover .ol-ctx-menu-container {
62
- opacity: 1;
63
- visibility: visible;
64
- -webkit-transition-delay: 0s;
65
- transition-delay: 0s;
66
- }
67
- .ol-ctx-menu-container li.ol-ctx-menu-submenu::after {
68
- position: absolute;
69
- top: 7px;
70
- right: 10px;
71
- content: "";
72
- display: inline-block;
73
- width: 0.6em;
74
- height: 0.6em;
75
- border-right: 0.3em solid #222;
76
- border-top: 0.3em solid #222;
77
- -webkit-transform: rotate(45deg);
78
- transform: rotate(45deg);
79
- }
80
- .ol-ctx-menu-container li.ol-ctx-menu-submenu:hover::after {
81
- border-color: #eee;
82
- }
83
- .ol-ctx-menu-container li.ol-ctx-menu-separator {
84
- padding: 0;
85
- }
86
- .ol-ctx-menu-container li.ol-ctx-menu-separator hr {
87
- border: 0;
88
- height: 1px;
89
- background-image: -webkit-gradient(linear, right top, left top, from(rgba(0, 0, 0, 0)), color-stop(rgba(0, 0, 0, 0.75)), to(rgba(0, 0, 0, 0)));
90
- background-image: linear-gradient(to left, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
91
- }
92
-
93
- .ol-ctx-menu-icon {
94
- text-indent: 20px;
95
- background-size: 20px auto;
96
- background-repeat: no-repeat;
97
- background-position: left center;
98
- }
99
-
100
- .ol-ctx-menu-zoom-in {
101
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABaUlEQVQ4T72U7VHCQBCGn90GtAMuNGCswFiBWIFQgWMFxg6wArECsQKhArEBiB1Qwa1zgQn5IAYcxv13k71n3919L8KJQ07M47+BzgG9TRfZ/JBuWhS6BJFHRJICYrZGZIz3z5Ct2+B7gG6I6kt+wewdkQVwjtkAkR5mC8yu26A1oItR/cTsOweQBdgutD8G7jGm2PJ2n8oqUKIpIjd4HxTM8gvaT/F+AlmWnyWaIXKF95eNguFzTYFhNsdWu9kFgFlaFMANUH3D8wDLoLgSTSD2il8NCe2ZXQBxWDGwxmyUzzOMBZ7wy7Qb2K0wQfXjMOBuhlFpZtNty5sFaTQBuTusZdymeqs1SpYKcO9HkE3KbTd9WFijMHJQ5hBNEAYNq5Qd0dhyke0GiE4QzjqfW23mHT8Hl4DG4Lce3FPE7AtbBSdsbNqpoJLgYkRnNeUV+xwJDHTnUEkxHGbhBXUs5TjJjew/KPy94g+NRaIVRYmMXwAAAABJRU5ErkJggg==");
102
- }
103
-
104
- .ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-in {
105
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABc0lEQVQ4T71U21ECQRDsJgGdvQDECMQIxAjECMQILCPwzAAjECIQI0AiEDPQAPaWCBhrcKHuCUcV5f7dY3v6tUscefHIePhfwBBCF8CZqRCReRs1tQxDCH1VfQLQz4EsSY4AvIjIsgm8AhhCGKrqa9zwrqoLAKckB5HtguR1E2gBMITQU9VPAD8GICIGtl3e+xHJBwBT59xtHcsCYJZlUwA3kcGHbfDep51OZywi3/acZZm9vyJ5WR5o38uACmDunNt6ZwAkUxFZDwghDFT1jeSjiJinhVUBVNVJkiTDKO8CQA+AsbNQ7s1Ps0VVn5MkSfcCtmBoDZi1Bdx4eJ7zbBolrwPy3o9J3rWSHPs3A1BbjVKlYBaIyDgvu9LDXDU2RTZmXVW1oKyLxRD+OrkOrJLy5mVM0iaftDhuhVbsvBzMglzKUNW6IV/OOWtCM8MmVvEkmbwt83LaB19fdgOtVquUZJeknaDdobTwbOcvBzPcN/AXH1DFFWP7u9oAAAAASUVORK5CYII=");
106
- }
107
-
108
- .ol-ctx-menu-zoom-out {
109
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABU0lEQVQ4T72U7VECMRRFz3sNaAdkacC1AtcKxApcKnCsQOwAK3CtQKxAqEBsANYOqCDPyTIC+8WCw5jfybn33dxEOPGSE/P4b6BzQG89RT47ZJoWhy5B5BGRZAMxWyEyxvtnyFdt8AagS1F9KQ6YvSMyB84xGyDSw2yO2XUbtAJ0MaqfmH0XAPIA2y7tj4F7jAm2uG1yWQZKNEHkBu+Dg2njWBJNEbnC+8uaIFRuWfuG2QxbbrOrUd0A1Tc8D7AIjkur7DAAsVf8MiWMZ3ZR2m02LPIMscATfjHqBnY7TFD9OAy4zTCCPG/MUKMM5O6wkXFr9dZq7FQqqHk/hDzbFa73cFONTZFDdRyiCcKg5rrSiLaXkiI6RjjrfG6VzDs+B5eAxuDXeYpmNRGzL2wZ/wof+du4GNFpBVqqz5HA4MM5VEYYDrOs+1I6Q9u/4Q8O9wN/AGgWjBVqQjjgAAAAAElFTkSuQmCC");
110
- }
111
-
112
- .ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-out {
113
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABYklEQVQ4T72U4VHCQBCF36tA91KAWIFYgViBWIFYgWMFYgdYgVCBWAFSgdiBFpAsFWSdxcDkQoBkhnF/ZjbfvX377ogjF4/Mw/8CVbUD4MynEJF5k2lqFapqz8yeAPRKkCXJEYAXEVnugm8BVXVgZq/FD+9mtgBwSrJfqF2QvN4FjYCq2jWzTwA/DhARh20qTdMRyQcA0xDCbZ3KCJhl2RTATaHgo+6HLMv8+xXJy+qB3l8FGoB5CKHsXcRV1b6ZvZF8FBH3NKotoJlNkiQZFONdlLtJ3rufbouZPSdJMjwIbKDQEzBrClx7eC4i33Uepmk6JnnXaOQifzMAtdGoRApugYiMI1uqKkrRWAfZo9MxM1+UZzFewl8mN4nYdVM83L7BkwbXLUrF3sfBLQDQBbDy08x8vOohXyEE71lVq9emuEk+3gZa3XYroCvwFyjP8yHJDsnxwaU08GxvS2uFhw78BbzWrxXgMbsHAAAAAElFTkSuQmCC");
114
- }
1
+ .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:hover>.ol-ctx-menu-container{opacity:1;visibility:visible;transition-delay:0s}.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 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,6 +1,313 @@
1
- /*!
2
- * ol-contextmenu - v4.0.0
3
- * https://github.com/jonataswalker/ol-contextmenu
4
- * Built: Wed Nov 20 2019 13:29:37 GMT-0300 (Brasilia Standard Time)
5
- */
6
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("ol/control/Control")):"function"==typeof define&&define.amd?define(["ol/control/Control"],e):(t=t||self).ContextMenu=e(t.ol.control.Control)}(this,(function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="ol-ctx-menu",n={namespace:e,container:e+"-container",separator:e+"-separator",submenu:e+"-submenu",hidden:e+"-hidden",icon:e+"-icon",zoomIn:e+"-zoom-in",zoomOut:e+"-zoom-out",unselectable:"ol-unselectable"},i=n,o="beforeopen",s="open",r="close",a="contextmenu",l={width:150,scrollAt:4,eventType:a,defaultItems:!0},c=[{text:"Zoom In",classname:n.zoomIn+" "+n.icon,callback:function(t,e){var n=e.getView();n.animate({zoom:+n.getZoom()+1,duration:700,center:t.coordinate})}},{text:"Zoom Out",classname:n.zoomOut+" "+n.icon,callback:function(t,e){var n=e.getView();n.animate({zoom:+n.getZoom()-1,duration:700,center:t.coordinate})}}];function h(t,e){if(void 0===e&&(e="Assertion failed"),!t){if("undefined"!=typeof Error)throw new Error(e);throw e}}function p(t){return/^\d+$/.test(t)}function u(t,e){return t.classList?t.classList.contains(e):y(e).test(t.className)}function d(t,e,n){void 0===e&&(e=window.document);var i=Array.prototype.slice,o=[];if(/^(#?[\w-]+|\.[\w-.]+)$/.test(t))switch(t[0]){case"#":o=[m(t.substr(1))];break;case".":o=i.call(e.getElementsByClassName(t.substr(1).replace(/\./g," ")));break;default:o=i.call(e.getElementsByTagName(t))}else o=i.call(e.querySelectorAll(t));return n?o:o[0]}function m(t){return t="#"===t[0]?t.substr(1,t.length):t,document.getElementById(t)}function f(t){var e=document.createDocumentFragment(),n=document.createElement("div");for(n.innerHTML=t;n.firstChild;)e.appendChild(n.firstChild);return e}function y(t){return new RegExp("(^|\\s+) "+t+" (\\s+|$)")}function v(t,e,n){t.classList?t.classList.add(e):t.className=(t.className+" "+e).trim(),n&&p(n)&&window.setTimeout((function(){return g(t,e)}),n)}function g(t,e,n){t.classList?t.classList.remove(e):t.className=t.className.replace(y(e)," ").trim(),n&&p(n)&&window.setTimeout((function(){return v(t,e)}),n)}var b=function(t){return this.Base=t,this.map=void 0,this.viewport=void 0,this.coordinateClicked=void 0,this.pixelClicked=void 0,this.lineHeight=0,this.items={},this.opened=!1,this.submenu={left:t.options.width-15+"px",lastLeft:""},this.eventHandler=this.handleEvent.bind(this),this};b.prototype.init=function(t){this.map=t,this.viewport=t.getViewport(),this.setListeners(),this.Base.Html.createMenu(),this.lineHeight=this.getItemsLength()>0?this.Base.container.offsetHeight/this.getItemsLength():this.Base.Html.cloneAndGetLineHeight()},b.prototype.getItemsLength=function(){var t=this,e=0;return Object.keys(this.items).forEach((function(n){t.items[n].submenu||t.items[n].separator||e++})),e},b.prototype.getPixelClicked=function(){return this.pixelClicked},b.prototype.getCoordinateClicked=function(){return this.coordinateClicked},b.prototype.positionContainer=function(t){var e=this,n=this.Base.container,o=this.map.getSize(),s=o[1]-t[1],r=o[0]-t[0],a=n.offsetWidth,l=Math.round(this.lineHeight*this.getItemsLength()),c=d("li."+i.submenu+">div",n,!0);r>=a?(n.style.right="auto",n.style.left=t[0]+5+"px"):(n.style.left="auto",n.style.right="15px"),s>=l?(n.style.bottom="auto",n.style.top=t[1]-10+"px"):(n.style.top="auto",n.style.bottom=0),function t(e,n,i){if(Array.isArray(e))e.forEach((function(e){return t(e,n,i)}));else for(var o=Array.isArray(n)?n:n.split(/\s+/),s=o.length;s--;)u(e,o[s])&&g(e,o[s],i)}(n,i.hidden),c.length&&(this.submenu.lastLeft=r<2*a?"-"+a+"px":this.submenu.left,c.forEach((function(t){var n,i,o,r={w:window.innerWidth||document.documentElement.clientWidth,h:window.innerHeight||document.documentElement.clientHeight},a=(i=(n=t).getBoundingClientRect(),o=document.documentElement,{left:i.left+window.pageXOffset-o.clientLeft,top:i.top+window.pageYOffset-o.clientTop,width:n.offsetWidth,height:n.offsetHeight}),l=a.height,c=s-l;c<0&&(c=l-(r.h-a.top),t.style.top="-"+c+"px"),t.style.left=e.submenu.lastLeft})))},b.prototype.openMenu=function(t,e){this.Base.dispatchEvent({type:s,pixel:t,coordinate:e}),this.opened=!0,this.positionContainer(t)},b.prototype.closeMenu=function(){this.opened=!1,function t(e,n,i){if(Array.isArray(e))e.forEach((function(e){return t(e,n)}));else for(var o=Array.isArray(n)?n:n.split(/\s+/),s=o.length;s--;)u(e,o[s])||v(e,o[s],i)}(this.Base.container,i.hidden),this.Base.dispatchEvent({type:r})},b.prototype.setListeners=function(){this.viewport.addEventListener(this.Base.options.eventType,this.eventHandler,!1)},b.prototype.removeListeners=function(){this.viewport.removeEventListener(this.Base.options.eventType,this.eventHandler,!1)},b.prototype.handleEvent=function(t){var e=this;this.coordinateClicked=this.map.getEventCoordinate(t),this.pixelClicked=this.map.getEventPixel(t),this.Base.dispatchEvent({type:o,pixel:this.pixelClicked,coordinate:this.coordinateClicked}),this.Base.disabled||(this.Base.options.eventType===a&&(t.stopPropagation(),t.preventDefault()),this.openMenu(this.pixelClicked,this.coordinateClicked),t.target.addEventListener("click",{handleEvent:function(n){e.closeMenu(),t.target.removeEventListener(n.type,this,!1)}},!1))},b.prototype.setItemListener=function(t,e){var n,i=this;t&&"function"==typeof this.items[e].callback&&(n=this.items[e].callback,t.addEventListener("click",(function(t){t.preventDefault();var o={coordinate:i.getCoordinateClicked(),data:i.items[e].data||null};i.closeMenu(),n(o,i.map)}),!1))};var C=function(t){return this.Base=t,this.Base.container=this.container=this.createContainer(!0),this};return C.prototype.createContainer=function(t){var e=document.createElement("div"),n=document.createElement("ul"),o=[i.container,i.unselectable];return t&&o.push(i.hidden),e.className=o.join(" "),e.style.width=parseInt(this.Base.options.width,10)+"px",e.appendChild(n),e},C.prototype.createMenu=function(){var t=[];if("items"in this.Base.options?t=this.Base.options.defaultItems?this.Base.options.items.concat(c):this.Base.options.items:this.Base.options.defaultItems&&(t=c),0===t.length)return!1;t.forEach(this.addMenuEntry,this)},C.prototype.addMenuEntry=function(t){var e,n=this;if(t.items&&Array.isArray(t.items)){t.classname=t.classname||"",e=i.submenu,~t.classname.indexOf(e)||(t.classname=t.classname.length?" "+i.submenu:i.submenu);var o=this.generateHtmlAndPublish(this.container,t),s=this.createContainer();s.style.left=this.Base.Internal.submenu.lastLeft||this.Base.Internal.submenu.left,o.appendChild(s),t.items.forEach((function(t){n.generateHtmlAndPublish(s,t,!0)}))}else this.generateHtmlAndPublish(this.container,t)},C.prototype.generateHtmlAndPublish=function(t,e,n){var o,s,r="_"+Math.random().toString(36).substr(2,9),a=!1;return"string"==typeof e&&"-"===e.trim()?(o=f('<li id="'+r+'" class="'+i.separator+'"><hr></li>'),s=[].slice.call(o.childNodes,0)[0],t.firstChild.appendChild(o),a=!0):(e.classname=e.classname||"",o=f("<span>"+e.text+"</span>"),s=document.createElement("li"),e.icon&&(""===e.classname?e.classname=i.icon:-1===e.classname.indexOf(i.icon)&&(e.classname+=" "+i.icon),s.setAttribute("style","background-image:url("+e.icon+")")),s.id=r,s.className=e.classname,s.appendChild(o),t.firstChild.appendChild(s)),this.Base.Internal.items[r]={id:r,submenu:n||0,separator:a,callback:e.callback,data:e.data||null},this.Base.Internal.setItemListener(s,r),s},C.prototype.removeMenuEntry=function(t){var e=d("#"+t,this.container.firstChild);e&&this.container.firstChild.removeChild(e),delete this.Base.Internal.items[t]},C.prototype.cloneAndGetLineHeight=function(){var t=this.container.cloneNode(),e=f("<span>Foo</span>"),n=f("<span>Foo</span>"),i=document.createElement("li"),o=document.createElement("li");i.appendChild(e),o.appendChild(n),t.appendChild(i),t.appendChild(o),this.container.parentNode.appendChild(t);var s=t.offsetHeight/2;return this.container.parentNode.removeChild(t),s},function(t){function e(e){void 0===e&&(e={}),h("object"==typeof e,"@param `opt_options` should be object type!"),this.options=function(t,e){var n={};for(var i in t)n[i]=t[i];for(var o in e)n[o]=e[o];return n}(l,e),this.disabled=!1,this.Internal=new b(this),this.Html=new C(this),t.call(this,{element:this.container})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clear=function(){Object.keys(this.Internal.items).forEach(this.Html.removeMenuEntry,this.Html)},e.prototype.close=function(){this.Internal.closeMenu()},e.prototype.enable=function(){this.disabled=!1},e.prototype.disable=function(){this.disabled=!0},e.prototype.getDefaultItems=function(){return c},e.prototype.countItems=function(){return Object.keys(this.Internal.items).length},e.prototype.extend=function(t){h(Array.isArray(t),"@param `arr` should be an Array."),t.forEach(this.push,this)},e.prototype.isOpen=function(){return this.Internal.opened},e.prototype.updatePosition=function(t){h(Array.isArray(t),"@param `pixel` should be an Array."),this.isOpen()&&this.Internal.positionContainer(t)},e.prototype.pop=function(){var t=Object.keys(this.Internal.items);this.Html.removeMenuEntry(t[t.length-1])},e.prototype.push=function(t){h(null!=t,"@param `item` must be informed."),this.Html.addMenuEntry(t)},e.prototype.shift=function(){this.Html.removeMenuEntry(Object.keys(this.Internal.items)[0])},e.prototype.setMap=function(e){t.prototype.setMap.call(this,e),e?this.Internal.init(e,this):this.Internal.removeListeners()},e}(t)}));
1
+ var S = Object.defineProperty;
2
+ var k = (s, t, e) => t in s ? S(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var a = (s, t, e) => (k(s, typeof t != "symbol" ? t + "" : t, e), e);
4
+ import T from "ol/control/Control";
5
+ var M = /* @__PURE__ */ ((s) => (s.CONTEXTMENU = "contextmenu", s.CLICK = "click", s.DBLCLICK = "dblclick", s))(M || {}), p = /* @__PURE__ */ ((s) => (s.BEFOREOPEN = "beforeopen", s.OPEN = "open", s.CLOSE = "close", s.ADD_MENU_ENTRY = "add-menu-entry", s))(p || {});
6
+ const O = {
7
+ width: 150,
8
+ scrollAt: 4,
9
+ eventType: M.CONTEXTMENU,
10
+ defaultItems: !0,
11
+ items: []
12
+ }, d = "ol-ctx-menu", r = {
13
+ namespace: d,
14
+ container: `${d}-container`,
15
+ separator: `${d}-separator`,
16
+ submenu: `${d}-submenu`,
17
+ hidden: `${d}-hidden`,
18
+ icon: `${d}-icon`,
19
+ zoomIn: `${d}-zoom-in`,
20
+ zoomOut: `${d}-zoom-out`,
21
+ unselectable: "ol-unselectable"
22
+ }, x = [
23
+ {
24
+ text: "Zoom In",
25
+ classname: `${r.zoomIn} ${r.icon}`,
26
+ callback: (s, t) => {
27
+ const e = t.getView();
28
+ e.animate({
29
+ zoom: Number(e.getZoom()) + 1,
30
+ duration: 700,
31
+ center: s.coordinate
32
+ });
33
+ }
34
+ },
35
+ {
36
+ text: "Zoom Out",
37
+ classname: `${r.zoomOut} ${r.icon}`,
38
+ callback: (s, t) => {
39
+ const e = t.getView();
40
+ e.animate({
41
+ zoom: Number(e.getZoom()) - 1,
42
+ duration: 700,
43
+ center: s.coordinate
44
+ });
45
+ }
46
+ }
47
+ ];
48
+ var w = { exports: {} };
49
+ function b() {
50
+ }
51
+ b.prototype = {
52
+ on: function(s, t, e) {
53
+ var n = this.e || (this.e = {});
54
+ return (n[s] || (n[s] = [])).push({
55
+ fn: t,
56
+ ctx: e
57
+ }), this;
58
+ },
59
+ once: function(s, t, e) {
60
+ var n = this;
61
+ function i() {
62
+ n.off(s, i), t.apply(e, arguments);
63
+ }
64
+ return i._ = t, this.on(s, i, e);
65
+ },
66
+ emit: function(s) {
67
+ var t = [].slice.call(arguments, 1), e = ((this.e || (this.e = {}))[s] || []).slice(), n = 0, i = e.length;
68
+ for (n; n < i; n++)
69
+ e[n].fn.apply(e[n].ctx, t);
70
+ return this;
71
+ },
72
+ off: function(s, t) {
73
+ var e = this.e || (this.e = {}), n = e[s], i = [];
74
+ if (n && t)
75
+ for (var o = 0, l = n.length; o < l; o++)
76
+ n[o].fn !== t && n[o].fn._ !== t && i.push(n[o]);
77
+ return i.length ? e[s] = i : delete e[s], this;
78
+ }
79
+ };
80
+ w.exports = b;
81
+ var D = w.exports.TinyEmitter = b;
82
+ const y = new D();
83
+ function E(s) {
84
+ const t = document.createDocumentFragment(), e = document.createElement("div");
85
+ for (e.innerHTML = s; e.firstChild; )
86
+ t.append(e.firstChild);
87
+ return t;
88
+ }
89
+ function I(s) {
90
+ const t = document.importNode(s), e = s.offsetWidth;
91
+ t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;
92
+ const n = E("<span>Foo</span>"), i = E("<span>Foo</span>"), o = document.createElement("li"), l = document.createElement("li");
93
+ o.append(n), l.append(i), t.append(o), t.append(l), s.parentNode?.append(t);
94
+ const u = t.offsetHeight / 2;
95
+ return s.parentNode?.removeChild(t), u;
96
+ }
97
+ function L(s, t, e = !1) {
98
+ const n = `_${Math.random().toString(36).slice(2, 11)}`;
99
+ if (typeof t != "string" && "text" in t) {
100
+ const u = `<span>${t.text}</span>`, f = E(u), c = document.createElement("li");
101
+ return 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 = n, c.className = t.classname, c.append(f), s.append(c), y.emit(
102
+ p.ADD_MENU_ENTRY,
103
+ {
104
+ id: n,
105
+ isSubmenu: e,
106
+ isSeparator: !1,
107
+ callback: "callback" in t ? t.callback : null,
108
+ data: "data" in t ? t.data : null
109
+ },
110
+ c
111
+ ), c;
112
+ }
113
+ const i = `<li id="${n}" class="${r.separator}"><hr></li>`, o = E(i);
114
+ s.append(o);
115
+ const l = s.lastChild;
116
+ return y.emit(
117
+ p.ADD_MENU_ENTRY,
118
+ {
119
+ id: n,
120
+ isSubmenu: e,
121
+ isSeparator: !0,
122
+ callback: null,
123
+ data: null
124
+ },
125
+ l
126
+ ), l;
127
+ }
128
+ function v(s, t, e) {
129
+ t.forEach((n) => {
130
+ if (typeof n != "string" && "items" in n && Array.isArray(n.items)) {
131
+ const i = L(s, n, !0);
132
+ i.classList.add(r.submenu);
133
+ const o = document.createElement("ul");
134
+ o.classList.add(r.container), o.style.width = `${e}px`, i.append(o), v(o, n.items, e);
135
+ } else
136
+ L(s, n);
137
+ });
138
+ }
139
+ function g(s, t) {
140
+ if (!s)
141
+ throw new Error(t);
142
+ }
143
+ class z extends T {
144
+ constructor(e = {}) {
145
+ g(typeof e == "object", "@param `opts` should be object type!");
146
+ const n = document.createElement("div");
147
+ super({ element: n });
148
+ a(this, "map");
149
+ a(this, "container");
150
+ a(this, "coordinate", []);
151
+ a(this, "pixel", []);
152
+ a(this, "contextMenuEventListener");
153
+ a(this, "entryCallbackEventListener");
154
+ a(this, "mapMoveListener");
155
+ a(this, "lineHeight", 0);
156
+ a(this, "disabled");
157
+ a(this, "opened");
158
+ a(this, "items", []);
159
+ a(this, "menuEntries", /* @__PURE__ */ new Map());
160
+ a(this, "options");
161
+ this.options = { ...O, ...e };
162
+ const i = document.createElement("ul");
163
+ n.append(i), n.style.width = `${this.options.width}px`, n.classList.add(
164
+ r.container,
165
+ r.unselectable,
166
+ r.hidden
167
+ ), this.container = n, this.contextMenuEventListener = (o) => {
168
+ this.handleContextMenu(o);
169
+ }, this.entryCallbackEventListener = (o) => {
170
+ this.handleEntryCallback(o);
171
+ }, this.mapMoveListener = () => {
172
+ this.handleMapMove();
173
+ }, this.disabled = !1, this.opened = !1, y.on(
174
+ p.ADD_MENU_ENTRY,
175
+ (o, l) => {
176
+ this.handleAddMenuEntry(o, l);
177
+ },
178
+ this
179
+ );
180
+ }
181
+ clear() {
182
+ for (const e of this.menuEntries.keys())
183
+ this.removeMenuEntry(e);
184
+ this.container.replaceChildren();
185
+ }
186
+ enable() {
187
+ this.disabled = !1;
188
+ }
189
+ disable() {
190
+ this.disabled = !0;
191
+ }
192
+ getDefaultItems() {
193
+ return x;
194
+ }
195
+ countItems() {
196
+ return this.menuEntries.size;
197
+ }
198
+ extend(e) {
199
+ g(Array.isArray(e), "@param `items` should be an Array."), v(
200
+ this.container.firstElementChild,
201
+ e,
202
+ this.options.width
203
+ );
204
+ }
205
+ closeMenu() {
206
+ this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(p.CLOSE);
207
+ }
208
+ isOpen() {
209
+ return this.opened;
210
+ }
211
+ updatePosition(e) {
212
+ g(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
213
+ }
214
+ pop() {
215
+ const e = Array.from(this.menuEntries.keys()).pop();
216
+ e && this.removeMenuEntry(e);
217
+ }
218
+ shift() {
219
+ const e = Array.from(this.menuEntries.keys()).shift();
220
+ e && this.removeMenuEntry(e);
221
+ }
222
+ push(e) {
223
+ e && this.extend([e]);
224
+ }
225
+ setMap(e) {
226
+ if (super.setMap(e), e) {
227
+ this.map = e, this.map.getViewport().addEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.map.on("movestart", () => {
228
+ this.handleMapMove();
229
+ }), this.items = this.options.defaultItems ? this.options.items.concat(x) : this.options.items, v(
230
+ this.container.firstElementChild,
231
+ this.items,
232
+ this.options.width
233
+ );
234
+ const n = this.getMenuEntriesLength();
235
+ this.lineHeight = n > 0 ? this.container.offsetHeight / n : I(this.container);
236
+ } else
237
+ this.removeListeners(), this.clear();
238
+ }
239
+ removeListeners() {
240
+ this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1);
241
+ }
242
+ removeMenuEntry(e) {
243
+ const n = document.getElementById(e);
244
+ n?.remove(), n?.removeEventListener("click", this.entryCallbackEventListener), this.menuEntries.delete(e);
245
+ }
246
+ handleContextMenu(e) {
247
+ this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent({
248
+ type: p.BEFOREOPEN,
249
+ pixel: this.pixel,
250
+ coordinate: this.coordinate
251
+ }), !this.disabled && (this.options.eventType === M.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), this.openMenu(), e.target?.addEventListener(
252
+ "pointerdown",
253
+ (n) => {
254
+ this.opened && (n.stopPropagation(), this.closeMenu());
255
+ },
256
+ { once: !0 }
257
+ ));
258
+ }
259
+ openMenu() {
260
+ this.menuEntries.size !== 0 && (this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden));
261
+ }
262
+ getMenuEntriesLength() {
263
+ return Array.from(this.menuEntries).filter(
264
+ ([, e]) => e.isSeparator === !1 || e.isSubmenu === !1
265
+ ).length;
266
+ }
267
+ positionContainer() {
268
+ const e = this.map.getSize() || [0, 0], n = {
269
+ w: e[0] - this.pixel[0],
270
+ h: e[1] - this.pixel[1]
271
+ }, i = {
272
+ w: this.container.offsetWidth,
273
+ h: Math.round(this.lineHeight * this.getMenuEntriesLength())
274
+ }, o = n.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w;
275
+ 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;
276
+ const l = (c) => Array.from(c.children).filter(
277
+ (m) => m.tagName === "LI" && m.classList.contains(r.submenu)
278
+ );
279
+ let u = 0;
280
+ const f = (c, m) => {
281
+ u += 1, l(c).forEach((C) => {
282
+ const A = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = C.querySelector(
283
+ `ul.${r.container}`
284
+ ), $ = Math.round(
285
+ this.lineHeight * Array.from(h.children).filter((N) => N.tagName === "LI").length
286
+ );
287
+ h.style.left = `${A}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(u), l(h).length > 0 && f(h, m - i.w);
288
+ });
289
+ };
290
+ f(this.container.firstElementChild, n.w);
291
+ }
292
+ handleMapMove() {
293
+ this.closeMenu();
294
+ }
295
+ handleEntryCallback(e) {
296
+ e.preventDefault(), e.stopPropagation();
297
+ const n = e.currentTarget, i = this.menuEntries.get(n.id);
298
+ if (!i)
299
+ return;
300
+ const o = {
301
+ coordinate: this.coordinate,
302
+ data: i.data
303
+ };
304
+ this.closeMenu(), i.callback?.(o, this.map);
305
+ }
306
+ handleAddMenuEntry(e, n) {
307
+ this.menuEntries.set(e.id, e), "callback" in e && typeof e.callback == "function" && n.addEventListener("click", this.entryCallbackEventListener, !1);
308
+ }
309
+ }
310
+ window.ol?.control && (window.ol.control.ContextMenu = z);
311
+ export {
312
+ z as default
313
+ };
@@ -0,0 +1 @@
1
+ (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 z=Object.defineProperty;var H=(l,c,f)=>c in l?z(l,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[c]=f;var a=(l,c,f)=>(H(l,typeof c!="symbol"?c+"":c,f),f);const f=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(l);var M=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(M||{}),m=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(m||{});const S={width:150,scrollAt:4,eventType:M.CONTEXTMENU,defaultItems:!0,items:[]},p="ol-ctx-menu",r={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"},C=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var A={exports:{}};function x(){}x.prototype={on:function(n,i,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:i,ctx:e}),this},once:function(n,i,e){var t=this;function s(){t.off(n,s),i.apply(e,arguments)}return s._=i,this.on(n,s,e)},emit:function(n){var i=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,s=e.length;for(t;t<s;t++)e[t].fn.apply(e[t].ctx,i);return this},off:function(n,i){var e=this.e||(this.e={}),t=e[n],s=[];if(t&&i)for(var o=0,h=t.length;o<h;o++)t[o].fn!==i&&t[o].fn._!==i&&s.push(t[o]);return s.length?e[n]=s:delete e[n],this}},A.exports=x;var k=A.exports.TinyEmitter=x;const b=new k;function y(n){const i=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)i.append(e.firstChild);return i}function T(n){const i=document.importNode(n),e=n.offsetWidth;i.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=y("<span>Foo</span>"),s=y("<span>Foo</span>"),o=document.createElement("li"),h=document.createElement("li");o.append(t),h.append(s),i.append(o),i.append(h),n.parentNode?.append(i);const E=i.offsetHeight/2;return n.parentNode?.removeChild(i),E}function $(n,i,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof i!="string"&&"text"in i){const E=`<span>${i.text}</span>`,v=y(E),u=document.createElement("li");return i.classname=i.classname||"",i.icon&&(i.classname===""?i.classname=r.icon:i.classname.includes(r.icon)===!1&&(i.classname+=` ${r.icon}`),u.setAttribute("style",`background-image:url(${i.icon})`)),u.id=t,u.className=i.classname,u.append(v),n.append(u),b.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in i?i.callback:null,data:"data"in i?i.data:null},u),u}const s=`<li id="${t}" class="${r.separator}"><hr></li>`,o=y(s);n.append(o);const h=n.lastChild;return b.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},h),h}function L(n,i,e){i.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const s=$(n,t,!0);s.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,s.append(o),L(o,t.items,e)}else $(n,t)})}const P="";function w(n,i){if(!n)throw new Error(i)}class N extends f.default{constructor(e={}){w(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={...S,...e};const s=document.createElement("ul");t.append(s),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,b.on(m.ADD_MENU_ENTRY,(o,h)=>{this.handleAddMenuEntry(o,h)},this)}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren()}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return C}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(r.hidden),this.dispatchEvent(m.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()}),this.items=this.options.defaultItems?this.options.items.concat(C):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:T(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1)}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({type:m.BEFOREOPEN,pixel:this.pixel,coordinate:this.coordinate}),!this.disabled&&(this.options.eventType===M.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),this.openMenu(),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden))}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]},s={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=s.w?this.pixel[0]+5:this.pixel[0]-s.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=s.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-s.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=s.w;const h=u=>Array.from(u.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const v=(u,g)=>{E+=1,h(u).forEach(_=>{const D=g>=s.w?s.w-8:(s.w+8)*-1,d=_.querySelector(`ul.${r.container}`),O=Math.round(this.lineHeight*Array.from(d.children).filter(I=>I.tagName==="LI").length);d.style.left=`${D}px`,d.style.right="auto",d.style.top=t.h>=O+s.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(E),h(d).length>0&&v(d,g-s.w)})};v(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=this.menuEntries.get(t.id);if(!s)return;const o={coordinate:this.coordinate,data:s.data};this.closeMenu(),s.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 window.ol?.control&&(window.ol.control.ContextMenu=N),N});
package/package.json CHANGED
@@ -1,53 +1,63 @@
1
1
  {
2
- "name": "ol-contextmenu",
3
- "version": "4.0.0",
4
- "description": "Custom Context Menu for Openlayers",
5
- "main": "dist/ol-contextmenu.js",
6
- "author": "Jonatas Walker",
7
- "homepage": "https://github.com/jonataswalker/ol-contextmenu",
8
- "license": "MIT",
9
- "repository": {
10
- "type": "git",
11
- "url": "git://github.com/jonataswalker/ol-contextmenu.git"
12
- },
13
- "bugs": {
14
- "url": "https://github.com/jonataswalker/ol-contextmenu/issues"
15
- },
16
- "files": [
17
- "dist/"
18
- ],
19
- "scripts": {
20
- "dev": "rollup -w -c",
21
- "build": "rollup -c",
22
- "test": "npm run build && npm run test:unit",
23
- "test:unit": "jest",
24
- "test:unit:watch": "jest --watch"
25
- },
26
- "dependencies": {},
27
- "devDependencies": {
28
- "@babel/core": "^7.7.2",
29
- "@babel/preset-env": "^7.7.1",
30
- "autoprefixer": "^9.7.2",
31
- "babel-jest": "^24.9.0",
32
- "canvas": "^2.6.0",
33
- "eslint": "^6.6.0",
34
- "eslint-config-jwalker": "^5.2.0",
35
- "eslint-config-prettier": "^6.7.0",
36
- "eslint-plugin-jest": "^23.0.4",
37
- "eslint-plugin-prettier": "^3.1.1",
38
- "jest": "^24.9.0",
39
- "ol": "^6.1.1",
40
- "postcss": "^7.0.23",
41
- "prettier": "^1.19.1",
42
- "rollup": "^1.27.2",
43
- "rollup-plugin-buble": "^0.19.8",
44
- "rollup-plugin-commonjs": "^10.1.0",
45
- "rollup-plugin-eslint": "^7.0.0",
46
- "rollup-plugin-filesize": "^6.2.1",
47
- "rollup-plugin-includepaths": "^0.2.3",
48
- "rollup-plugin-node-resolve": "^5.2.0",
49
- "rollup-plugin-sass": "^1.2.2",
50
- "rollup-plugin-terser": "^5.1.2",
51
- "should": "^13.2.3"
52
- }
2
+ "name": "ol-contextmenu",
3
+ "version": "5.0.0-alpha",
4
+ "description": "Custom Context Menu for Openlayers",
5
+ "type": "module",
6
+ "main": "./dist/ol-contextmenu.umd.cjs",
7
+ "module": "./dist/ol-contextmenu.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/ol-contextmenu.js",
11
+ "require": "./dist/ol-contextmenu.umd.cjs"
12
+ }
13
+ },
14
+ "types": "./dist/ol-contextmenu.d.ts",
15
+ "author": "Jonatas Walker",
16
+ "homepage": "https://github.com/jonataswalker/ol-contextmenu",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git://github.com/jonataswalker/ol-contextmenu.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/jonataswalker/ol-contextmenu/issues"
24
+ },
25
+ "engines": {
26
+ "node": "^16 || ^18",
27
+ "npm": ">=8"
28
+ },
29
+ "files": [
30
+ "dist/"
31
+ ],
32
+ "scripts": {
33
+ "dev": "vite",
34
+ "build": "npm run generate-types && tsc && vite build",
35
+ "preview": "vite preview",
36
+ "lint": "eslint --cache --cache-location .eslintcache/ --ext .js .",
37
+ "lint:fix": "npm run lint -- --fix",
38
+ "generate-types": "tsc src/**/*.ts --declaration --declarationMap --emitDeclarationOnly --outdir dist",
39
+ "test": "npm run build && npm run test:unit",
40
+ "test:unit": "jest",
41
+ "test:unit:watch": "jest --watch"
42
+ },
43
+ "devDependencies": {
44
+ "@types/ol": "^6.5.3",
45
+ "@vitejs/plugin-legacy": "^2.0.1",
46
+ "canvas": "^2.9.3",
47
+ "eslint": "^8.22.0",
48
+ "eslint-config-jwalker": "^7.9.2",
49
+ "eslint-config-prettier": "^8.5.0",
50
+ "eslint-plugin-prettier": "^4.2.1",
51
+ "ol": "^7.0.0",
52
+ "prettier": "^2.7.1",
53
+ "rollup-plugin-terser": "^7.0.2",
54
+ "typescript": "^4.7.4",
55
+ "vite": "^3.0.9"
56
+ },
57
+ "peerDependencies": {
58
+ "ol": "^6.15.1"
59
+ },
60
+ "dependencies": {
61
+ "tiny-emitter": "^2.1.0"
62
+ }
53
63
  }