@defra/interactive-map 0.0.59-alpha → 0.0.61-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.
Files changed (125) hide show
  1. package/assets/templates/add-polygons.njk +2 -2
  2. package/assets/templates/add-symbols.njk +2 -2
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/button-definition.md +11 -0
  9. package/docs/api/context.md +2 -0
  10. package/docs/api/panel-definition.md +30 -0
  11. package/docs/api/symbol-config.md +12 -0
  12. package/docs/api.md +21 -2
  13. package/docs/assets/images/slot-map.svg +3 -3
  14. package/docs/plugins/datasets.md +11 -1
  15. package/docs/plugins/draw.md +26 -0
  16. package/package.json +1 -1
  17. package/plugins/datasets/dist/esm/index.js +1 -1
  18. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  20. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  21. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  22. package/plugins/datasets/dist/umd/index.js +1 -1
  23. package/plugins/datasets/src/index.js +0 -1
  24. package/plugins/datasets/src/index.test.js +2 -8
  25. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  26. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  27. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  28. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  29. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  30. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  31. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  32. package/plugins/draw/dist/umd/index.js +1 -1
  33. package/plugins/draw/src/DrawInit.jsx +3 -0
  34. package/plugins/draw/src/DrawInit.test.jsx +16 -0
  35. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
  36. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  37. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
  38. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
  39. package/plugins/draw/src/defaults.js +4 -0
  40. package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
  41. package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
  42. package/plugins/draw/src/manifest.js +4 -1
  43. package/plugins/draw/src/manifest.test.js +15 -2
  44. package/plugins/draw/src/utils/snapMinZoom.js +8 -0
  45. package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
  46. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  47. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  48. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  49. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  50. package/plugins/map-key/src/manifest.js +1 -1
  51. package/plugins/search/dist/css/index.css +1 -1
  52. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  53. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  54. package/providers/esri/src/esriProvider.js +10 -21
  55. package/providers/esri/src/utils/coords.js +37 -7
  56. package/providers/esri/src/utils/coords.test.js +22 -1
  57. package/providers/esri/src/utils/spatial.js +1 -47
  58. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  59. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  60. package/providers/maplibre/src/maplibreProvider.js +5 -14
  61. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  62. package/providers/maplibre/src/utils/spatial.js +0 -40
  63. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  64. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  65. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  66. package/providers/openlayers/src/openlayersProvider.js +5 -14
  67. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  68. package/providers/openlayers/src/utils/spatial.js +0 -39
  69. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  70. package/src/App/components/Hints/Hints.jsx +9 -21
  71. package/src/App/components/Hints/Hints.test.jsx +20 -33
  72. package/src/App/components/MapButton/MapButton.jsx +20 -2
  73. package/src/App/components/MapButton/MapButton.module.scss +15 -1
  74. package/src/App/components/MapButton/MapButton.test.jsx +21 -3
  75. package/src/App/components/Panel/Panel.jsx +16 -1
  76. package/src/App/components/Panel/Panel.test.jsx +44 -0
  77. package/src/App/components/Tooltip/Tooltip.jsx +29 -11
  78. package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
  79. package/src/App/components/Viewport/MapController.jsx +2 -0
  80. package/src/App/components/Viewport/MapController.test.jsx +3 -0
  81. package/src/App/hooks/useCrossHairAPI.js +27 -28
  82. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  83. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  84. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  85. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  86. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  87. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  88. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  89. package/src/App/hooks/useUserMoveTracking.js +65 -0
  90. package/src/App/hooks/useUserMoveTracking.test.js +99 -0
  91. package/src/App/hooks/useVisibleGeometry.js +35 -45
  92. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  93. package/src/App/layout/Layout.jsx +4 -4
  94. package/src/App/layout/layout.module.scss +124 -61
  95. package/src/App/renderer/mapButtons.js +1 -0
  96. package/src/App/renderer/mapButtons.test.js +8 -0
  97. package/src/App/store/AppProvider.jsx +3 -0
  98. package/src/App/store/appDispatchMiddleware.js +18 -10
  99. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  100. package/src/App/store/mapActionsMap.js +2 -1
  101. package/src/App/store/mapActionsMap.test.js +6 -0
  102. package/src/App/store/mapReducer.js +2 -0
  103. package/src/App/store/mapReducer.test.js +1 -0
  104. package/src/InteractiveMap/InteractiveMap.js +3 -2
  105. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  106. package/src/config/events.js +1 -1
  107. package/src/config/mapPanelSlots.js +8 -0
  108. package/src/config/symbolConfig.js +1 -1
  109. package/src/scss/settings/_colors.scss +4 -0
  110. package/src/services/symbolRegistry.js +1 -1
  111. package/src/services/symbolRegistry.test.js +19 -0
  112. package/src/types.js +33 -8
  113. package/src/utils/getFitMove.js +73 -0
  114. package/src/utils/getFitMove.test.js +114 -0
  115. package/src/utils/getSafeZoneInset.js +122 -77
  116. package/src/utils/getSafeZoneInset.test.js +241 -54
  117. package/src/utils/getValueForStyle.js +10 -5
  118. package/src/utils/getValueForStyle.test.js +13 -2
  119. package/src/utils/renderedBoxes.js +25 -0
  120. package/src/utils/renderedBoxes.test.js +61 -0
  121. package/src/utils/screenBox.js +70 -0
  122. package/src/utils/screenBox.test.js +69 -0
  123. package/src/utils/symbolUtils.js +9 -9
  124. package/src/utils/symbolUtils.test.js +21 -0
  125. package/providers/esri/src/utils/spatial.test.js +0 -58
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("defra",[],e):"object"==typeof exports?exports.defra=e():(t.defra=t.defra||{},t.defra.drawPlugin=e())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var t,e,r={738:function(t){t.exports=preactCompat}},n={};function o(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=function(t,e){for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=function(t){return Promise.all(Object.keys(o.f).reduce(function(e,r){return o.f[r](t,e),e},[]))},o.u=function(t){return{356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[t]+".js"},o.miniCssF=function(t){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t={},e="defra.drawPlugin:",o.l=function(r,n,i,u){if(t[r])t[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==r||p.getAttribute("data-webpack")==e+i){c=p;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",e+i),c.src=r),t[r]=[n];var s=function(e,n){c.onerror=c.onload=null,clearTimeout(d);var o=t[r];if(delete t[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(t){return t(n)}),e)return e(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=s.bind(null,c.onerror),c.onload=s.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},function(){var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t}(),function(){var t={57:0};o.f.j=function(e,r){var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=t[e]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(e),c=new Error;o.l(u,function(r){if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+e,e)}};var e=function(e,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(e){return 0!==t[e]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(e&&e(r);f<u.length;f++)i=u[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))}();var i={};function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof f?n:f,l=Object.create(c.prototype);return a(l,"_invoke",function(r,n,o){var i,c,a,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,c=0,a=t,s.n=r,u}};function d(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<l.length;e++){var o,i=l[e],d=s.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),c=l,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=s.n<0)?a:r.call(n,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),l}var u={};function f(){}function l(){}function p(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),d=p.prototype=f.prototype=Object.create(s);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t}return l.prototype=p,a(d,"constructor",p),a(p,"constructor",l),l.displayName="GeneratorFunction",a(p,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,n,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:b}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function f(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(){var t,e;return p(p({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=c().m(function t(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,o.e(568).then(o.bind(o,806));case 1:return e=t.v.manifest,t.a(2,e)}},t)}),e=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){f(i,n,o,u,c,"next",t)}function c(t){f(i,n,o,u,c,"throw",t)}u(void 0)})},function(){return e.apply(this,arguments)})})}return o.d(i,{default:function(){return d}}),i.default}()});
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("defra",[],e):"object"==typeof exports?exports.defra=e():(t.defra=t.defra||{},t.defra.drawPlugin=e())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var t,e,r={738:function(t){t.exports=preactCompat}},n={};function o(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=function(t,e){for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=function(t){return Promise.all(Object.keys(o.f).reduce(function(e,r){return o.f[r](t,e),e},[]))},o.u=function(t){return{356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[t]+".js"},o.miniCssF=function(t){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t={},e="defra.drawPlugin:",o.l=function(r,n,i,u){if(t[r])t[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==r||p.getAttribute("data-webpack")==e+i){c=p;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",e+i),c.src=r),t[r]=[n];var s=function(e,n){c.onerror=c.onload=null,clearTimeout(d);var o=t[r];if(delete t[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(t){return t(n)}),e)return e(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=s.bind(null,c.onerror),c.onload=s.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},function(){var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t}(),function(){var t={57:0};o.f.j=function(e,r){var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=t[e]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(e),c=new Error;o.l(u,function(r){if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+e,e)}};var e=function(e,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(e){return 0!==t[e]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(e&&e(r);f<u.length;f++)i=u[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))}();var i={};function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof f?n:f,l=Object.create(c.prototype);return a(l,"_invoke",function(r,n,o){var i,c,a,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,c=0,a=t,s.n=r,u}};function d(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<l.length;e++){var o,i=l[e],d=s.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),c=l,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=s.n<0)?a:r.call(n,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),l}var u={};function f(){}function l(){}function p(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),d=p.prototype=f.prototype=Object.create(s);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t}return l.prototype=p,a(d,"constructor",p),a(p,"constructor",l),l.displayName="GeneratorFunction",a(p,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,n,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:b}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function f(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(){var t,e;return p(p({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=c().m(function t(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,o.e(568).then(o.bind(o,579));case 1:return e=t.v.manifest,t.a(2,e)}},t)}),e=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){f(i,n,o,u,c,"next",t)}function c(t){f(i,n,o,u,c,"throw",t)}u(void 0)})},function(){return e.apply(this,arguments)})})}return o.d(i,{default:function(){return d}}),i.default}()});
@@ -3,6 +3,7 @@ import { EVENTS } from '../../../src/config/events.js'
3
3
  import { loadDrawAdapter } from './adapters/loadDrawAdapter.js'
4
4
  import { attachEvents } from './events.js'
5
5
  import { useSpatialList } from './hooks/useSpatialList.js'
6
+ import { useSnapMinZoom } from './hooks/useSnapMinZoom.js'
6
7
  import { APPLICATION_MODE_ID } from './defaults.js'
7
8
  import { needsDrawTarget } from './utils/needsDrawTarget.js'
8
9
  import { isDrawingMode, isSessionMode } from './utils/drawModes.js'
@@ -78,6 +79,8 @@ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginSt
78
79
 
79
80
  useLoadDrawAdapter({ mapState, pluginConfig, pluginState, mapProvider, eventBus, symbolRegistry })
80
81
 
82
+ useSnapMinZoom({ mapState, pluginConfig, pluginState, mapProvider, hints })
83
+
81
84
  // Enters the 'draw' application mode (declared in the manifest) in any draw/edit mode, and leaves it
82
85
  // when the draw/edit mode ends. useLayoutEffect so the class lands in the same paint as the change.
83
86
  useLayoutEffect(() => {
@@ -5,11 +5,13 @@ import { DrawInit } from './DrawInit.jsx'
5
5
  import { loadDrawAdapter } from './adapters/loadDrawAdapter.js'
6
6
  import { attachEvents } from './events.js'
7
7
  import { useSpatialList } from './hooks/useSpatialList.js'
8
+ import { useSnapMinZoom } from './hooks/useSnapMinZoom.js'
8
9
 
9
10
  jest.mock('./adapters/loadDrawAdapter.js', () => ({ loadDrawAdapter: jest.fn() }))
10
11
  jest.mock('../../../src/services/logger.js', () => ({ logger: { error: jest.fn() } }))
11
12
  jest.mock('./events.js', () => ({ attachEvents: jest.fn(() => jest.fn()) }))
12
13
  jest.mock('./hooks/useSpatialList.js', () => ({ useSpatialList: jest.fn() }))
14
+ jest.mock('./hooks/useSnapMinZoom.js', () => ({ useSnapMinZoom: jest.fn() }))
13
15
 
14
16
  const makeProps = (overrides = {}) => {
15
17
  const adapter = { remove: jest.fn(), setInterfaceType: jest.fn() }
@@ -253,6 +255,20 @@ describe('useSpatialList wiring', () => {
253
255
  })
254
256
  })
255
257
 
258
+ describe('useSnapMinZoom wiring', () => {
259
+ test('is called with the map and plugin state, the map provider and the hints service', async () => {
260
+ const { props } = makeProps({ pluginState: { dispatch: jest.fn(), mode: 'draw_line' } })
261
+ await renderInit(props)
262
+ expect(useSnapMinZoom).toHaveBeenCalledWith({
263
+ mapState: props.mapState,
264
+ pluginConfig: props.pluginConfig,
265
+ pluginState: props.pluginState,
266
+ mapProvider: props.mapProvider,
267
+ hints: props.services.hints
268
+ })
269
+ })
270
+ })
271
+
256
272
  describe('crosshair', () => {
257
273
  test('fixes the crosshair at centre while drawing on a touch interface', async () => {
258
274
  const { props } = makeProps({
@@ -68,6 +68,7 @@ export const displayedShape = (mode, coordinates) => {
68
68
  * setGeometry(geometry)
69
69
  * get(id) / add(feature) / setStyle(id, properties) / setProperties(id, properties) / delete(id) / deleteAll()
70
70
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
71
+ * setSnapAvailable(bool)
71
72
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
72
73
  * on(event, handler) / off(event, handler)
73
74
  * remove()
@@ -82,6 +83,7 @@ export class MaplibreDrawAdapter {
82
83
  // Assigned once per feature, on creation only (see styles.js's SORT_KEY_PROP) — drives
83
84
  // paint order so a later-drawn feature reliably layers above an earlier one.
84
85
  this._sortKeyCounter = 0
86
+ this._snapAvailable = true
85
87
 
86
88
  const { draw, remove } = createMapboxDraw({
87
89
  mapStyle: options.mapStyle,
@@ -370,9 +372,23 @@ export class MaplibreDrawAdapter {
370
372
 
371
373
  setSnapEnabled (bool) {
372
374
  this._mapProvider.snapEnabled = bool
375
+ this._applySnapStatus()
376
+ }
377
+
378
+ // Snaps only while the user has snap on and it's available
379
+ setSnapAvailable (bool) {
380
+ if (bool === this._snapAvailable) {
381
+ return
382
+ }
383
+ this._snapAvailable = bool
384
+ this._applySnapStatus()
385
+ }
386
+
387
+ _applySnapStatus () {
388
+ const isActive = this.isSnapEnabled()
373
389
  const snap = getSnapInstance(this._map)
374
- if (snap?.setSnapStatus) { snap.setSnapStatus(bool) }
375
- if (!bool && snap) {
390
+ if (snap?.setSnapStatus) { snap.setSnapStatus(isActive) }
391
+ if (!isActive && snap) {
376
392
  clearSnapState(snap)
377
393
  if (this._map.getLayer('snap-helper-circle')) {
378
394
  this._map.setLayoutProperty('snap-helper-circle', 'visibility', 'none')
@@ -392,7 +408,7 @@ export class MaplibreDrawAdapter {
392
408
  }
393
409
 
394
410
  isSnapEnabled () {
395
- return this._mapProvider.snapEnabled === true
411
+ return this._mapProvider.snapEnabled === true && this._snapAvailable
396
412
  }
397
413
 
398
414
  setFeatureProperty (id, property, value) {
@@ -1164,3 +1164,30 @@ describe('remove', () => {
1164
1164
  expect(removeDraw).toHaveBeenCalled()
1165
1165
  })
1166
1166
  })
1167
+
1168
+ describe('snap availability', () => {
1169
+ test('snaps only while snap is on and available, keeping the user\'s choice', () => {
1170
+ const { adapter, mapProvider } = setup()
1171
+ const snap = { setSnapStatus: jest.fn() }
1172
+ getSnapInstance.mockReturnValue(snap)
1173
+ adapter.setSnapEnabled(true)
1174
+
1175
+ adapter.setSnapAvailable(false)
1176
+ expect(snap.setSnapStatus).toHaveBeenLastCalledWith(false)
1177
+ expect(clearSnapState).toHaveBeenCalledWith(snap)
1178
+ expect(adapter.isSnapEnabled()).toBe(false)
1179
+ expect(mapProvider.snapEnabled).toBe(true)
1180
+
1181
+ adapter.setSnapAvailable(true)
1182
+ expect(snap.setSnapStatus).toHaveBeenLastCalledWith(true)
1183
+ expect(adapter.isSnapEnabled()).toBe(true)
1184
+ })
1185
+
1186
+ test('does nothing when availability hasn\'t changed', () => {
1187
+ const { adapter } = setup()
1188
+ const snap = { setSnapStatus: jest.fn() }
1189
+ getSnapInstance.mockReturnValue(snap)
1190
+ adapter.setSnapAvailable(true)
1191
+ expect(snap.setSnapStatus).not.toHaveBeenCalled()
1192
+ })
1193
+ })
@@ -31,12 +31,14 @@ const DRAW_OUTLINE_STYLE_LAYER = 'stroke-inactive.cold'
31
31
  * setGeometry(geometry)
32
32
  * get(id) / add(feature) / setStyle(id, properties) / setProperties(id, properties) / delete(id) / deleteAll()
33
33
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
34
+ * setSnapAvailable(bool)
34
35
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
35
36
  * on(event, handler) / off(event, handler)
36
37
  * remove()
37
38
  */
38
39
  export class OLDrawAdapter {
39
40
  _snapEnabled = false
41
+ _snapAvailable = true
40
42
 
41
43
  constructor (mapProvider, options) {
42
44
  const { manager, remove } = createOLDraw({
@@ -135,7 +137,13 @@ export class OLDrawAdapter {
135
137
 
136
138
  setSnapEnabled (bool) {
137
139
  this._snapEnabled = bool
138
- this._manager.snap?.setActive(bool)
140
+ this._manager.snap?.setActive(this.isSnapEnabled())
141
+ }
142
+
143
+ // Snaps only while the user has snap on and it's available
144
+ setSnapAvailable (bool) {
145
+ this._snapAvailable = bool
146
+ this._manager.snap?.setActive(this.isSnapEnabled())
139
147
  }
140
148
 
141
149
  setSnapLayers (layers) {
@@ -143,7 +151,7 @@ export class OLDrawAdapter {
143
151
  this._manager.snap?.setSnapLayers(translated)
144
152
  }
145
153
 
146
- isSnapEnabled () { return this._snapEnabled }
154
+ isSnapEnabled () { return this._snapEnabled && this._snapAvailable }
147
155
 
148
156
  setFeatureProperty () { /* not implemented for OL */ }
149
157
  setDrawingPreviewProperty (property, value) { this._manager.setDrawingPreviewProperty(property, value) }
@@ -289,3 +289,17 @@ test('remove runs the olDraw cleanup', () => {
289
289
  adapter.remove()
290
290
  expect(createOLDraw.mock.results.at(-1).value.remove).toHaveBeenCalled()
291
291
  })
292
+
293
+ test('snaps only while snap is on and available', () => {
294
+ const { manager, adapter } = setup()
295
+ adapter.setSnapEnabled(true)
296
+ adapter.setSnapAvailable(false)
297
+ expect(manager.snap.setActive).toHaveBeenLastCalledWith(false)
298
+ expect(adapter.isSnapEnabled()).toBe(false)
299
+ adapter.setSnapAvailable(true)
300
+ expect(manager.snap.setActive).toHaveBeenLastCalledWith(true)
301
+ expect(adapter.isSnapEnabled()).toBe(true)
302
+
303
+ manager.snap = null
304
+ expect(() => adapter.setSnapAvailable(false)).not.toThrow()
305
+ })
@@ -39,6 +39,10 @@ export const TOLERANCES = {
39
39
  snapRadius: 12
40
40
  }
41
41
 
42
+ // Shown when the user zooms below snapMinZoom, and read with the Snap button while it's
43
+ // disabled there. Overridden by snapZoomInHintText.
44
+ export const SNAP_ZOOM_IN_HINT_TEXT = 'Zoom in to use snap'
45
+
42
46
  export const KEYBOARD = {
43
47
  nudgeAmount: 1,
44
48
  stepAmount: 5
@@ -0,0 +1,29 @@
1
+ import { useEffect, useRef } from 'react'
2
+ import { isBelowSnapMinZoom, getSnapHintText } from '../utils/snapMinZoom.js'
3
+
4
+ /**
5
+ * Stops the adapter snapping below snapMinZoom, keeping the user's on/off choice. When the user
6
+ * has snap on and their own zoom takes the map below it during a draw or edit, a hint tells them
7
+ * to zoom in. Zooms made by code never show the hint.
8
+ */
9
+ export function useSnapMinZoom ({ mapState, pluginConfig, pluginState, mapProvider, hints }) {
10
+ const { zoom, isUserMove } = mapState
11
+ const { mode, hasSnapLayers, snap } = pluginState
12
+ const draw = mapProvider.draw
13
+ const isBelow = isBelowSnapMinZoom(pluginConfig, zoom)
14
+ const previousRef = useRef({ mode: null, isBelow: false })
15
+
16
+ useEffect(() => {
17
+ if (!draw) {
18
+ return
19
+ }
20
+ const previous = previousRef.current
21
+ previousRef.current = { mode, isBelow }
22
+ draw.setSnapAvailable(!isBelow)
23
+
24
+ const isZoomInSession = !!mode && previous.mode === mode && hasSnapLayers
25
+ if (isBelow && !previous.isBelow && isZoomInSession && snap && isUserMove) {
26
+ hints.show(getSnapHintText(pluginConfig))
27
+ }
28
+ }, [draw, mode, isBelow])
29
+ }
@@ -0,0 +1,82 @@
1
+ import { renderHook } from '@testing-library/react'
2
+ import { useSnapMinZoom } from './useSnapMinZoom.js'
3
+
4
+ const setup = ({ mode = 'draw_polygon', zoom = 16, isUserMove = true, hasSnapLayers = true, snap = true, snapMinZoom = 16, draw = { setSnapAvailable: jest.fn() } } = {}) => {
5
+ const hints = { show: jest.fn() }
6
+ const props = (overrides = {}) => ({
7
+ mapState: { zoom, isUserMove, ...overrides.mapState },
8
+ pluginConfig: { snapMinZoom, ...overrides.pluginConfig },
9
+ pluginState: { mode, hasSnapLayers, snap, ...overrides.pluginState },
10
+ mapProvider: { draw },
11
+ hints
12
+ })
13
+ const hook = renderHook((hookProps) => useSnapMinZoom(hookProps), { initialProps: props() })
14
+ const rerender = (overrides) => hook.rerender(props(overrides))
15
+ return { draw, hints, rerender }
16
+ }
17
+
18
+ describe('useSnapMinZoom', () => {
19
+ test('makes snapping unavailable below snapMinZoom, and available again at it', () => {
20
+ const { draw, rerender } = setup()
21
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(true)
22
+ rerender({ mapState: { zoom: 15 } })
23
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(false)
24
+ rerender({ mapState: { zoom: 16 } })
25
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(true)
26
+ })
27
+
28
+ test('shows the hint when the user zooms below snapMinZoom with snap on', () => {
29
+ const { hints, rerender } = setup()
30
+ rerender({ mapState: { zoom: 15 } })
31
+ expect(hints.show).toHaveBeenCalledWith('Zoom in to use snap')
32
+ })
33
+
34
+ test('shows the configured hint text', () => {
35
+ const { hints, rerender } = setup()
36
+ rerender({ mapState: { zoom: 15 }, pluginConfig: { snapZoomInHintText: 'Zoom in further' } })
37
+ expect(hints.show).toHaveBeenCalledWith('Zoom in further')
38
+ })
39
+
40
+ test('doesn\'t show the hint again while the map stays below snapMinZoom', () => {
41
+ const { hints, rerender } = setup()
42
+ rerender({ mapState: { zoom: 15 } })
43
+ rerender({ mapState: { zoom: 14 } })
44
+ expect(hints.show).toHaveBeenCalledTimes(1)
45
+ })
46
+
47
+ test('doesn\'t show the hint with snap off', () => {
48
+ const { draw, hints, rerender } = setup({ snap: false })
49
+ rerender({ mapState: { zoom: 15 } })
50
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(false)
51
+ expect(hints.show).not.toHaveBeenCalled()
52
+ })
53
+
54
+ test('doesn\'t show the hint when code zoomed the map', () => {
55
+ const { draw, hints, rerender } = setup()
56
+ rerender({ mapState: { zoom: 15, isUserMove: false } })
57
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(false)
58
+ expect(hints.show).not.toHaveBeenCalled()
59
+ })
60
+
61
+ test('doesn\'t show the hint when a draw or edit starts below snapMinZoom', () => {
62
+ const { hints, rerender } = setup({ mode: null, zoom: 12 })
63
+ rerender({ pluginState: { mode: 'draw_polygon' } })
64
+ expect(hints.show).not.toHaveBeenCalled()
65
+ })
66
+
67
+ test('doesn\'t show the hint outside a draw or edit, or without snap layers', () => {
68
+ const outside = setup({ mode: null })
69
+ outside.rerender({ mapState: { zoom: 15 } })
70
+ expect(outside.hints.show).not.toHaveBeenCalled()
71
+
72
+ const noLayers = setup({ hasSnapLayers: false })
73
+ noLayers.rerender({ mapState: { zoom: 15 } })
74
+ expect(noLayers.hints.show).not.toHaveBeenCalled()
75
+ })
76
+
77
+ test('waits for the adapter', () => {
78
+ const { hints, rerender } = setup({ draw: null })
79
+ rerender({ mapState: { zoom: 15 } })
80
+ expect(hints.show).not.toHaveBeenCalled()
81
+ })
82
+ })
@@ -16,6 +16,7 @@ import { isMac } from '../../../src/utils/isMac.js'
16
16
  import { APPLICATION_MODE_ID } from './defaults.js'
17
17
  import { needsDrawTarget } from './utils/needsDrawTarget.js'
18
18
  import { isShapeDrawMode, isCheckedMode } from './utils/drawModes.js'
19
+ import { isBelowSnapMinZoom, getSnapHintText } from './utils/snapMinZoom.js'
19
20
 
20
21
  // edit_point behaves like edit_vertex for Done/Undo, but stays out of drawDeletePoint and mergeShapes (neither applies to a single coordinate).
21
22
 
@@ -115,8 +116,10 @@ export const manifest = {
115
116
  label: 'Snap',
116
117
  iconId: 'magnet',
117
118
  hiddenWhen: ({ pluginState }) => !pluginState.mode || !pluginState.hasSnapLayers,
118
- enableWhen: ({ pluginState }) => !pluginState.holding,
119
+ // Also disabled below snapMinZoom, keeping the user's on/off choice
120
+ enableWhen: ({ pluginConfig, pluginState, mapState }) => !pluginState.holding && !isBelowSnapMinZoom(pluginConfig, mapState.zoom),
119
121
  pressedWhen: ({ pluginState }) => !!pluginState.snap,
122
+ description: ({ pluginConfig, mapState }) => isBelowSnapMinZoom(pluginConfig, mapState.zoom) ? getSnapHintText(pluginConfig) : undefined,
120
123
  ...createButtonSlots(true, TOOLBAR_SLOT)
121
124
  },
122
125
  {
@@ -195,8 +195,21 @@ describe('top row buttons', () => {
195
195
 
196
196
  test('is disabled while Done waits on a check', () => {
197
197
  expect(item().hiddenWhen({ pluginState: { mode: 'draw_line', hasSnapLayers: true, holding: true } })).toBe(false)
198
- expect(item().enableWhen({ pluginState: { holding: true } })).toBe(false)
199
- expect(item().enableWhen({ pluginState: { holding: false } })).toBe(true)
198
+ expect(item().enableWhen({ pluginState: { holding: true }, mapState: {} })).toBe(false)
199
+ expect(item().enableWhen({ pluginState: { holding: false }, mapState: {} })).toBe(true)
200
+ })
201
+
202
+ test('is disabled below snapMinZoom', () => {
203
+ const enabled = (zoom) => item().enableWhen({ pluginConfig: { snapMinZoom: 16 }, pluginState: { holding: false }, mapState: { zoom } })
204
+ expect(enabled(15)).toBe(false)
205
+ expect(enabled(16)).toBe(true)
206
+ })
207
+
208
+ test('is described with the hint below snapMinZoom', () => {
209
+ const description = (pluginConfig, zoom) => item().description({ pluginConfig: { snapMinZoom: 16, ...pluginConfig }, mapState: { zoom } })
210
+ expect(description({}, 15)).toBe('Zoom in to use snap')
211
+ expect(description({ snapZoomInHintText: 'Zoom in further' }, 15)).toBe('Zoom in further')
212
+ expect(description({}, 16)).toBeUndefined()
200
213
  })
201
214
 
202
215
  test('is visible during draw_point, which supports snapping but has no undo/delete', () => {
@@ -0,0 +1,8 @@
1
+ import { SNAP_ZOOM_IN_HINT_TEXT } from '../defaults.js'
2
+
3
+ /** Whether the map is zoomed out below snapMinZoom, so snapping isn't available */
4
+ export const isBelowSnapMinZoom = (pluginConfig, zoom) =>
5
+ typeof pluginConfig?.snapMinZoom === 'number' && typeof zoom === 'number' && zoom < pluginConfig.snapMinZoom
6
+
7
+ /** The hint telling the user to zoom in to use snap */
8
+ export const getSnapHintText = (pluginConfig) => pluginConfig?.snapZoomInHintText ?? SNAP_ZOOM_IN_HINT_TEXT
@@ -0,0 +1,22 @@
1
+ import { isBelowSnapMinZoom, getSnapHintText } from './snapMinZoom.js'
2
+
3
+ describe('isBelowSnapMinZoom', () => {
4
+ test('is true only below snapMinZoom', () => {
5
+ expect(isBelowSnapMinZoom({ snapMinZoom: 16 }, 15.9)).toBe(true)
6
+ expect(isBelowSnapMinZoom({ snapMinZoom: 16 }, 16)).toBe(false)
7
+ })
8
+
9
+ test('is false without a snapMinZoom or a zoom', () => {
10
+ expect(isBelowSnapMinZoom({}, 1)).toBe(false)
11
+ expect(isBelowSnapMinZoom(undefined, 1)).toBe(false)
12
+ expect(isBelowSnapMinZoom({ snapMinZoom: 16 }, undefined)).toBe(false)
13
+ })
14
+ })
15
+
16
+ describe('getSnapHintText', () => {
17
+ test('uses the configured text, or the default', () => {
18
+ expect(getSnapHintText({ snapZoomInHintText: 'Zoom in further' })).toBe('Zoom in further')
19
+ expect(getSnapHintText({})).toBe('Zoom in to use snap')
20
+ expect(getSnapHintText(undefined)).toBe('Zoom in to use snap')
21
+ })
22
+ })
@@ -1 +1 @@
1
- import{useCallback as e,useRef as t,useEffect as r,useMemo as n}from"preact/compat";const o={MAP_SET_SIZE:"map:setsize",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_STYLE_CHANGE:"map:stylechange",MAP_MOVE_END:"map:moveend",MAP_DATA_CHANGE:"map:datachange",MAP_CLICK:"map:click"};function i(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function a(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!u(e[0])||!u(e[1]))throw new Error("coordinates must contain numbers");return i({type:"Point",coordinates:e},t,r)}function s(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return i({type:"LineString",coordinates:e},t,r)}function l(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return i({type:"MultiLineString",coordinates:e},t,r)}function u(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}const d=11102230246251565e-32,p=134217729,f=(3+8*d)*d;function y(e,t,r,n,o){let i,a,s,l,c=t[0],u=n[0],d=0,p=0;u>c==u>-c?(i=c,c=t[++d]):(i=u,u=n[++p]);let f=0;if(d<e&&p<r)for(u>c==u>-c?(a=c+i,s=i-(a-c),c=t[++d]):(a=u+i,s=i-(a-u),u=n[++p]),i=a,0!==s&&(o[f++]=s);d<e&&p<r;)u>c==u>-c?(a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d]):(a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p]),i=a,0!==s&&(o[f++]=s);for(;d<e;)a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d],i=a,0!==s&&(o[f++]=s);for(;p<r;)a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p],i=a,0!==s&&(o[f++]=s);return 0===i&&0!==f||(o[f++]=i),f}function g(e){return new Float64Array(e)}const h=g(4),m=g(8),E=g(12),S=g(16),v=g(4);function b(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),l=a-s,c=Math.abs(a+s);return Math.abs(l)>=33306690738754716e-32*c?l:-function(e,t,r,n,o,i,a){let s,l,c,u,d,g,b,k,M,P,I,A,w,C,T,_,L,F;const x=e-o,R=r-o,B=t-i,D=n-i;C=x*D,g=p*x,b=g-(g-x),k=x-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=B*R,g=p*B,b=g-(g-B),k=B-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,h[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,h[1]=w-(I+d)+(d-_),F=A+I,d=F-A,h[2]=A-(F-d)+(I-d),h[3]=F;let G=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,h),O=22204460492503146e-32*a;if(G>=O||-G>=O)return G;if(d=e-x,s=e-(x+d)+(d-o),d=r-R,c=r-(R+d)+(d-o),d=t-B,l=t-(B+d)+(d-i),d=n-D,u=n-(D+d)+(d-i),0===s&&0===l&&0===c&&0===u)return G;if(O=11093356479670487e-47*a+f*Math.abs(G),G+=x*u+D*s-(B*c+R*l),G>=O||-G>=O)return G;C=s*D,g=p*s,b=g-(g-s),k=s-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=l*R,g=p*l,b=g-(g-l),k=l-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const H=y(4,h,4,v,m);C=x*u,g=p*x,b=g-(g-x),k=x-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=B*c,g=p*B,b=g-(g-B),k=B-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const N=y(H,m,4,v,E);C=s*u,g=p*s,b=g-(g-s),k=s-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=l*c,g=p*l,b=g-(g-l),k=l-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const K=y(N,E,4,v,S);return S[K-1]}(e,t,r,n,o,i,c)}function k(e,t){var r,n,o,i,a,s,l,c,u,d=0,p=e[0],f=e[1],y=t.length;for(r=0;r<y;r++){n=0;var g=t[r],h=g.length-1;if((c=g[0])[0]!==g[h][0]&&c[1]!==g[h][1])throw new Error("First and last coordinates in a ring must be the same");for(i=c[0]-p,a=c[1]-f;n<h;n++){if(s=(u=g[n+1])[0]-p,l=u[1]-f,0===a&&0===l){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(0===(o=b(i,s,a,l,0,0)))return 0;(o>0&&l>0&&a<=0||o<0&&l<=0&&a>0)&&d++}c=u,a=l,i=s}}return d%2!=0}function M(e){return"Feature"===e.type?e.geometry:e}function P(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(e),o=M(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let l=!1;for(var c=0;c<s.length;++c){const e=k(n,s[c]);if(0===e)return!r.ignoreBoundary;e&&(l=!0)}return l}class I{constructor(e=[],t=A){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function A(e,t){return e<t?-1:e>t?1:0}function w(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function C(e,t){return e.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:e.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:e.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?e.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}class T{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let _=0,L=0,F=0;function x(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;L+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new T(o,_,L,F),l=new T(i,_,L,F+1);s.otherEvent=l,l.otherEvent=s,w(s,l)>0?(l.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,l.isLeftEndpoint=!1),t.push(s),t.push(l),o=i,F+=1}}_+=1}class R{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function B(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,l=t.rightSweepEvent.p.x,c=t.rightSweepEvent.p.y,u=(c-s)*(o-r)-(l-a)*(i-n),d=(l-a)*(n-s)-(c-s)*(r-a),p=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const f=d/u,y=p/u;if(f>=0&&f<=1&&y>=0&&y<=1){return[r+f*(o-r),n+f*(i-n)]}return!1}var D=function(e,t){const r=new I([],w);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)x(r[e],t)}else x(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new I([],C);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new R(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=B(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function G(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let s=[];"FeatureCollection"===e.type?s=s.concat(e.features):"Feature"===e.type?s.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||s.push(i(e)),"FeatureCollection"===t.type?s=s.concat(t.features):"Feature"===t.type?s.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||s.push(i(t));const c=D(l(s),o);let u=[];if(n){const e={};c.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,u.push(t))})}else u=c;return l(u.map(e=>a(e)))}function O(e,t,r){if(null!==e)for(var n,o,i,a,s,l,c,u,d=0,p=0,f=e.type,y="FeatureCollection"===f,g="Feature"===f,h=y?e.features.length:1,m=0;m<h;m++){s=(u=!!(c=y?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var E=0;E<s;E++){var S=0,v=0;if(null!==(a=u?c.geometries[E]:c)){l=a.coordinates;var b=a.type;switch(d=0,b){case null:break;case"Point":if(!1===t(l,p,m,S,v))return!1;p++,S++;break;case"LineString":case"MultiPoint":for(n=0;n<l.length;n++){if(!1===t(l[n],p,m,S,v))return!1;p++,"MultiPoint"===b&&S++}"LineString"===b&&S++;break;case"Polygon":case"MultiLineString":for(n=0;n<l.length;n++){for(o=0;o<l[n].length-d;o++){if(!1===t(l[n][o],p,m,S,v))return!1;p++}"MultiLineString"===b&&S++,"Polygon"===b&&v++}"Polygon"===b&&S++;break;case"MultiPolygon":for(n=0;n<l.length;n++){for(v=0,o=0;o<l[n].length;o++){for(i=0;i<l[n][o].length-d;i++){if(!1===t(l[n][o][i],p,m,S,v))return!1;p++}v++}S++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===O(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function H(e,t){!function(e,t){var r,n,o,i,a,s,l,c,u,d,p=0,f="FeatureCollection"===e.type,y="Feature"===e.type,g=f?e.features.length:1;for(r=0;r<g;r++){for(s=f?e.features[r].geometry:y?e.geometry:e,c=f?e.features[r].properties:y?e.properties:{},u=f?e.features[r].bbox:y?e.bbox:void 0,d=f?e.features[r].id:y?e.id:void 0,a=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=l?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,c,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,c,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,c,u,d))return!1;p++}}(e,function(e,r,n,o,a){var s,l=null===e?null:e.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return!1!==t(i(e,n,{bbox:o,id:a}),r,0)&&void 0}switch(l){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<e.coordinates.length;c++){var u=e.coordinates[c];if(!1===t(i({type:s,coordinates:u},n),r,c))return!1}})}function N(e,t={}){const r=M(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return K(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(K(e,o))}),l(i)}(r,t);default:throw new Error("invalid poly")}}function K(e,t){return e.length>1?c(e,t):s(e[0],t)}function U(e,t){for(let r=0;r<e.coordinates.length-1;r++)if($(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function V(e,t,r){for(const r of t.coordinates)if(P(r,e))return!0;return G(t,N(e),{ignoreSelfIntersections:r}).features.length>0}function $(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var q=function(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return H(e,e=>{H(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!U(t,e);case"Polygon":return!P(e,t)}break;case"LineString":switch(t.type){case"Point":return!U(e,t);case"LineString":return!function(e,t,r){const n=G(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!V(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!P(t,e);case"LineString":return!V(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(P(r,t))return!0;for(const r of t.coordinates[0])if(P(r,e))return!0;const n=G(N(e),N(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n};var z=function(e,t={}){if(null!=e.bbox&&!0!==t.recompute)return e.bbox;const r=[1/0,1/0,-1/0,-1/0];return O(e,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r};function j(e){const t=e.geometry||e;switch(t.type){case"Polygon":return function(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return i({type:"Polygon",coordinates:e},t,r)}(t.coordinates);case"MultiPolygon":return function(e,t,r={}){return i({type:"MultiPolygon",coordinates:e},t,r)}(t.coordinates);case"LineString":return s(t.coordinates);case"MultiLineString":return c(t.coordinates);case"Point":return a(t.coordinates);case"MultiPoint":return function(e,t,r={}){return i({type:"MultiPoint",coordinates:e},t,r)}(t.coordinates);default:throw new Error(`Unsupported geometry type: ${t.type}`)}}function X(e,t){return t.some(t=>!q(j(t),j(e)))}function W(e){if(e.length<2)return!1;if(e.some(e=>{return t=e.geometry?.type,!("Polygon"===t||"MultiPolygon"===t);var t}))return!1;const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length}const Y={".cold":".hot",".hot":".cold"},Z=e=>{for(const[t,r]of Object.entries(Y))if(e.endsWith(t))return`${e.slice(0,-t.length)}${r}`;return null},J=e=>{const t={};for(const r of e){t[r.layerId]=r;const e=Z(r.layerId);e&&(t[e]=r)}return t},Q=(e,t,r)=>{try{return e?.getFeaturesAtPoint(t,r)||[]}catch(e){return console.warn("Feature query failed:",e),[]}},ee=e=>{const t=e.geometry?.type;return"Point"===t||"MultiPoint"===t},te=e=>!!e.label&&(!e.symbol&&!e.svgContent&&(null===e.symbol||null===e.svgContent)),re=(e,t,r,n)=>({featureId:e,multiSelect:t,layerId:r.layerId,idProperty:r.idProperty,properties:n.properties,geometry:n.geometry}),ne=({featureId:e,feature:t,config:r,selectedFeatures:n,dispatch:o,multiSelect:i})=>{if(!n.length)return!1;const a=n.findIndex(t=>t.featureId===e&&t.layerId===r.layerId);if(-1!==a){if(n.length<3)return!1;const e=(e=>{const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);e[n].geometry?.type&&X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length?null:[...t].map(t=>e[t])})(n.filter((e,t)=>t!==a));return!!e&&(o({type:"SET_SELECTED_FEATURES",payload:e}),!0)}const s=n.filter(e=>e.geometry?.type);return!(!t.geometry?.type||!s.length)&&(!X(t,s)&&(o({type:"TOGGLE_SELECTED_FEATURES",payload:{...re(e,i,r,t),replaceAll:!0}}),!0))},oe=({mapProvider:t,layers:r,interactionModes:n,multiSelect:o,dispatch:i,markers:a,layerConfigMap:s,debug:l,tolerance:c,processFeatureMatch:u,processFallback:d,scale:p})=>e(({point:e,coords:f})=>{const y=l?Q(t,e,{radius:c}):null;if(y&&((e,t)=>{const[r,n]=e;console.groupCollapsed(`[interact] click (${r.toFixed(4)}, ${n.toFixed(4)}) — ${t.length} feature${1!==t.length?"s":""}`),t.forEach(e=>{console.log({layer:e.layer.id,type:e.layer.type,id:e.id??"—",sourceLayer:e.sourceLayer??"—",properties:e.properties})}),console.groupEnd()})(f,y),n.includes("selectMarker")){const t=((e,t,r)=>{for(const n of e.items){const o=e.markerRefs?.get(n.id);if(!o||te(n))continue;const i=o.closest(".im-c-viewport__markers")||o.parentElement,a=i?i.getBoundingClientRect():{left:0,top:0},{left:s,top:l,right:c,bottom:u}=o.getBoundingClientRect(),d=t.x*r,p=t.y*r;if(d>=s-a.left&&d<=c-a.left&&p>=l-a.top&&p<=u-a.top)return n.id}return null})(a,e,p);if(t)return void i({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:t,multiSelect:o}})}if(n.includes("selectFeature")&&r.length>0){const r=((e,t)=>{const r=e.filter(e=>t[e.layer?.id]),n=r.find(ee);if(n)return{feature:n,config:t[n.layer.id]};const o=r[0];return o?{feature:o,config:t[o.layer.id]}:null})(y??Q(t,e,{radius:c}),s);if(r)return void u(r)}d({coords:f})},[t,r,n,o,i,a,s,l,c,u,d,p]),ie=({mapState:n,pluginState:o,services:i,mapProvider:a})=>{const{markers:s,mapSizeScale:l}=n,{dispatch:c,layers:u,interactionModes:d,multiSelect:p,contiguous:f,marker:y,tolerance:g,selectedFeatures:h,selectedMarkers:m,deselectOnClickOutside:E}=o,{eventBus:S}=i,v=J(u),b=e(({feature:e,config:t})=>{s.remove("location");const r=e.properties?.[t.idProperty]??e.id;if(null==r)return;const n=a.getFeatureGeometry?.(t.layerId,r,t.idProperty),o=n?{...e,geometry:n}:e;if(f&&p){if(ne({featureId:r,feature:o,config:t,selectedFeatures:h,dispatch:c,multiSelect:p}))return}c({type:"TOGGLE_SELECTED_FEATURES",payload:re(r,p,t,o)})},[s,c,p,f,h,a]),k=e(({coords:e})=>{const t=d.includes("placeMarker");(t||E)&&(c({type:"CLEAR_SELECTED_FEATURES"}),t&&(s.add("location",e,y),S.emit("interact:markerchange",{coords:e})))},[d,c,s,y,S,E]),M=oe({mapProvider:a,layers:u,interactionModes:d,multiSelect:p,dispatch:c,markers:s,layerConfigMap:v,debug:o?.debug,tolerance:g,processFeatureMatch:b,processFallback:k,scale:l});return((e,n,o)=>{const i=t(null);r(()=>{const t=i.current;(null===t||0===t.features.length&&0===t.markers.length)&&0===n.length&&0===o.length||(e.emit("interact:selectionchange",{selectedFeatures:n.map(({featureId:e,layerId:t,idProperty:r,properties:n,geometry:o})=>({featureId:e,layerId:t,idProperty:r,properties:n,geometryType:o?.type})),selectedMarkers:o,contiguous:W(n)}),i.current={features:n,markers:o})},[n,o])})(S,h,m),{handleInteraction:M}},ae=e=>{const t=e.closest(".im-c-viewport__markers");if(!t)return!1;const r=t.getBoundingClientRect(),{left:n,right:o,top:i,bottom:a}=e.getBoundingClientRect();return o>r.left&&n<r.right&&a>r.top&&i<r.bottom},se=(e,t,r)=>{const{x:n,y:o}=e.mapToScreen(r);return{x:n*t,y:o*t}},le=(e,t,r,n,o)=>{const i=t[e.layer?.id];if(!i?.labelProperty)return null;const a=((e,t)=>e.properties?.[t.idProperty]??e.id)(e,i),s=null==a?null:String(a);if(null==s||r.has(s))return null;r.add(s);const l={id:s,label:e.properties?.[i.labelProperty]??s,isMarker:!1,featureId:a,layerId:i.layerId,idProperty:i.idProperty,geometry:e.geometry,properties:e.properties},c=function(e){try{const[t,r,n,o]=z(j(e));return[(t+n)/2,(r+o)/2]}catch{return null}}(e);return c&&Object.assign(l,se(n,o,c)),l};function ce({markers:e,mapSizeScale:n,interactionModes:i,layers:a,mapProvider:s,multiSelect:l,spatialListRegistry:c,eventBus:u,itemsRef:d}){const p=t(l);p.current=l,r(()=>{const t=()=>{const t=[];i?.includes("selectMarker")&&t.push(...((e,t,r)=>{const n=[];for(const o of e.items){if(!o.label)continue;const i=e.markerRefs?.get(o.id);if(!te(o)&&i&&ae(i)){const e={id:o.id,label:o.label,isMarker:!0};o.coords&&Object.assign(e,se(t,r,o.coords)),n.push(e)}}return n})(e,s,n)),i?.includes("selectFeature")&&a.length>0&&t.push(...((e,t,r)=>{const n=[],o=new Set,i=t.map(e=>e.layerId),a=J(t),s=e.getVisibleFeatures(i);for(const t of s){const i=le(t,a,o,e,r);i&&n.push(i)}return n})(s,a,n)),d.current=t,c.notifyItemsChanged("interact")};return t(),u.on(o.MAP_MOVE_END,t),u.on(o.MAP_DATA_CHANGE,t),()=>{u.off(o.MAP_MOVE_END,t),u.off(o.MAP_DATA_CHANGE,t)}},[e,n,i,a,s,l,c,u,d]),r(()=>(c.registerItemProvider("interact",{getItems:()=>({items:d.current,multiselectable:p.current,label:"Map features"})}),()=>{c.unregisterItemProvider("interact")}),[c,d])}function ue({mapState:e,pluginState:n,services:i,mapProvider:a,spatialListRegistry:s}){const{markers:l,mapSizeScale:c}=e,{dispatch:u,interactionModes:d,layers:p,multiSelect:f}=n,{eventBus:y}=i,g=t(null),h=t([]);ce({markers:l,mapSizeScale:c,interactionModes:d,layers:p,mapProvider:a,multiSelect:f,spatialListRegistry:s,eventBus:y,itemsRef:h}),function({itemsRef:e,eventBus:t,dispatch:n,listboxActiveItemRef:i}){r(()=>{const r=({id:t})=>{if(null===t)return i.current=null,void n({type:"SET_LISTBOX_ACTIVE",payload:null});const r=e.current.find(e=>e.id===t);if(!r)return;if(r.isMarker)return i.current={id:t,isMarker:!0},void n({type:"SET_LISTBOX_ACTIVE",payload:null});const o={featureId:r.featureId,layerId:r.layerId,idProperty:r.idProperty,geometry:r.geometry};i.current={id:t,isMarker:!1,...o,properties:r.properties},n({type:"SET_LISTBOX_ACTIVE",payload:o})};return t.on(o.MAP_SET_ACTIVE_ITEM,r),()=>{t.off(o.MAP_SET_ACTIVE_ITEM,r)}},[e,t,n,i])}({itemsRef:h,eventBus:y,dispatch:u,listboxActiveItemRef:g}),function({eventBus:e,dispatch:t,listboxActiveItemRef:n,multiSelect:i}){r(()=>{const r=()=>{const e=n.current;if(e)if(e.isMarker)t({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:e.id,multiSelect:i}});else{const{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s}=e;t({type:"TOGGLE_SELECTED_FEATURES",payload:{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s,multiSelect:i,replaceAll:!i}})}};return e.on(o.MAP_SELECT_ITEM,r),()=>{e.off(o.MAP_SELECT_ITEM,r)}},[e,t,n,i])}({eventBus:y,dispatch:u,listboxActiveItemRef:g,multiSelect:f})}const de=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];return Object.values(e)[0]??null}return null},pe={light:{haloColor:"#ffffff",selectedColor:"#0b0c0c",activeColor:"#ffdd00",foregroundColor:"#0b0c0c"},dark:{haloColor:"#0b0c0c",selectedColor:"#ffffff",activeColor:"#ffdd00",foregroundColor:"#ffffff"}},fe=({mapProvider:e,mapStyle:t,pluginState:o,selectedFeatures:i,events:a,eventBus:s})=>{const{layers:l,listboxActiveItem:c}=o,u=n(()=>t?((e,t)=>{const r={};if(!t)return console.warn("[interact] buildStylesMap: mapStyle is null/undefined, cannot build styles"),r;const n=pe[t.mapColorScheme]??pe.light,o=t.activeColor??n.activeColor,i=t.selectedColor??n.selectedColor;return e.forEach(e=>{const n=e.activeStroke||o,a=e.selectedStroke||i,s=e.selectedFill||"transparent",l=e.selectedStrokeWidth||3,c=l+6;r[e.layerId]={stroke:de(n,t.id),selectionStroke:de(a,t.id),fill:de(s,t.id),strokeWidth:l,activeStrokeWidth:c}}),r})(l,t):null,[l,t]),d=()=>{const t=c?[{featureId:c.featureId,layerId:c.layerId,idProperty:c.idProperty,geometry:c.geometry}]:[];e.updateHighlightedFeatures?.(i,t,u)};r(()=>{if(!e||!u)return;d();let t=0,r=!1;const n=()=>{d(),Date.now()>=t&&(s.off(a.MAP_DATA_CHANGE,n),r=!1)},o=()=>{t=Date.now()+3e3,r||(r=!0,s.on(a.MAP_DATA_CHANGE,n))};return s.on(a.MAP_STYLE_CHANGE,o),s.on(a.MAP_SET_SIZE,o),()=>{s.off(a.MAP_STYLE_CHANGE,o),s.off(a.MAP_SET_SIZE,o),s.off(a.MAP_DATA_CHANGE,n)}},[i,c,e,u,s])},ye='[role="listbox"], [role="option"]';const ge=e=>!("Enter"!==e.key||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey);function he({getAppState:e,mapState:t,getPluginState:r,buttonConfig:n,events:o,eventBus:i,handleInteraction:a,clickReadyRef:s}){const{selectAtTarget:l}=n,c=()=>a(t.crossHair.getDetail()),u=e=>{s.current&&a(e)},{handleKeydown:d,handleKeyup:p}=((e,t)=>{let r=!1;return{handleKeydown:t=>{r=ge(t)&&e.current===t.target},handleKeyup:e=>{ge(e)&&r&&(e.preventDefault(),t())}}})(e().layoutRefs.viewportRef,c),f=((e,t)=>(r,n)=>{const o=t();e.markers.remove("location"),o.dispatch({type:"TOGGLE_SELECTED_FEATURES",payload:{multiSelect:o.multiSelect,addToExisting:n,...r}})})(t,r),y=e=>f(e,!0),g=e=>f(e,!1);return document.addEventListener("keydown",d),document.addEventListener("keyup",p),i.on(o.MAP_CLICK,u),i.on("interact:selectFeature",y),i.on("interact:unselectFeature",g),l.onClick=c,()=>{l.onClick=null,document.removeEventListener("keydown",d),document.removeEventListener("keyup",p),i.off(o.MAP_CLICK,u),i.off("interact:selectFeature",y),i.off("interact:unselectFeature",g)}}const me=({appState:e,pluginState:t})=>{return!!e.expandedButtons?.has("mapControls")||"touch"===e.interfaceType&&!1!==t.touchTarget&&(r=t.interactionModes,!(1===r?.length&&r.includes("selectMarker")));var r};const Ee={ENABLE:(e,t)=>({...e,...t,enabled:!0}),DISABLE:e=>({...e,enabled:!1,selectedFeatures:[],selectedMarkers:[],listboxActiveItem:null}),TOGGLE_SELECTED_FEATURES:(e,t)=>{const{featureId:r,multiSelect:n,layerId:o,idProperty:i,addToExisting:a=!0,replaceAll:s=!1,properties:l,geometry:c}=t,u=Array.isArray(e.selectedFeatures)?e.selectedFeatures:[],d=u.findIndex(e=>e.featureId===r&&e.layerId===o);if(!1===a){const t=u.filter((e,t)=>t!==d);return{...e,selectedFeatures:t}}const p={featureId:r,layerId:o,idProperty:i,properties:l,geometry:c};let f;if(n&&!s){const e=[...u];-1===d?e.push(p):e.splice(d,1),f=e}else{f=-1!==d&&1===u.length?[]:[p]}return{...e,selectedFeatures:f,selectedMarkers:n&&!s?e.selectedMarkers:[]}},TOGGLE_SELECTED_MARKERS:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers,o=n.includes(t);if(r){const r=o?n.filter(e=>e!==t):[...n,t];return{...e,selectedMarkers:r}}return{...e,selectedFeatures:[],selectedMarkers:o&&1===n.length?[]:[t]}},CLEAR_SELECTED_FEATURES:e=>({...e,selectedFeatures:[],selectedMarkers:[]}),SET_SELECTED_FEATURES:(e,t)=>({...e,selectedFeatures:t}),SELECT_MARKER:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers;if(n.includes(t))return e;const o=r?[...n,t]:[t];return{...e,selectedFeatures:r?e.selectedFeatures:[],selectedMarkers:o}},UNSELECT_MARKER:(e,{markerId:t})=>{const r=e.selectedMarkers;return r.includes(t)?{...e,selectedMarkers:r.filter(e=>e!==t)}:e},SET_LISTBOX_ACTIVE:(e,t)=>({...e,listboxActiveItem:t??null}),SET_LISTBOX_FOCUSED:(e,t)=>({...e,listboxFocused:!!t})},Se={tolerance:10,interactionModes:["selectMarker"],multiSelect:!1,contiguous:!1,deselectOnClickOutside:!1,touchTarget:!0,marker:{}},ve="Select",be={InitComponent:({appState:n,mapState:i,services:a,buttonConfig:s,mapProvider:l,pluginState:c})=>{const{enabled:u,selectedFeatures:d,interactionModes:p,layers:f}=c,{eventBus:y}=a,{crossHair:g,mapStyle:h,markers:m}=i,E=me({appState:n,pluginState:c});ue({mapState:i,pluginState:c,services:a,mapProvider:l,spatialListRegistry:n.spatialListRegistry});const{handleInteraction:S}=ie({mapState:i,pluginState:c,services:a,mapProvider:l});return fe({mapProvider:l,mapStyle:h,pluginState:c,selectedFeatures:d,events:o,eventBus:y}),r(()=>{y.emit("interact:active",{active:u,interactionModes:p})},[u,p]),function({enabled:e,interactionModes:t,markers:n,layers:o,eventBus:i}){r(()=>{if(!e)return;const r=t?.includes("selectMarker")&&n.items.some(e=>e.label),a=t?.includes("selectFeature")&&o.some(e=>e.labelProperty);(r||a)&&i.emit("interact:listboxcapable")},[e,t,n,o,i])}({enabled:u,interactionModes:p,markers:m,layers:f,eventBus:y}),((e,t,n,o)=>{r(()=>{const r=t&&n?.includes("selectFeature")?o.map(e=>e.layerId):[];return e.setHoverCursor?.(r),()=>e.setHoverCursor?.([])},[t,n,o])})(l,u,p,f),function({crossHair:n,enabled:o,targetNeeded:i,appState:a,dispatch:s}){const l=t(o);l.current=o;const c=t(i);c.current=i;const u=t(n);u.current=n;const d=t(s);d.current=s;const p=t(!1),f=t(!1),y=t(a.interfaceType);y.current=a.interfaceType;const g=e(()=>{const e="keyboard"===y.current&&f.current,t=c.current&&!p.current;l.current&&(e||t)?u.current.fixAtCenter():u.current.hide()},[]);r(()=>{g()},[o,i,a.interfaceType,g]),r(()=>{const e=a.layoutRefs?.appContainerRef?.current;if(!e)return;const t=e=>{p.current=e,d.current?.({type:"SET_LISTBOX_FOCUSED",payload:e})};f.current=!!document.activeElement?.closest("[data-map-keyboard-scope]"),document.activeElement?.closest(ye)&&t(!0);const r=e=>{const r=!!e.target.closest(ye),n=!!e.target.closest("[data-map-keyboard-scope]"),o=p.current!==r,i=o||f.current!==n;o&&t(r),f.current=n,i&&l.current&&g()};return e.addEventListener("focusin",r),()=>{e.removeEventListener("focusin",r)}},[a.layoutRefs,g])}({crossHair:g,enabled:u,targetNeeded:E,appState:n,dispatch:c.dispatch}),function({pluginState:e,appState:n,mapState:i,buttonConfig:a,eventBus:s,handleInteraction:l}){const c=t(l);c.current=l;const u=t(e);u.current=e;const d=t(n);d.current=n;const p=t(!1);r(()=>{p.current=!1;const e=setTimeout(()=>{p.current=!0},0);return()=>clearTimeout(e)},[e.enabled]),r(()=>{if(e.enabled)return he({getAppState:()=>d.current,mapState:i,getPluginState:()=>u.current,buttonConfig:a,events:o,eventBus:s,handleInteraction:e=>c.current(e),clickReadyRef:p})},[e.enabled,a,s]),r(()=>{if(!e.enabled)return;const t=()=>c.current(i.crossHair.getDetail());return i.crossHair.activate=t,()=>{i.crossHair.activate===t&&(i.crossHair.activate=null)}},[e.enabled,i.crossHair])}({pluginState:c,appState:n,mapState:i,buttonConfig:s,eventBus:y,handleInteraction:S}),null},reducer:{initialState:{enabled:!1,layers:[],marker:null,interactionModes:null,multiSelect:!1,deselectOnClickOutside:!1,touchTarget:!0,selectedFeatures:[],selectedMarkers:[],closeOnAction:!0,listboxActiveItem:null,listboxFocused:!1},actions:Ee},buttons:[{id:"selectAtTarget",label:"Select",variant:"primary",hiddenWhen:({appState:e,pluginState:t})=>!t.enabled||t.listboxFocused||!me({appState:e,pluginState:t}),mobile:{slot:"actions"},tablet:{slot:"actions"},desktop:{slot:"actions"}}],keyboardShortcuts:[{id:"clickAtTarget",title:"Click at target",command:"<kbd>Enter</kbd>"},{id:"selectFeatures",group:ve,context:"listbox",title:"Select features",command:"<kbd>Tab</kbd>"},{id:"navigateFeatures",group:ve,context:"listbox",title:"Highlight next feature",command:"<kbd>↑</kbd> or <kbd>↓</kbd>"},{id:"navigateFeaturesSpatially",group:ve,context:"listbox",title:"Highlight nearby feature",command:`${"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||"")?"<kbd>Option</kbd>":"<kbd>Alt</kbd>"} + <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>←</kbd> or <kbd>→</kbd>`},{id:"selectFeature",group:ve,context:"listbox",title:"Select a feature",command:"<kbd>Enter</kbd> or <kbd>Space</kbd>"},{id:"dismissHintOrReturn",group:ve,context:"listbox",title:"Dismiss hint / return to map",command:"<kbd>Escape</kbd>"}],icons:[{id:"select",svgContent:'<path d="M22 14a8 8 0 0 1-8 8"/><path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/><path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1"/><path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10"/><path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>'}],api:{enable:({pluginState:e,pluginConfig:t},r)=>{e.dispatch({type:"ENABLE",payload:{...Se,...t,...r}})},disable:({pluginState:e})=>{e.dispatch({type:"DISABLE"})},clear:({pluginState:e,mapState:t})=>{e.dispatch({type:"CLEAR_SELECTED_FEATURES"}),t.markers.remove("location")},selectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:selectFeature",{featureId:t,layerId:r,idProperty:n})},unselectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:unselectFeature",{featureId:t,layerId:r,idProperty:n})},selectMarker:({pluginState:e},t)=>{e.dispatch({type:"SELECT_MARKER",payload:{markerId:t,multiSelect:e.multiSelect}})},unselectMarker:({pluginState:e},t)=>{e.dispatch({type:"UNSELECT_MARKER",payload:{markerId:t}})}}};export{be as manifest};
1
+ import{useCallback as e,useRef as t,useEffect as r,useMemo as n}from"preact/compat";const o={MAP_SET_SIZE:"map:setsize",MAP_SET_ACTIVE_ITEM:"map:setactiveitem",MAP_SELECT_ITEM:"map:selectitem",MAP_STYLE_CHANGE:"map:stylechange",MAP_MOVE_END:"map:moveend",MAP_DATA_CHANGE:"map:datachange",MAP_CLICK:"map:click"};function i(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function a(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!u(e[0])||!u(e[1]))throw new Error("coordinates must contain numbers");return i({type:"Point",coordinates:e},t,r)}function s(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return i({type:"LineString",coordinates:e},t,r)}function l(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return i({type:"MultiLineString",coordinates:e},t,r)}function u(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}const d=11102230246251565e-32,p=134217729,f=(3+8*d)*d;function y(e,t,r,n,o){let i,a,s,l,c=t[0],u=n[0],d=0,p=0;u>c==u>-c?(i=c,c=t[++d]):(i=u,u=n[++p]);let f=0;if(d<e&&p<r)for(u>c==u>-c?(a=c+i,s=i-(a-c),c=t[++d]):(a=u+i,s=i-(a-u),u=n[++p]),i=a,0!==s&&(o[f++]=s);d<e&&p<r;)u>c==u>-c?(a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d]):(a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p]),i=a,0!==s&&(o[f++]=s);for(;d<e;)a=i+c,l=a-i,s=i-(a-l)+(c-l),c=t[++d],i=a,0!==s&&(o[f++]=s);for(;p<r;)a=i+u,l=a-i,s=i-(a-l)+(u-l),u=n[++p],i=a,0!==s&&(o[f++]=s);return 0===i&&0!==f||(o[f++]=i),f}function g(e){return new Float64Array(e)}const m=g(4),h=g(8),E=g(12),S=g(16),v=g(4);function b(e,t,r,n,o,i){const a=(t-i)*(r-o),s=(e-o)*(n-i),l=a-s,c=Math.abs(a+s);return Math.abs(l)>=33306690738754716e-32*c?l:-function(e,t,r,n,o,i,a){let s,l,c,u,d,g,b,k,M,P,I,A,w,C,T,_,L,F;const x=e-o,R=r-o,B=t-i,D=n-i;C=x*D,g=p*x,b=g-(g-x),k=x-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=B*R,g=p*B,b=g-(g-B),k=B-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,m[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,m[1]=w-(I+d)+(d-_),F=A+I,d=F-A,m[2]=A-(F-d)+(I-d),m[3]=F;let G=function(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}(4,m),O=22204460492503146e-32*a;if(G>=O||-G>=O)return G;if(d=e-x,s=e-(x+d)+(d-o),d=r-R,c=r-(R+d)+(d-o),d=t-B,l=t-(B+d)+(d-i),d=n-D,u=n-(D+d)+(d-i),0===s&&0===l&&0===c&&0===u)return G;if(O=11093356479670487e-47*a+f*Math.abs(G),G+=x*u+D*s-(B*c+R*l),G>=O||-G>=O)return G;C=s*D,g=p*s,b=g-(g-s),k=s-b,g=p*D,M=g-(g-D),P=D-M,T=k*P-(C-b*M-k*M-b*P),_=l*R,g=p*l,b=g-(g-l),k=l-b,g=p*R,M=g-(g-R),P=R-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const H=y(4,m,4,v,h);C=x*u,g=p*x,b=g-(g-x),k=x-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=B*c,g=p*B,b=g-(g-B),k=B-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const N=y(H,h,4,v,E);C=s*u,g=p*s,b=g-(g-s),k=s-b,g=p*u,M=g-(g-u),P=u-M,T=k*P-(C-b*M-k*M-b*P),_=l*c,g=p*l,b=g-(g-l),k=l-b,g=p*c,M=g-(g-c),P=c-M,L=k*P-(_-b*M-k*M-b*P),I=T-L,d=T-I,v[0]=T-(I+d)+(d-L),A=C+I,d=A-C,w=C-(A-d)+(I-d),I=w-_,d=w-I,v[1]=w-(I+d)+(d-_),F=A+I,d=F-A,v[2]=A-(F-d)+(I-d),v[3]=F;const K=y(N,E,4,v,S);return S[K-1]}(e,t,r,n,o,i,c)}function k(e,t){var r,n,o,i,a,s,l,c,u,d=0,p=e[0],f=e[1],y=t.length;for(r=0;r<y;r++){n=0;var g=t[r],m=g.length-1;if((c=g[0])[0]!==g[m][0]&&c[1]!==g[m][1])throw new Error("First and last coordinates in a ring must be the same");for(i=c[0]-p,a=c[1]-f;n<m;n++){if(s=(u=g[n+1])[0]-p,l=u[1]-f,0===a&&0===l){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(0===(o=b(i,s,a,l,0,0)))return 0;(o>0&&l>0&&a<=0||o<0&&l<=0&&a>0)&&d++}c=u,a=l,i=s}}return d%2!=0}function M(e){return"Feature"===e.type?e.geometry:e}function P(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(e),o=M(t),i=o.type,a=t.bbox;let s=o.coordinates;if(a&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(n,a))return!1;"Polygon"===i&&(s=[s]);let l=!1;for(var c=0;c<s.length;++c){const e=k(n,s[c]);if(0===e)return!r.ignoreBoundary;e&&(l=!0)}return l}class I{constructor(e=[],t=A){if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let e=(this.length>>1)-1;e>=0;e--)this._down(e)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const e=this.data[0],t=this.data.pop();return this.length--,this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,n=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(n,i)>=0)break;t[e]=i,e=o}t[e]=n}_down(e){const{data:t,compare:r}=this,n=this.length>>1,o=t[e];for(;e<n;){let n=1+(e<<1),i=t[n];const a=n+1;if(a<this.length&&r(t[a],i)<0&&(n=a,i=t[a]),r(i,o)>=0)break;t[e]=i,e=n}t[e]=o}}function A(e,t){return e<t?-1:e>t?1:0}function w(e,t){return e.p.x>t.p.x?1:e.p.x<t.p.x?-1:e.p.y!==t.p.y?e.p.y>t.p.y?1:-1:1}function C(e,t){return e.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:e.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:e.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?e.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}class T{constructor(e,t,r,n){this.p={x:e[0],y:e[1]},this.featureId=t,this.ringId=r,this.eventId=n,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}let _=0,L=0,F=0;function x(e,t){const r="Feature"===e.type?e.geometry:e;let n=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(n=[n]),"LineString"===r.type&&(n=[[n]]);for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length;r++){let o=n[e][r][0],i=null;L+=1;for(let a=0;a<n[e][r].length-1;a++){i=n[e][r][a+1];const s=new T(o,_,L,F),l=new T(i,_,L,F+1);s.otherEvent=l,l.otherEvent=s,w(s,l)>0?(l.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,l.isLeftEndpoint=!1),t.push(s),t.push(l),o=i,F+=1}}_+=1}class R{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function B(e,t){if(null===e||null===t)return!1;if(e.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.leftSweepEvent)||e.rightSweepEvent.isSamePoint(t.rightSweepEvent)||e.leftSweepEvent.isSamePoint(t.leftSweepEvent)||e.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;const r=e.leftSweepEvent.p.x,n=e.leftSweepEvent.p.y,o=e.rightSweepEvent.p.x,i=e.rightSweepEvent.p.y,a=t.leftSweepEvent.p.x,s=t.leftSweepEvent.p.y,l=t.rightSweepEvent.p.x,c=t.rightSweepEvent.p.y,u=(c-s)*(o-r)-(l-a)*(i-n),d=(l-a)*(n-s)-(c-s)*(r-a),p=(o-r)*(n-s)-(i-n)*(r-a);if(0===u)return!1;const f=d/u,y=p/u;if(f>=0&&f<=1&&y>=0&&y<=1){return[r+f*(o-r),n+f*(i-n)]}return!1}var D=function(e,t){const r=new I([],w);return function(e,t){if("FeatureCollection"===e.type){const r=e.features;for(let e=0;e<r.length;e++)x(r[e],t)}else x(e,t)}(e,r),function(e,t){t=t||!1;const r=[],n=new I([],C);for(;e.length;){const o=e.pop();if(o.isLeftEndpoint){const e=new R(o);for(let i=0;i<n.data.length;i++){const a=n.data[i];if(t&&a.leftSweepEvent.featureId===o.featureId)continue;const s=B(e,a);!1!==s&&r.push(s)}n.push(e)}else!1===o.isLeftEndpoint&&n.pop()}return r}(r,t)};function G(e,t,r={}){const{removeDuplicates:n=!0,ignoreSelfIntersections:o=!0}=r;let s=[];"FeatureCollection"===e.type?s=s.concat(e.features):"Feature"===e.type?s.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||s.push(i(e)),"FeatureCollection"===t.type?s=s.concat(t.features):"Feature"===t.type?s.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||s.push(i(t));const c=D(l(s),o);let u=[];if(n){const e={};c.forEach(t=>{const r=t.join(",");e[r]||(e[r]=!0,u.push(t))})}else u=c;return l(u.map(e=>a(e)))}function O(e,t,r){if(null!==e)for(var n,o,i,a,s,l,c,u,d=0,p=0,f=e.type,y="FeatureCollection"===f,g="Feature"===f,m=y?e.features.length:1,h=0;h<m;h++){s=(u=!!(c=y?e.features[h].geometry:g?e.geometry:e)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var E=0;E<s;E++){var S=0,v=0;if(null!==(a=u?c.geometries[E]:c)){l=a.coordinates;var b=a.type;switch(d=0,b){case null:break;case"Point":if(!1===t(l,p,h,S,v))return!1;p++,S++;break;case"LineString":case"MultiPoint":for(n=0;n<l.length;n++){if(!1===t(l[n],p,h,S,v))return!1;p++,"MultiPoint"===b&&S++}"LineString"===b&&S++;break;case"Polygon":case"MultiLineString":for(n=0;n<l.length;n++){for(o=0;o<l[n].length-d;o++){if(!1===t(l[n][o],p,h,S,v))return!1;p++}"MultiLineString"===b&&S++,"Polygon"===b&&v++}"Polygon"===b&&S++;break;case"MultiPolygon":for(n=0;n<l.length;n++){for(v=0,o=0;o<l[n].length;o++){for(i=0;i<l[n][o].length-d;i++){if(!1===t(l[n][o][i],p,h,S,v))return!1;p++}v++}S++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(!1===O(a.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function H(e,t){!function(e,t){var r,n,o,i,a,s,l,c,u,d,p=0,f="FeatureCollection"===e.type,y="Feature"===e.type,g=f?e.features.length:1;for(r=0;r<g;r++){for(s=f?e.features[r].geometry:y?e.geometry:e,c=f?e.features[r].properties:y?e.properties:{},u=f?e.features[r].bbox:y?e.bbox:void 0,d=f?e.features[r].id:y?e.id:void 0,a=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=l?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,c,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,c,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,c,u,d))return!1;p++}}(e,function(e,r,n,o,a){var s,l=null===e?null:e.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return!1!==t(i(e,n,{bbox:o,id:a}),r,0)&&void 0}switch(l){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var c=0;c<e.coordinates.length;c++){var u=e.coordinates[c];if(!1===t(i({type:s,coordinates:u},n),r,c))return!1}})}function N(e,t={}){const r=M(e);switch(t.properties||"Feature"!==e.type||(t.properties=e.properties),r.type){case"Polygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{};return K(n,o)}(r,t);case"MultiPolygon":return function(e,t={}){const r=M(e),n=r.coordinates,o=t.properties?t.properties:"Feature"===e.type?e.properties:{},i=[];return n.forEach(e=>{i.push(K(e,o))}),l(i)}(r,t);default:throw new Error("invalid poly")}}function K(e,t){return e.length>1?c(e,t):s(e[0],t)}function U(e,t){for(let r=0;r<e.coordinates.length-1;r++)if($(e.coordinates[r],e.coordinates[r+1],t.coordinates))return!0;return!1}function V(e,t,r){for(const r of t.coordinates)if(P(r,e))return!0;return G(t,N(e),{ignoreSelfIntersections:r}).features.length>0}function $(e,t,r){const n=r[0]-e[0],o=r[1]-e[1],i=t[0]-e[0],a=t[1]-e[1];return 0===n*a-o*i&&(Math.abs(i)>=Math.abs(a)?i>0?e[0]<=r[0]&&r[0]<=t[0]:t[0]<=r[0]&&r[0]<=e[0]:a>0?e[1]<=r[1]&&r[1]<=t[1]:t[1]<=r[1]&&r[1]<=e[1])}var q=function(e,t,{ignoreSelfIntersections:r=!0}={ignoreSelfIntersections:!0}){let n=!0;return H(e,e=>{H(t,t=>{if(!1===n)return!1;n=function(e,t,r){switch(e.type){case"Point":switch(t.type){case"Point":return n=e.coordinates,o=t.coordinates,!(n[0]===o[0]&&n[1]===o[1]);case"LineString":return!U(t,e);case"Polygon":return!P(e,t)}break;case"LineString":switch(t.type){case"Point":return!U(e,t);case"LineString":return!function(e,t,r){const n=G(e,t,{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(e,t,r);case"Polygon":return!V(t,e,r)}break;case"Polygon":switch(t.type){case"Point":return!P(t,e);case"LineString":return!V(e,t,r);case"Polygon":return!function(e,t,r){for(const r of e.coordinates[0])if(P(r,t))return!0;for(const r of t.coordinates[0])if(P(r,e))return!0;const n=G(N(e),N(t),{ignoreSelfIntersections:r});if(n.features.length>0)return!0;return!1}(t,e,r)}}var n,o;return!1}(e.geometry,t.geometry,r)})}),n};var z=function(e,t={}){if(null!=e.bbox&&!0!==t.recompute)return e.bbox;const r=[1/0,1/0,-1/0,-1/0];return O(e,e=>{r[0]>e[0]&&(r[0]=e[0]),r[1]>e[1]&&(r[1]=e[1]),r[2]<e[0]&&(r[2]=e[0]),r[3]<e[1]&&(r[3]=e[1])}),r};function j(e){const t=e.geometry||e;switch(t.type){case"Polygon":return function(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return i({type:"Polygon",coordinates:e},t,r)}(t.coordinates);case"MultiPolygon":return function(e,t,r={}){return i({type:"MultiPolygon",coordinates:e},t,r)}(t.coordinates);case"LineString":return s(t.coordinates);case"MultiLineString":return c(t.coordinates);case"Point":return a(t.coordinates);case"MultiPoint":return function(e,t,r={}){return i({type:"MultiPoint",coordinates:e},t,r)}(t.coordinates);default:throw new Error(`Unsupported geometry type: ${t.type}`)}}function X(e,t){return t.some(t=>!q(j(t),j(e)))}function W(e){if(e.length<2)return!1;if(e.some(e=>{return t=e.geometry?.type,!("Polygon"===t||"MultiPolygon"===t);var t}))return!1;const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length}const Y={".cold":".hot",".hot":".cold"},Z=e=>{for(const[t,r]of Object.entries(Y))if(e.endsWith(t))return`${e.slice(0,-t.length)}${r}`;return null},J=e=>{const t={};for(const r of e){t[r.layerId]=r;const e=Z(r.layerId);e&&(t[e]=r)}return t},Q=(e,t,r)=>{try{return e?.getFeaturesAtPoint(t,r)||[]}catch(e){return console.warn("Feature query failed:",e),[]}},ee=e=>{const t=e.geometry?.type;return"Point"===t||"MultiPoint"===t},te=e=>!!e.label&&(!e.symbol&&!e.svgContent&&(null===e.symbol||null===e.svgContent)),re=(e,t,r,n)=>({featureId:e,multiSelect:t,layerId:r.layerId,idProperty:r.idProperty,properties:n.properties,geometry:n.geometry}),ne=({featureId:e,feature:t,config:r,selectedFeatures:n,dispatch:o,multiSelect:i})=>{if(!n.length)return!1;const a=n.findIndex(t=>t.featureId===e&&t.layerId===r.layerId);if(-1!==a){if(n.length<3)return!1;const e=(e=>{const t=new Set([0]);let r=!0;for(;r;){r=!1;for(let n=1;n<e.length;n++){if(t.has(n))continue;const o=[...t].map(t=>e[t]);e[n].geometry?.type&&X(e[n],o)&&(t.add(n),r=!0)}}return t.size===e.length?null:[...t].map(t=>e[t])})(n.filter((e,t)=>t!==a));return!!e&&(o({type:"SET_SELECTED_FEATURES",payload:e}),!0)}const s=n.filter(e=>e.geometry?.type);return!(!t.geometry?.type||!s.length)&&(!X(t,s)&&(o({type:"TOGGLE_SELECTED_FEATURES",payload:{...re(e,i,r,t),replaceAll:!0}}),!0))},oe=({mapProvider:t,layers:r,interactionModes:n,multiSelect:o,dispatch:i,markers:a,layerConfigMap:s,debug:l,tolerance:c,processFeatureMatch:u,processFallback:d,scale:p})=>e(({point:e,coords:f})=>{const y=l?Q(t,e,{radius:c}):null;if(y&&((e,t)=>{const[r,n]=e;console.groupCollapsed(`[interact] click (${r.toFixed(4)}, ${n.toFixed(4)}) — ${t.length} feature${1!==t.length?"s":""}`),t.forEach(e=>{console.log({layer:e.layer.id,type:e.layer.type,id:e.id??"—",sourceLayer:e.sourceLayer??"—",properties:e.properties})}),console.groupEnd()})(f,y),n.includes("selectMarker")){const t=((e,t,r)=>{for(const n of e.items){const o=e.markerRefs?.get(n.id);if(!o||te(n))continue;const i=o.closest(".im-c-viewport__markers")||o.parentElement,a=i?i.getBoundingClientRect():{left:0,top:0},{left:s,top:l,right:c,bottom:u}=o.getBoundingClientRect(),d=t.x*r,p=t.y*r;if(d>=s-a.left&&d<=c-a.left&&p>=l-a.top&&p<=u-a.top)return n.id}return null})(a,e,p);if(t)return void i({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:t,multiSelect:o}})}if(n.includes("selectFeature")&&r.length>0){const r=((e,t)=>{const r=e.filter(e=>t[e.layer?.id]),n=r.find(ee);if(n)return{feature:n,config:t[n.layer.id]};const o=r[0];return o?{feature:o,config:t[o.layer.id]}:null})(y??Q(t,e,{radius:c}),s);if(r)return void u(r)}d({coords:f})},[t,r,n,o,i,a,s,l,c,u,d,p]),ie=({mapState:n,pluginState:o,services:i,mapProvider:a})=>{const{markers:s,mapSizeScale:l}=n,{dispatch:c,layers:u,interactionModes:d,multiSelect:p,contiguous:f,marker:y,tolerance:g,selectedFeatures:m,selectedMarkers:h,deselectOnClickOutside:E}=o,{eventBus:S}=i,v=J(u),b=e(({feature:e,config:t})=>{s.remove("location");const r=e.properties?.[t.idProperty]??e.id;if(null==r)return;const n=a.getFeatureGeometry?.(t.layerId,r,t.idProperty),o=n?{...e,geometry:n}:e;if(f&&p){if(ne({featureId:r,feature:o,config:t,selectedFeatures:m,dispatch:c,multiSelect:p}))return}c({type:"TOGGLE_SELECTED_FEATURES",payload:re(r,p,t,o)})},[s,c,p,f,m,a]),k=e(({coords:e})=>{const t=d.includes("placeMarker");(t||E)&&(c({type:"CLEAR_SELECTED_FEATURES"}),t&&(s.add("location",e,y),S.emit("interact:markerchange",{coords:e})))},[d,c,s,y,S,E]),M=oe({mapProvider:a,layers:u,interactionModes:d,multiSelect:p,dispatch:c,markers:s,layerConfigMap:v,debug:o?.debug,tolerance:g,processFeatureMatch:b,processFallback:k,scale:l});return((e,n,o)=>{const i=t(null);r(()=>{const t=i.current;(null===t||0===t.features.length&&0===t.markers.length)&&0===n.length&&0===o.length||(e.emit("interact:selectionchange",{selectedFeatures:n.map(({featureId:e,layerId:t,idProperty:r,properties:n,geometry:o})=>({featureId:e,layerId:t,idProperty:r,properties:n,geometryType:o?.type})),selectedMarkers:o,contiguous:W(n)}),i.current={features:n,markers:o})},[n,o])})(S,m,h),{handleInteraction:M}},ae=e=>{const t=e.closest(".im-c-viewport__markers");if(!t)return!1;const r=t.getBoundingClientRect(),{left:n,right:o,top:i,bottom:a}=e.getBoundingClientRect();return o>r.left&&n<r.right&&a>r.top&&i<r.bottom},se=(e,t,r)=>{const{x:n,y:o}=e.mapToScreen(r);return{x:n*t,y:o*t}},le=(e,t,r,n,o)=>{const i=t[e.layer?.id];if(!i?.labelProperty)return null;const a=((e,t)=>e.properties?.[t.idProperty]??e.id)(e,i),s=null==a?null:String(a);if(null==s||r.has(s))return null;r.add(s);const l={id:s,label:e.properties?.[i.labelProperty]??s,isMarker:!1,featureId:a,layerId:i.layerId,idProperty:i.idProperty,geometry:e.geometry,properties:e.properties},c=function(e){try{const[t,r,n,o]=z(j(e));return[(t+n)/2,(r+o)/2]}catch{return null}}(e);return c&&Object.assign(l,se(n,o,c)),l};function ce({markers:e,mapSizeScale:n,interactionModes:i,layers:a,mapProvider:s,multiSelect:l,spatialListRegistry:c,eventBus:u,itemsRef:d}){const p=t(l);p.current=l,r(()=>{const t=()=>{const t=[];i?.includes("selectMarker")&&t.push(...((e,t,r)=>{const n=[];for(const o of e.items){if(!o.label)continue;const i=e.markerRefs?.get(o.id);if(!te(o)&&i&&ae(i)){const e={id:o.id,label:o.label,isMarker:!0};o.coords&&Object.assign(e,se(t,r,o.coords)),n.push(e)}}return n})(e,s,n)),i?.includes("selectFeature")&&a.length>0&&t.push(...((e,t,r)=>{const n=[],o=new Set,i=t.map(e=>e.layerId),a=J(t),s=e.getVisibleFeatures(i);for(const t of s){const i=le(t,a,o,e,r);i&&n.push(i)}return n})(s,a,n)),d.current=t,c.notifyItemsChanged("interact")};return t(),u.on(o.MAP_MOVE_END,t),u.on(o.MAP_DATA_CHANGE,t),()=>{u.off(o.MAP_MOVE_END,t),u.off(o.MAP_DATA_CHANGE,t)}},[e,n,i,a,s,l,c,u,d]),r(()=>(c.registerItemProvider("interact",{getItems:()=>({items:d.current,multiselectable:p.current,label:"Map features"})}),()=>{c.unregisterItemProvider("interact")}),[c,d])}function ue({mapState:e,pluginState:n,services:i,mapProvider:a,spatialListRegistry:s}){const{markers:l,mapSizeScale:c}=e,{dispatch:u,interactionModes:d,layers:p,multiSelect:f}=n,{eventBus:y}=i,g=t(null),m=t([]);ce({markers:l,mapSizeScale:c,interactionModes:d,layers:p,mapProvider:a,multiSelect:f,spatialListRegistry:s,eventBus:y,itemsRef:m}),function({itemsRef:e,eventBus:t,dispatch:n,listboxActiveItemRef:i}){r(()=>{const r=({id:t})=>{if(null===t)return i.current=null,void n({type:"SET_LISTBOX_ACTIVE",payload:null});const r=e.current.find(e=>e.id===t);if(!r)return;if(r.isMarker)return i.current={id:t,isMarker:!0},void n({type:"SET_LISTBOX_ACTIVE",payload:null});const o={featureId:r.featureId,layerId:r.layerId,idProperty:r.idProperty,geometry:r.geometry};i.current={id:t,isMarker:!1,...o,properties:r.properties},n({type:"SET_LISTBOX_ACTIVE",payload:o})};return t.on(o.MAP_SET_ACTIVE_ITEM,r),()=>{t.off(o.MAP_SET_ACTIVE_ITEM,r)}},[e,t,n,i])}({itemsRef:m,eventBus:y,dispatch:u,listboxActiveItemRef:g}),function({eventBus:e,dispatch:t,listboxActiveItemRef:n,multiSelect:i}){r(()=>{const r=()=>{const e=n.current;if(e)if(e.isMarker)t({type:"TOGGLE_SELECTED_MARKERS",payload:{markerId:e.id,multiSelect:i}});else{const{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s}=e;t({type:"TOGGLE_SELECTED_FEATURES",payload:{featureId:r,layerId:n,idProperty:o,geometry:a,properties:s,multiSelect:i,replaceAll:!i}})}};return e.on(o.MAP_SELECT_ITEM,r),()=>{e.off(o.MAP_SELECT_ITEM,r)}},[e,t,n,i])}({eventBus:y,dispatch:u,listboxActiveItemRef:g,multiSelect:f})}const de=(e,t)=>{if("number"==typeof e)return e;if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&null!=e[t])return e[t];return Object.values(e)[0]??null}return null},pe={light:{haloColor:"#ffffff",selectedColor:"#0b0c0c",activeColor:"#ffdd00",foregroundColor:"#0b0c0c"},dark:{haloColor:"#0b0c0c",selectedColor:"#ffffff",activeColor:"#ffdd00",foregroundColor:"#ffffff"}},fe=({mapProvider:e,mapStyle:t,pluginState:o,selectedFeatures:i,events:a,eventBus:s})=>{const{layers:l,listboxActiveItem:c}=o,u=n(()=>t?((e,t)=>{const r={};if(!t)return console.warn("[interact] buildStylesMap: mapStyle is null/undefined, cannot build styles"),r;const n=pe[t.mapColorScheme]??pe.light,o=t.activeColor??n.activeColor,i=t.selectedColor??n.selectedColor;return e.forEach(e=>{const n=e.activeStroke||o,a=e.selectedStroke||i,s=e.selectedFill||"transparent",l=e.selectedStrokeWidth||3,c=l+6;r[e.layerId]={stroke:de(n,t.id),selectionStroke:de(a,t.id),fill:de(s,t.id),strokeWidth:l,activeStrokeWidth:c}}),r})(l,t):null,[l,t]),d=()=>{const t=c?[{featureId:c.featureId,layerId:c.layerId,idProperty:c.idProperty,geometry:c.geometry}]:[];e.updateHighlightedFeatures?.(i,t,u)};r(()=>{if(!e||!u)return;d();let t=0,r=!1;const n=()=>{d(),Date.now()>=t&&(s.off(a.MAP_DATA_CHANGE,n),r=!1)},o=()=>{t=Date.now()+3e3,r||(r=!0,s.on(a.MAP_DATA_CHANGE,n))};return s.on(a.MAP_STYLE_CHANGE,o),s.on(a.MAP_SET_SIZE,o),()=>{s.off(a.MAP_STYLE_CHANGE,o),s.off(a.MAP_SET_SIZE,o),s.off(a.MAP_DATA_CHANGE,n)}},[i,c,e,u,s])},ye='[role="listbox"], [role="option"]';const ge=e=>!("Enter"!==e.key||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey);function me({getAppState:e,mapState:t,getPluginState:r,buttonConfig:n,events:o,eventBus:i,handleInteraction:a,clickReadyRef:s}){const{selectAtTarget:l}=n,c=()=>a(t.crossHair.getDetail()),u=e=>{s.current&&a(e)},{handleKeydown:d,handleKeyup:p}=((e,t)=>{let r=!1;return{handleKeydown:t=>{r=ge(t)&&e.current===t.target},handleKeyup:e=>{ge(e)&&r&&(e.preventDefault(),t())}}})(e().layoutRefs.viewportRef,c),f=((e,t)=>(r,n)=>{const o=t();e.markers.remove("location"),o.dispatch({type:"TOGGLE_SELECTED_FEATURES",payload:{multiSelect:o.multiSelect,addToExisting:n,...r}})})(t,r),y=e=>f(e,!0),g=e=>f(e,!1);return document.addEventListener("keydown",d),document.addEventListener("keyup",p),i.on(o.MAP_CLICK,u),i.on("interact:selectFeature",y),i.on("interact:unselectFeature",g),l.onClick=c,()=>{l.onClick=null,document.removeEventListener("keydown",d),document.removeEventListener("keyup",p),i.off(o.MAP_CLICK,u),i.off("interact:selectFeature",y),i.off("interact:unselectFeature",g)}}const he=({appState:e,pluginState:t})=>{return!!e.expandedButtons?.has("mapControls")||"touch"===e.interfaceType&&!1!==t.touchTarget&&(r=t.interactionModes,!(1===r?.length&&r.includes("selectMarker")));var r};const Ee={ENABLE:(e,t)=>({...e,...t,enabled:!0}),DISABLE:e=>({...e,enabled:!1,selectedFeatures:[],selectedMarkers:[],listboxActiveItem:null}),TOGGLE_SELECTED_FEATURES:(e,t)=>{const{featureId:r,multiSelect:n,layerId:o,idProperty:i,addToExisting:a=!0,replaceAll:s=!1,properties:l,geometry:c}=t,u=Array.isArray(e.selectedFeatures)?e.selectedFeatures:[],d=u.findIndex(e=>e.featureId===r&&e.layerId===o);if(!1===a){const t=u.filter((e,t)=>t!==d);return{...e,selectedFeatures:t}}const p={featureId:r,layerId:o,idProperty:i,properties:l,geometry:c};let f;if(n&&!s){const e=[...u];-1===d?e.push(p):e.splice(d,1),f=e}else{f=-1!==d&&1===u.length?[]:[p]}return{...e,selectedFeatures:f,selectedMarkers:n&&!s?e.selectedMarkers:[]}},TOGGLE_SELECTED_MARKERS:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers,o=n.includes(t);if(r){const r=o?n.filter(e=>e!==t):[...n,t];return{...e,selectedMarkers:r}}return{...e,selectedFeatures:[],selectedMarkers:o&&1===n.length?[]:[t]}},CLEAR_SELECTED_FEATURES:e=>({...e,selectedFeatures:[],selectedMarkers:[]}),SET_SELECTED_FEATURES:(e,t)=>({...e,selectedFeatures:t}),SELECT_MARKER:(e,{markerId:t,multiSelect:r})=>{const n=e.selectedMarkers;if(n.includes(t))return e;const o=r?[...n,t]:[t];return{...e,selectedFeatures:r?e.selectedFeatures:[],selectedMarkers:o}},UNSELECT_MARKER:(e,{markerId:t})=>{const r=e.selectedMarkers;return r.includes(t)?{...e,selectedMarkers:r.filter(e=>e!==t)}:e},SET_LISTBOX_ACTIVE:(e,t)=>({...e,listboxActiveItem:t??null}),SET_LISTBOX_FOCUSED:(e,t)=>({...e,listboxFocused:!!t})},Se={tolerance:10,interactionModes:["selectMarker"],multiSelect:!1,contiguous:!1,deselectOnClickOutside:!1,touchTarget:!0,marker:{}},ve="Select",be={InitComponent:({appState:n,mapState:i,services:a,buttonConfig:s,mapProvider:l,pluginState:c})=>{const{enabled:u,selectedFeatures:d,interactionModes:p,layers:f}=c,{eventBus:y}=a,{crossHair:g,mapStyle:m,markers:h}=i,E=he({appState:n,pluginState:c});ue({mapState:i,pluginState:c,services:a,mapProvider:l,spatialListRegistry:n.spatialListRegistry});const{handleInteraction:S}=ie({mapState:i,pluginState:c,services:a,mapProvider:l});return fe({mapProvider:l,mapStyle:m,pluginState:c,selectedFeatures:d,events:o,eventBus:y}),r(()=>{y.emit("interact:active",{active:u,interactionModes:p})},[u,p]),function({enabled:e,interactionModes:t,markers:n,layers:o,eventBus:i}){r(()=>{if(!e)return;const r=t?.includes("selectMarker")&&n.items.some(e=>e.label),a=t?.includes("selectFeature")&&o.some(e=>e.labelProperty);(r||a)&&i.emit("interact:listboxcapable")},[e,t,n,o,i])}({enabled:u,interactionModes:p,markers:h,layers:f,eventBus:y}),((e,t,n,o)=>{r(()=>{const r=t&&n?.includes("selectFeature")?o.map(e=>e.layerId):[];return e.setHoverCursor?.(r),()=>e.setHoverCursor?.([])},[t,n,o])})(l,u,p,f),function({crossHair:n,enabled:o,targetNeeded:i,appState:a,dispatch:s}){const l=t(o);l.current=o;const c=t(i);c.current=i;const u=t(n);u.current=n;const d=t(s);d.current=s;const p=t(!1),f=t(!1),y=t(a.interfaceType);y.current=a.interfaceType;const g=e(()=>{const e="keyboard"===y.current&&f.current,t=c.current&&!p.current;l.current&&(e||t)?u.current.fixAtCenter():u.current.hide()},[]);r(()=>{g()},[o,i,a.interfaceType,g]),r(()=>{const e=a.layoutRefs?.appContainerRef?.current;if(!e)return;const t=e=>{p.current=e,d.current?.({type:"SET_LISTBOX_FOCUSED",payload:e})};f.current=!!document.activeElement?.closest("[data-map-keyboard-scope]"),document.activeElement?.closest(ye)&&t(!0);const r=e=>{const r=!!e.target.closest(ye),n=!!e.target.closest("[data-map-keyboard-scope]"),o=p.current!==r,i=o||f.current!==n;o&&t(r),f.current=n,i&&l.current&&g()};return e.addEventListener("focusin",r),()=>{e.removeEventListener("focusin",r)}},[a.layoutRefs,g])}({crossHair:g,enabled:u,targetNeeded:E,appState:n,dispatch:c.dispatch}),function({pluginState:e,appState:n,mapState:i,buttonConfig:a,eventBus:s,handleInteraction:l}){const c=t(l);c.current=l;const u=t(e);u.current=e;const d=t(n);d.current=n;const p=t(!1);r(()=>{p.current=!1;const e=setTimeout(()=>{p.current=!0},0);return()=>clearTimeout(e)},[e.enabled]),r(()=>{if(e.enabled)return me({getAppState:()=>d.current,mapState:i,getPluginState:()=>u.current,buttonConfig:a,events:o,eventBus:s,handleInteraction:e=>c.current(e),clickReadyRef:p})},[e.enabled,a,s]),r(()=>{if(!e.enabled)return;const t=()=>c.current(i.crossHair.getDetail());return i.crossHair.activate=t,()=>{i.crossHair.activate===t&&(i.crossHair.activate=null)}},[e.enabled,i.crossHair])}({pluginState:c,appState:n,mapState:i,buttonConfig:s,eventBus:y,handleInteraction:S}),null},reducer:{initialState:{enabled:!1,layers:[],marker:null,interactionModes:null,multiSelect:!1,deselectOnClickOutside:!1,touchTarget:!0,selectedFeatures:[],selectedMarkers:[],closeOnAction:!0,listboxActiveItem:null,listboxFocused:!1},actions:Ee},buttons:[{id:"selectAtTarget",label:"Select",variant:"primary",hiddenWhen:({appState:e,pluginState:t})=>!t.enabled||t.listboxFocused||!he({appState:e,pluginState:t}),mobile:{slot:"actions"},tablet:{slot:"actions"},desktop:{slot:"actions"}}],keyboardShortcuts:[{id:"clickAtTarget",title:"Click at target",command:"<kbd>Enter</kbd>"},{id:"selectFeatures",group:ve,context:"listbox",title:"Select features",command:"<kbd>Tab</kbd>"},{id:"navigateFeatures",group:ve,context:"listbox",title:"Highlight next feature",command:"<kbd>↑</kbd> or <kbd>↓</kbd>"},{id:"navigateFeaturesSpatially",group:ve,context:"listbox",title:"Highlight nearby feature",command:`${"undefined"!=typeof navigator&&/mac/i.test(navigator.userAgentData?.platform||navigator.platform||"")?"<kbd>Option</kbd>":"<kbd>Alt</kbd>"} + <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>←</kbd> or <kbd>→</kbd>`},{id:"selectFeature",group:ve,context:"listbox",title:"Select a feature",command:"<kbd>Enter</kbd> or <kbd>Space</kbd>"},{id:"dismissHintOrReturn",group:ve,context:"listbox",title:"Dismiss hint / return to map",command:"<kbd>Escape</kbd>"}],icons:[{id:"select",svgContent:'<path d="M22 14a8 8 0 0 1-8 8"/><path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/><path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1"/><path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10"/><path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>'}],api:{enable:({pluginState:e,pluginConfig:t},r)=>{e.dispatch({type:"ENABLE",payload:{...Se,...t,...r}})},disable:({pluginState:e})=>{e.dispatch({type:"DISABLE"})},clear:({pluginState:e,mapState:t})=>{e.dispatch({type:"CLEAR_SELECTED_FEATURES"}),t.markers.remove("location")},selectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:selectFeature",{featureId:t,layerId:r,idProperty:n})},unselectFeature:({services:e},{featureId:t,layerId:r,idProperty:n})=>{e.eventBus.emit("interact:unselectFeature",{featureId:t,layerId:r,idProperty:n})},selectMarker:({pluginState:e},t)=>{e.dispatch({type:"SELECT_MARKER",payload:{markerId:t,multiSelect:e.multiSelect}})},unselectMarker:({pluginState:e},t)=>{e.dispatch({type:"UNSELECT_MARKER",payload:{markerId:t}})}}};export{be as manifest};