@defra/interactive-map 0.0.53-alpha → 0.0.55-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 (199) hide show
  1. package/assets/templates/add-polygons.njk +1 -1
  2. package/assets/templates/add-symbols.njk +4 -4
  3. package/assets/templates/draw-tools.njk +7 -7
  4. package/assets/templates/marker-panel.njk +5 -5
  5. package/assets/templates/place-marker.njk +8 -8
  6. package/assets/templates/search-control.njk +1 -1
  7. package/assets/templates/select-feature.njk +7 -7
  8. package/assets/templates/style-switcher.njk +4 -4
  9. package/assets/templates/toggle-marker-label.njk +3 -3
  10. package/dist/css/index.css +1 -1
  11. package/dist/esm/im-core.js +1 -1
  12. package/dist/esm/im-shell.js +1 -1
  13. package/dist/esm/index.js +1 -1
  14. package/dist/umd/im-core.js +1 -1
  15. package/dist/umd/im-core.js.LICENSE.txt +0 -30
  16. package/dist/umd/index.js +1 -1
  17. package/dist/umd/index.js.LICENSE.txt +0 -20
  18. package/docs/api/context.md +12 -0
  19. package/docs/api.md +14 -16
  20. package/docs/building-a-plugin.md +2 -2
  21. package/docs/examples/add-marker-with-panel.mdx +46 -44
  22. package/docs/examples/add-polygons.mdx +100 -98
  23. package/docs/examples/add-symbols.mdx +75 -73
  24. package/docs/examples/basic-map.mdx +16 -14
  25. package/docs/examples/button-map.mdx +16 -14
  26. package/docs/examples/draw-tools.mdx +119 -117
  27. package/docs/examples/place-marker.mdx +51 -49
  28. package/docs/examples/search-control.mdx +22 -20
  29. package/docs/examples/select-feature.mdx +107 -105
  30. package/docs/examples/style-switcher.mdx +47 -45
  31. package/docs/examples/toggle-marker-label.mdx +30 -28
  32. package/docs/getting-started.md +26 -24
  33. package/docs/plugins/datasets.md +2 -0
  34. package/docs/plugins/draw.md +10 -10
  35. package/docs/plugins/interact.md +9 -9
  36. package/docs/plugins/map-key.md +41 -0
  37. package/docs/plugins/plugin-descriptor.md +1 -1
  38. package/docs/plugins/search.md +3 -3
  39. package/docusaurus.config.cjs +23 -0
  40. package/package.json +3 -7
  41. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  42. package/plugins/beta/draw-es/dist/esm/index.js +1 -1
  43. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  44. package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
  45. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  46. package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
  47. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  48. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  49. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
  50. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  51. package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
  52. package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
  53. package/plugins/beta/frame/dist/esm/index.js +1 -1
  54. package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
  55. package/plugins/beta/frame/dist/umd/index.js +1 -1
  56. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  57. package/plugins/beta/map-styles/dist/esm/index.js +1 -1
  58. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  59. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  60. package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
  61. package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
  62. package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
  63. package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
  64. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  65. package/plugins/beta/use-location/dist/esm/index.js +1 -1
  66. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  67. package/plugins/beta/use-location/dist/umd/index.js +1 -1
  68. package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
  69. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  70. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  71. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  72. package/plugins/datasets/dist/esm/index.js +1 -1
  73. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  74. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  75. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  76. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  77. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  78. package/plugins/datasets/dist/umd/index.js +1 -1
  79. package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
  80. package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
  81. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +1 -1
  82. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +3 -3
  83. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
  84. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +1 -3
  85. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +0 -12
  86. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +2 -2
  87. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +1 -2
  88. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +3 -3
  89. package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
  90. package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
  91. package/plugins/datasets/src/initialise/defaults.js +12 -24
  92. package/plugins/datasets/src/initialise/defaults.test.js +25 -57
  93. package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
  94. package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
  95. package/plugins/datasets/src/registry/dataset.js +21 -16
  96. package/plugins/datasets/src/registry/dataset.test.js +101 -11
  97. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  98. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  99. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  100. package/plugins/draw/dist/esm/index.js +1 -1
  101. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  102. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  103. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  104. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  105. package/plugins/draw/dist/umd/index.js +1 -1
  106. package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
  107. package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
  108. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  109. package/plugins/interact/dist/esm/index.js +1 -1
  110. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  111. package/plugins/interact/dist/umd/index.js +1 -1
  112. package/plugins/map-key/dist/css/index.css +1 -1
  113. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  114. package/plugins/map-key/dist/esm/index.js +1 -1
  115. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  116. package/plugins/map-key/dist/umd/index.js +1 -1
  117. package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
  118. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +34 -3
  119. package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
  120. package/plugins/map-key/src/components/Key/KeySvg.jsx +5 -5
  121. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
  122. package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
  123. package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
  124. package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
  125. package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
  126. package/plugins/map-key/src/index.js +34 -0
  127. package/plugins/map-key/src/utils/groupStyles.js +5 -2
  128. package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
  129. package/plugins/menu/dist/esm/index.js +1 -1
  130. package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
  131. package/plugins/menu/dist/umd/index.js +1 -1
  132. package/plugins/search/dist/esm/im-search-plugin.js +1 -1
  133. package/plugins/search/dist/esm/index.js +1 -1
  134. package/plugins/search/dist/umd/im-search-plugin.js +1 -1
  135. package/plugins/search/dist/umd/index.js +1 -1
  136. package/plugins/search/src/Search.jsx +0 -1
  137. package/plugins/search/src/components/Form/Form.jsx +3 -3
  138. package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
  139. package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
  140. package/plugins/search/src/defaults.js +3 -0
  141. package/plugins/search/src/events/formHandlers.js +3 -9
  142. package/plugins/search/src/events/formHandlers.test.js +6 -9
  143. package/plugins/search/src/events/inputHandlers.js +8 -2
  144. package/plugins/search/src/events/inputHandlers.test.js +20 -0
  145. package/plugins/search/src/events/suggestionHandlers.js +3 -5
  146. package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
  147. package/plugins/search/src/utils/showResult.js +9 -0
  148. package/plugins/search/src/utils/showResult.test.js +16 -0
  149. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  150. package/providers/beta/esri/dist/esm/index.js +1 -1
  151. package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
  152. package/providers/beta/open-names/dist/esm/index.js +1 -1
  153. package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
  154. package/providers/beta/open-names/dist/umd/index.js +1 -1
  155. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  156. package/providers/beta/openlayers/dist/esm/index.js +1 -1
  157. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  158. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  159. package/providers/beta/openlayers/src/index.js +27 -4
  160. package/providers/beta/openlayers/src/index.test.js +47 -0
  161. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  162. package/providers/maplibre/dist/esm/index.js +1 -1
  163. package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
  164. package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
  165. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  166. package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
  167. package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
  168. package/providers/maplibre/dist/umd/index.js +1 -1
  169. package/providers/maplibre/src/index.js +41 -12
  170. package/providers/maplibre/src/index.test.js +43 -12
  171. package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
  172. package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
  173. package/providers/maplibre/src/utils/spatial.js +22 -12
  174. package/providers/maplibre/src/utils/spatial.test.js +6 -6
  175. package/providers/maplibre/src/utils/workerUrl.js +15 -0
  176. package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
  177. package/rollup.esm.mjs +38 -1
  178. package/src/App/components/Hints/Hints.module.scss +1 -1
  179. package/src/App/components/Viewport/Viewport.jsx +6 -4
  180. package/src/App/components/Viewport/Viewport.test.jsx +18 -1
  181. package/src/App/hooks/useMapAnnouncements.js +7 -2
  182. package/src/App/hooks/useMapAnnouncements.test.js +13 -2
  183. package/src/App/hooks/useModalPanelBehaviour.js +3 -1
  184. package/src/App/initialiseApp.js +1 -1
  185. package/src/App/store/ServiceProvider.jsx +7 -1
  186. package/src/App/store/ServiceProvider.test.jsx +15 -0
  187. package/src/InteractiveMap/InteractiveMap.js +5 -4
  188. package/src/InteractiveMap/InteractiveMap.test.js +9 -2
  189. package/src/InteractiveMap/domStateManager.js +21 -1
  190. package/src/InteractiveMap/domStateManager.test.js +48 -1
  191. package/src/InteractiveMap/polyfills.js +4 -3
  192. package/src/InteractiveMap/polyfills.test.js +12 -0
  193. package/src/services/mapFocus.js +64 -0
  194. package/src/services/mapFocus.test.js +76 -0
  195. package/src/types.js +5 -7
  196. package/src/utils/detectInterfaceType.js +16 -5
  197. package/src/utils/detectInterfaceType.test.js +32 -0
  198. package/webpack.dev.mjs +2 -0
  199. package/webpack.umd.mjs +28 -7
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("defra",[],r):"object"==typeof exports?exports.defra=r():(e.defra=e.defra||{},e.defra.searchPlugin=r())}(this,()=>(()=>{"use strict";var e,r,t={738(e){e.exports=preactCompat},287(e){e.exports=preactJsxRuntime},604(e,r,t){t.d(r,{V:()=>o,z:()=>n});var n={expanded:!1,showMarker:!0,placeholder:"Search",minSearchLength:3,maxSuggestions:8,noResultsMessage:"No results available",searchErrorMessage:"Sorry, there was a problem with search"},o="search"}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.m=t,o.d=(e,r)=>{for(var t in r)o.o(r,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce((r,t)=>(o.f[t](e,r),r),[])),o.u=e=>"im-search-plugin.js",o.miniCssF=e=>{},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="defra.searchPlugin:",o.l=(t,n,i,a)=>{if(e[t])e[t].push(n);else{var c,u;if(void 0!==i)for(var f=document.getElementsByTagName("script"),p=0;p<f.length;p++){var s=f[p];if(s.getAttribute("src")==t||s.getAttribute("data-webpack")==r+i){c=s;break}}c||(u=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",r+i),c.src=t),e[t]=[n];var l=(r,n)=>{c.onerror=c.onload=null,clearTimeout(d);var o=e[t];if(delete e[t],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(e=>e(n)),r)return r(n)},d=setTimeout(l.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=l.bind(null,c.onerror),c.onload=l.bind(null,c.onload),u&&document.head.appendChild(c)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var r=o.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={57:0};o.f.j=(r,t)=>{var n=o.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else{var i=new Promise((t,o)=>n=e[r]=[t,o]);t.push(n[2]=i);var a=o.p+o.u(r),c=new Error;o.l(a,t=>{if(o.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var i=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;c.message="Loading chunk "+r+" failed.\n("+i+": "+a+")",c.name="ChunkLoadError",c.type=i,c.request=a,n[1](c)}},"chunk-"+r,r)}};var r=(r,t)=>{var n,i,[a,c,u]=t,f=0;if(a.some(r=>0!==e[r])){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);u&&u(o)}for(r&&r(t);f<a.length;f++)i=a[f],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0},t=this.webpackChunkdefra_DefraMap=this.webpackChunkdefra_DefraMap||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})();var i={};o.d(i,{default:()=>b});var a=o(604);function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(){var e,r,t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",o=t.toStringTag||"@@toStringTag";function i(t,n,o,i){var u=n&&n.prototype instanceof c?n:c,p=Object.create(u.prototype);return f(p,"_invoke",function(t,n,o){var i,c,u,f=0,p=o||[],s=!1,l={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(r,t){return i=r,c=0,u=e,l.n=t,a}};function d(t,n){for(c=t,u=n,r=0;!s&&f&&!o&&r<p.length;r++){var o,i=p[r],d=l.p,b=i[2];t>3?(o=b===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=t<2&&d<i[1])?(c=0,l.v=n,l.n=i[1]):d<b&&(o=t<3||i[0]>n||n>b)&&(i[4]=t,i[5]=n,l.n=b,c=0))}if(o||t>1)return a;throw s=!0,n}return function(o,p,b){if(f>1)throw TypeError("Generator is already running");for(s&&1===p&&d(p,b),c=p,u=b;(r=c<2?e:u)||!s;){i||(c?c<3?(c>1&&(l.n=-1),d(c,u)):l.n=u:l.v=u);try{if(f=2,i){if(c||(o="next"),r=i[o]){if(!(r=r.call(i,u)))throw TypeError("iterator result is not an object");if(!r.done)return r;u=r.value,c<2&&(c=0)}else 1===c&&(r=i.return)&&r.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((r=(s=l.n<0)?u:t.call(n,l))!==a)break}catch(r){i=e,c=1,u=r}finally{f=1}}return{value:r,done:s}}}(t,o,i),!0),p}var a={};function c(){}function p(){}function s(){}r=Object.getPrototypeOf;var l=[][n]?r(r([][n]())):(f(r={},n,function(){return this}),r),d=s.prototype=c.prototype=Object.create(l);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,f(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return p.prototype=s,f(d,"constructor",s),f(s,"constructor",p),p.displayName="GeneratorFunction",f(s,o,"GeneratorFunction"),f(d),f(d,o,"Generator"),f(d,n,function(){return this}),f(d,"toString",function(){return"[object Generator]"}),(u=function(){return{w:i,m:b}})()}function f(e,r,t,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}f=function(e,r,t,n){function i(r,t){f(e,r,function(e){return this._invoke(r,t,e)})}r?o?o(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n}):e[r]=t:(i("next",0),i("throw",1),i("return",2))},f(e,r,t,n)}function p(e,r,t,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void t(e)}c.done?r(u):Promise.resolve(u).then(n,o)}function s(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function l(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?s(Object(t),!0).forEach(function(r){d(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function d(e,r,t){return(r=function(e){var r=function(e){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var t=r.call(e,"string");if("object"!=c(t))return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==c(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function b(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return l(l(l({},a.z),t),{},{id:"search",load:(e=u().m(function e(){var r;return u().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.e(254).then(o.bind(o,1));case 1:return r=e.v.manifest,e.a(2,r)}},e)}),r=function(){var r=this,t=arguments;return new Promise(function(n,o){var i=e.apply(r,t);function a(e){p(i,n,o,a,c,"next",e)}function c(e){p(i,n,o,a,c,"throw",e)}a(void 0)})},function(){return r.apply(this,arguments)})})}return i.default})());
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("defra",[],t):"object"==typeof exports?exports.defra=t():(e.defra=e.defra||{},e.defra.searchPlugin=t())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var e,t,r={738:function(e){e.exports=preactCompat},287:function(e){e.exports=preactJsxRuntime},604:function(e,t,r){r.d(t,{V3:function(){return i},cr:function(){return o},zY:function(){return n}});var n={expanded:!1,showMarker:!0,placeholder:"Search",minSearchLength:3,maxSuggestions:8,noResultsMessage:"No results available",searchErrorMessage:"Sorry, there was a problem with search"},o="Map moved to {query}",i="search"}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.m=r,o.d=function(e,t){for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.f={},o.e=function(e){return Promise.all(Object.keys(o.f).reduce(function(t,r){return o.f[r](e,t),t},[]))},o.u=function(e){return"im-search-plugin.js"},o.miniCssF=function(e){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},e={},t="defra.searchPlugin:",o.l=function(r,n,i,u){if(e[r])e[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),s=0;s<f.length;s++){var l=f[s];if(l.getAttribute("src")==r||l.getAttribute("data-webpack")==t+i){c=l;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",t+i),c.src=r),e[r]=[n];var p=function(t,n){c.onerror=c.onload=null,clearTimeout(d);var o=e[r];if(delete e[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(e){return e(n)}),t)return t(n)},d=setTimeout(p.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=p.bind(null,c.onerror),c.onload=p.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},function(){var e;o.g.importScripts&&(e=o.g.location+"");var t=o.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=r[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e}(),function(){var e={57:0};o.f.j=function(t,r){var n=o.o(e,t)?e[t]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=e[t]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(t),c=new Error;o.l(u,function(r){if(o.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+t+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+t,t)}};var t=function(t,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(t){return 0!==e[t]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(t&&t(r);f<u.length;f++)i=u[f],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))}();var i={};o.d(i,{default:function(){return b}});var u=o(604);function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function a(){var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=n&&n.prototype instanceof c?n:c,s=Object.create(a.prototype);return f(s,"_invoke",function(r,n,o){var i,c,a,f=0,s=o||[],l=!1,p={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(t,r){return i=t,c=0,a=e,p.n=r,u}};function d(r,n){for(c=r,a=n,t=0;!l&&f&&!o&&t<s.length;t++){var o,i=s[t],d=p.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,p.v=n,p.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,p.n=b,c=0))}if(o||r>1)return u;throw l=!0,n}return function(o,s,b){if(f>1)throw TypeError("Generator is already running");for(l&&1===s&&d(s,b),c=s,a=b;(t=c<2?e:a)||!l;){i||(c?c<3?(c>1&&(p.n=-1),d(c,a)):p.n=a:p.v=a);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,a)))throw TypeError("iterator result is not an object");if(!t.done)return t;a=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(l=p.n<0)?a:r.call(n,p))!==u)break}catch(t){i=e,c=1,a=t}finally{f=1}}return{value:t,done:l}}}(r,o,i),!0),s}var u={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var p=[][n]?t(t([][n]())):(f(t={},n,function(){return this}),t),d=l.prototype=c.prototype=Object.create(p);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,f(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return s.prototype=l,f(d,"constructor",l),f(l,"constructor",s),s.displayName="GeneratorFunction",f(l,o,"GeneratorFunction"),f(d),f(d,o,"Generator"),f(d,n,function(){return this}),f(d,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:b}})()}function f(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}f=function(e,t,r,n){function i(t,r){f(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},f(e,t,r,n)}function s(e,t,r,n,o,i,u){try{var c=e[i](u),a=c.value}catch(e){return void r(e)}c.done?t(a):Promise.resolve(a).then(n,o)}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach(function(t){d(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function d(e,t,r){return(t=function(e){var t=function(e){if("object"!=c(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=c(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==c(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function b(){var e,t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return p(p(p({},u.zY),r),{},{id:"search",load:(e=a().m(function e(){var t;return a().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.e(254).then(o.bind(o,323));case 1:return t=e.v.manifest,e.a(2,t)}},e)}),t=function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function u(e){s(i,n,o,u,c,"next",e)}function c(e){s(i,n,o,u,c,"throw",e)}u(void 0)})},function(){return t.apply(this,arguments)})})}return i.default}()});
@@ -36,7 +36,6 @@ export function Search ({ appConfig, iconRegistry, pluginState, pluginConfig, ap
36
36
  datasets: mergedDatasets,
37
37
  services,
38
38
  mapProvider,
39
- viewportRef,
40
39
  searchContainerRef,
41
40
  markers: mapState.markers,
42
41
  markerOptions,
@@ -55,7 +55,7 @@ export const Form = ({
55
55
  className={classNames}
56
56
  style={getFormStyle(pluginConfig, pluginState, appState)}
57
57
  aria-controls={`${id}-viewport`}
58
- onSubmit={(e) => events.handleSubmit(e, appState, pluginState)}
58
+ onSubmit={(event) => events.handleSubmit(event, appState, pluginState)}
59
59
  >
60
60
  {/* Hidden submit button - required for Enter key to trigger form submission */}
61
61
  <button type='submit' style={{ display: 'none' }} aria-hidden='true' tabIndex={-1}>
@@ -81,10 +81,10 @@ export const Form = ({
81
81
  enterKeyHint='search'
82
82
  value={pluginState.value}
83
83
  onClick={events.handleInputClick}
84
- onChange={events.handleInputChange}
84
+ onChange={(event) => events.handleInputChange(event, pluginState)}
85
85
  onFocus={() => events.handleInputFocus(appState.interfaceType)}
86
86
  onBlur={() => events.handleInputBlur(appState.interfaceType)}
87
- onKeyDown={(e) => events.handleInputKeyDown(e, pluginState)}
87
+ onKeyDown={(event) => events.handleInputKeyDown(event, pluginState)}
88
88
  ref={inputRef}
89
89
  />
90
90
  <span id={`${id}-search-hint`} className='im-c-search__hint'>
@@ -7,6 +7,8 @@ export const Suggestions = ({ id, pluginState, handleSuggestionClick }) => {
7
7
  aria-labelledby={`${id}-search-input`} // Option A: label from input
8
8
  className='im-c-search-suggestions'
9
9
  style={!pluginState.areSuggestionsVisible || !pluginState.suggestions.length ? { display: 'none' } : undefined}
10
+ // Keep focus in the input while a suggestion is pressed, so its blur can't hide the list before the click lands
11
+ onMouseDown={(event) => event.preventDefault()}
10
12
  >
11
13
  {pluginState.suggestions.map((suggestion, i) => (
12
14
  <li // NOSONAR
@@ -29,6 +29,12 @@ describe('Suggestions', () => {
29
29
  expect(listbox.className).toContain('im-c-search-suggestions')
30
30
  })
31
31
 
32
+ it('keeps focus in the input when a suggestion is pressed', () => {
33
+ render(<Suggestions {...baseProps} />)
34
+ const option = screen.getAllByRole('option')[1]
35
+ expect(fireEvent.mouseDown(option)).toBe(false) // default prevented
36
+ })
37
+
32
38
  it('hides the listbox when suggestions are not visible', () => {
33
39
  render(
34
40
  <Suggestions
@@ -8,5 +8,8 @@ export const DEFAULTS = {
8
8
  searchErrorMessage: 'Sorry, there was a problem with search'
9
9
  }
10
10
 
11
+ // Read by screen readers as focus moves to the map after a search finds a result
12
+ export const RESULT_MESSAGE = 'Map moved to {query}'
13
+
11
14
  // The application mode search enters while its form is expanded (see search.scss's .im-o-app--mode-search)
12
15
  export const APPLICATION_MODE_ID = 'search'
@@ -1,5 +1,5 @@
1
1
  import { fetchSuggestions } from './fetchSuggestions.js'
2
- import { updateMap } from '../utils/updateMap.js'
2
+ import { showResult } from '../utils/showResult.js'
3
3
  import { DEFAULTS } from '../defaults.js'
4
4
 
5
5
  // Resolve the open trigger — a core-rendered MapButton. Prefer the shared buttonRefs
@@ -63,7 +63,6 @@ const tabOutFromTrigger = (event, buttonRefs, searchContainerRef) => {
63
63
  export const createFormHandlers = ({
64
64
  dispatch,
65
65
  services,
66
- viewportRef,
67
66
  searchContainerRef,
68
67
  mapProvider,
69
68
  markers,
@@ -100,9 +99,7 @@ export const createFormHandlers = ({
100
99
  if (selectedIndex >= 0) {
101
100
  const suggestion = suggestions[selectedIndex]
102
101
  dispatch({ type: 'SET_VALUE', payload: suggestion.text })
103
- viewportRef.current?.focus()
104
- updateMap({ mapProvider, bounds: suggestion.bounds, point: suggestion.point, markers, showMarker, markerOptions })
105
- services.eventBus.emit('search:match', { query: suggestion.text, ...suggestion })
102
+ showResult({ suggestion, query: suggestion.text, services, mapProvider, markers, showMarker, markerOptions })
106
103
  return
107
104
  }
108
105
 
@@ -118,14 +115,11 @@ export const createFormHandlers = ({
118
115
  }
119
116
 
120
117
  if (newSuggestions.length) {
121
- viewportRef.current?.focus()
122
118
  if (appState.breakpoint === 'mobile') {
123
119
  dispatch({ type: 'TOGGLE_EXPANDED', payload: false })
124
120
  services.eventBus.emit('search:close')
125
121
  }
126
- const suggestion = newSuggestions[0]
127
- updateMap({ mapProvider, bounds: suggestion.bounds, point: suggestion.point, markers, showMarker, markerOptions })
128
- services.eventBus.emit('search:match', { query: value, ...suggestion })
122
+ showResult({ suggestion: newSuggestions[0], query: value, services, mapProvider, markers, showMarker, markerOptions })
129
123
  }
130
124
  }
131
125
  }
@@ -12,7 +12,6 @@ jest.mock('../utils/updateMap.js')
12
12
  describe('createFormHandlers', () => {
13
13
  let dispatch
14
14
  let services
15
- let viewportRef
16
15
  let markers
17
16
  let handlers
18
17
 
@@ -20,11 +19,8 @@ describe('createFormHandlers', () => {
20
19
  dispatch = jest.fn()
21
20
 
22
21
  services = {
23
- eventBus: { emit: jest.fn() }
24
- }
25
-
26
- viewportRef = {
27
- current: { focus: jest.fn() }
22
+ eventBus: { emit: jest.fn() },
23
+ focusMap: jest.fn()
28
24
  }
29
25
 
30
26
  markers = {
@@ -34,7 +30,6 @@ describe('createFormHandlers', () => {
34
30
  handlers = createFormHandlers({
35
31
  dispatch,
36
32
  services,
37
- viewportRef,
38
33
  mapProvider: 'map',
39
34
  markers,
40
35
  datasets: [],
@@ -129,6 +124,7 @@ describe('createFormHandlers', () => {
129
124
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_SELECTED', payload: -1 })
130
125
  expect(dispatch).toHaveBeenCalledWith({ type: 'HIDE_SUGGESTIONS' })
131
126
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_VALUE', payload: 'Paris' })
127
+ expect(services.focusMap).toHaveBeenCalledWith({ message: 'Map moved to Paris' })
132
128
 
133
129
  expect(updateMap).toHaveBeenCalledWith(
134
130
  expect.objectContaining({ bounds: 'b', point: 'p' })
@@ -174,7 +170,7 @@ describe('createFormHandlers', () => {
174
170
  )
175
171
 
176
172
  expect(fetchSuggestions).toHaveBeenCalled()
177
- expect(viewportRef.current.focus).toHaveBeenCalled()
173
+ expect(services.focusMap).toHaveBeenCalledWith({ message: 'Map moved to rome' })
178
174
  expect(updateMap).toHaveBeenCalled()
179
175
  expect(services.eventBus.emit).toHaveBeenCalledWith(
180
176
  'search:match',
@@ -227,6 +223,7 @@ describe('createFormHandlers', () => {
227
223
  expect(fetchSuggestions).toHaveBeenCalled()
228
224
 
229
225
  // But nothing downstream runs
226
+ expect(services.focusMap).not.toHaveBeenCalled()
230
227
  expect(updateMap).not.toHaveBeenCalled()
231
228
  expect(services.eventBus.emit).not.toHaveBeenCalledWith(
232
229
  'search:match',
@@ -282,7 +279,7 @@ describe('createFormHandlers', () => {
282
279
  // before, input, closeButton, trigger, afterTrigger
283
280
  const stops = [before, input, closeButton, trigger, afterTrigger]
284
281
  stops.forEach(el => { el.getClientRects = () => [{}] })
285
- tabHandlers = createFormHandlers({ dispatch, services, viewportRef, searchContainerRef: { current: container }, markers })
282
+ tabHandlers = createFormHandlers({ dispatch, services, searchContainerRef: { current: container }, markers })
286
283
  })
287
284
 
288
285
  afterEach(() => {
@@ -13,10 +13,16 @@ export const createInputHandlers = ({ dispatch, debouncedFetchSuggestions }) =>
13
13
  dispatch({ type: 'INPUT_BLUR', payload: interfaceType })
14
14
  },
15
15
 
16
- handleInputChange (e) {
17
- const value = e.target.value
16
+ handleInputChange (event, pluginState) {
17
+ const value = event.target.value
18
18
  dispatch({ type: 'SET_VALUE', payload: value })
19
19
 
20
+ // Typing after arrowing to a suggestion returns the focus ring to the input
21
+ if (pluginState?.selectedIndex >= 0) {
22
+ dispatch({ type: 'SET_SELECTED', payload: -1 })
23
+ dispatch({ type: 'SET_KEYBOARD_FOCUS_WITHIN', payload: true })
24
+ }
25
+
20
26
  if (value.length < DEFAULTS.minSearchLength) {
21
27
  debouncedFetchSuggestions.cancel()
22
28
  dispatch({ type: 'UPDATE_SUGGESTIONS', payload: { results: [], hasError: false } })
@@ -101,4 +101,24 @@ describe('createInputHandlers', () => {
101
101
  expect(debouncedFetchSuggestions).toHaveBeenCalledWith(value)
102
102
  expect(debouncedFetchSuggestions.cancel).not.toHaveBeenCalled()
103
103
  })
104
+
105
+ test('handleInputChange after arrowing to a suggestion clears it and restores the input focus ring', () => {
106
+ const value = 'a'.repeat(DEFAULTS.minSearchLength)
107
+
108
+ handlers.handleInputChange({ target: { value } }, { selectedIndex: 1 })
109
+
110
+ expect(dispatch.mock.calls.map(([action]) => action)).toEqual([
111
+ { type: 'SET_VALUE', payload: value },
112
+ { type: 'SET_SELECTED', payload: -1 },
113
+ { type: 'SET_KEYBOARD_FOCUS_WITHIN', payload: true },
114
+ { type: 'SHOW_SUGGESTIONS' }
115
+ ])
116
+ })
117
+
118
+ test('handleInputChange with no suggestion selected leaves the focus ring alone', () => {
119
+ handlers.handleInputChange({ target: { value: 'abc' } }, { selectedIndex: -1 })
120
+
121
+ expect(dispatch).not.toHaveBeenCalledWith({ type: 'SET_KEYBOARD_FOCUS_WITHIN', payload: true })
122
+ expect(dispatch).not.toHaveBeenCalledWith({ type: 'SET_SELECTED', payload: -1 })
123
+ })
104
124
  })
@@ -1,6 +1,6 @@
1
- import { updateMap } from '../utils/updateMap.js'
1
+ import { showResult } from '../utils/showResult.js'
2
2
 
3
- export const createSuggestionHandlers = ({ dispatch, services, mapProvider, markers, showMarker, markerOptions, viewportRef }) => {
3
+ export const createSuggestionHandlers = ({ dispatch, services, mapProvider, markers, showMarker, markerOptions }) => {
4
4
  const selectionMessage = (suggestions, index) =>
5
5
  index >= 0
6
6
  ? `${suggestions[index]?.text}. ${index + 1} of ${suggestions.length} is highlighted`
@@ -17,9 +17,7 @@ export const createSuggestionHandlers = ({ dispatch, services, mapProvider, mark
17
17
  services.eventBus.emit('search:close')
18
18
  }
19
19
 
20
- viewportRef.current?.focus()
21
- updateMap({ mapProvider, bounds: suggestion.bounds, point: suggestion.point, markers, showMarker, markerOptions })
22
- services.eventBus.emit('search:match', { query: suggestion.text, ...suggestion })
20
+ showResult({ suggestion, query: suggestion.text, services, mapProvider, markers, showMarker, markerOptions })
23
21
  },
24
22
 
25
23
  handleInputKeyDown (e, pluginState) {
@@ -9,7 +9,6 @@ jest.mock('../utils/updateMap.js')
9
9
  describe('createSuggestionHandlers', () => {
10
10
  let dispatch
11
11
  let services
12
- let viewportRef
13
12
  let handlers
14
13
 
15
14
  beforeEach(() => {
@@ -17,19 +16,17 @@ describe('createSuggestionHandlers', () => {
17
16
 
18
17
  services = {
19
18
  eventBus: { emit: jest.fn() },
20
- announce: jest.fn()
19
+ announce: jest.fn(),
20
+ focusMap: jest.fn()
21
21
  }
22
22
 
23
- viewportRef = { current: { focus: jest.fn() } }
24
-
25
23
  handlers = createSuggestionHandlers({
26
24
  dispatch,
27
25
  services,
28
26
  mapProvider: 'map',
29
27
  markers: 'markers',
30
28
  showMarker: true,
31
- markerOptions: { backgroundColor: 'blue' },
32
- viewportRef
29
+ markerOptions: { backgroundColor: 'blue' }
33
30
  })
34
31
 
35
32
  jest.clearAllMocks()
@@ -45,7 +42,7 @@ describe('createSuggestionHandlers', () => {
45
42
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_VALUE', payload: 'Paris' })
46
43
  expect(dispatch).toHaveBeenCalledWith({ type: 'HIDE_SUGGESTIONS' })
47
44
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_SELECTED', payload: -1 })
48
- expect(viewportRef.current.focus).toHaveBeenCalled()
45
+ expect(services.focusMap).toHaveBeenCalledWith({ message: 'Map moved to Paris' })
49
46
  expect(updateMap).toHaveBeenCalledWith(expect.objectContaining({ bounds: 'b', point: 'p' }))
50
47
  expect(services.eventBus.emit).toHaveBeenCalledWith(
51
48
  'search:match',
@@ -60,7 +57,7 @@ describe('createSuggestionHandlers', () => {
60
57
 
61
58
  expect(dispatch).toHaveBeenCalledWith({ type: 'TOGGLE_EXPANDED', payload: false })
62
59
  expect(services.eventBus.emit).toHaveBeenCalledWith('search:close')
63
- expect(viewportRef.current.focus).toHaveBeenCalled()
60
+ expect(services.focusMap).toHaveBeenCalledWith({ message: 'Map moved to Berlin' })
64
61
  })
65
62
 
66
63
  // ---------- ArrowDown ----------
@@ -0,0 +1,9 @@
1
+ import { updateMap } from './updateMap.js'
2
+ import { RESULT_MESSAGE } from '../defaults.js'
3
+
4
+ // Moves focus to the map with the result message, moves the map to the result and emits the match
5
+ export const showResult = ({ suggestion, query, services, mapProvider, markers, showMarker, markerOptions }) => {
6
+ services.focusMap({ message: RESULT_MESSAGE.replace('{query}', query) })
7
+ updateMap({ mapProvider, bounds: suggestion.bounds, point: suggestion.point, markers, showMarker, markerOptions })
8
+ services.eventBus.emit('search:match', { query, ...suggestion })
9
+ }
@@ -0,0 +1,16 @@
1
+ import { showResult } from './showResult.js'
2
+ import { updateMap } from './updateMap.js'
3
+
4
+ jest.mock('./updateMap.js')
5
+
6
+ describe('showResult', () => {
7
+ it('focuses the map with the result message, moves the map and emits the match', () => {
8
+ const services = { focusMap: jest.fn(), eventBus: { emit: jest.fn() } }
9
+ const suggestion = { text: 'Carlisle, Cumbria', bounds: 'b', point: 'p' }
10
+ showResult({ suggestion, query: 'carlisle', services, mapProvider: 'map', markers: 'markers', showMarker: true })
11
+
12
+ expect(services.focusMap).toHaveBeenCalledWith({ message: 'Map moved to carlisle' })
13
+ expect(updateMap).toHaveBeenCalledWith(expect.objectContaining({ mapProvider: 'map', bounds: 'b', point: 'p' }))
14
+ expect(services.eventBus.emit).toHaveBeenCalledWith('search:match', { query: 'carlisle', ...suggestion })
15
+ })
16
+ })
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import r from"@arcgis/core/config.js";import n from"@arcgis/core/layers/support/TileInfo.js";import a from"@arcgis/core/Map.js";import o from"@arcgis/core/views/MapView.js";import i from"@arcgis/core/layers/VectorTileLayer.js";import s from"@arcgis/core/geometry/Point.js";import{when as m,once as l,watch as p}from"@arcgis/core/core/reactiveUtils.js";import c from"@arcgis/core/geometry/Extent.js";class u{_notImplemented(e){throw new Error("".concat(this.name," must implement ").concat(e,"()"))}isBaseMapReady(){this._notImplemented("isBaseMapReady")}addSymbolsToMap(){this._notImplemented("addSymbolsToMap")}addPatternsToMap(){this._notImplemented("addPatternsToMap")}getActiveSymbolImageId(){this._notImplemented("getActiveSymbolImageId")}getSelectedSymbolImageId(){this._notImplemented("getSelectedSymbolImageId")}}var v={animationDuration:200},d=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom"];var y=(e,t)=>{var r=null,n=function(){for(var n=arguments.length,a=new Array(n),o=0;o<n;o++)a[o]=arguments[o];clearTimeout(r),r=setTimeout(()=>{e(...a)},t)};return n.cancel=()=>{r&&(clearTimeout(r),r=null)},n};function h(e){var{mapProvider:t,view:r,baseTileLayer:n,events:a,eventBus:o,getZoom:i,getCenter:s,getBounds:c,getResolution:u}=e,v=!1,d=[],h=[],f=e=>{var t=(()=>{if(v||!r||r.destroyed||!r.extent)return null;var{maxZoom:e,minZoom:t}=r.constraints;return{center:s(),bounds:c(),resolution:u(),zoom:i(),isAtMaxZoom:r.zoom+.01>=e,isAtMinZoom:r.zoom-.01<=t}})();t&&o.emit(e,t)};m(()=>n.loaded&&r.resolution>0,()=>f(a.MAP_LOADED)),l(()=>r.ready).then(()=>{v||(t.setBaseMapReady(!0),o.emit(a.MAP_READY,{map:t.map,view:t.view,mapStyleId:t.mapStyleId,mapSize:t.mapSize,crs:t.crs}))}),l(()=>r.stationary).then(()=>f(a.MAP_FIRST_IDLE));var g=y(()=>f(a.MAP_MOVE_END),500);h.push(g),d.push(p(()=>[r.interacting,r.animation],e=>{var[t,r]=e;(t||r)&&o.emit(a.MAP_MOVE_START),t||r||g()}));var w,x,b,M=(w=()=>f(a.MAP_MOVE),x=10,b=0,function(){var e=Date.now();e-b>=x&&(b=e,w(...arguments))});h.push(M),d.push(p(()=>r.zoom,M)),d.push(p(()=>r.extent,()=>o.emit(a.MAP_RENDER),{initial:!1}));var E=y(()=>f(a.MAP_DATA_CHANGE),500);h.push(E),d.push(p(()=>r.updating,e=>!e&&E()));var S=null,T=null;return d.push(r.on("pointer-down",e=>{S=e.x,T=e.y})),d.push(r.on("pointer-up",e=>{var n;if(0===e.button&&!(Math.hypot(e.x-S,e.y-T)>6)&&"active"!==(null===(n=t.sketchViewModel)||void 0===n?void 0:n.state)){var i={x:e.x,y:e.y},s=r.toMap(i);s&&o.emit(a.MAP_CLICK,{point:i,coords:[s.x,s.y]})}})),{remove(){v=!0,h.forEach(e=>e.cancel()),d.forEach(e=>e.remove())}}}var f=e=>e?new c({xmin:e[0],ymin:e[1],xmax:e[2],ymax:e[3],spatialReference:{wkid:27700}}):void 0,g=e=>e?new s({x:e[0],y:e[1],spatialReference:{wkid:27700}}):void 0,w=(e,t)=>{if(e)if("FeatureCollection"===e.type)e.features.forEach(e=>w(e,t));else if("Feature"===e.type)w(e.geometry,t);else if("GeometryCollection"===e.type)e.geometries.forEach(e=>w(e,t));else{var r=e=>{Array.isArray(e)&&("number"==typeof e[0]?t.push(e):e.forEach(r))};r(e.coordinates)}},x=e=>{var t=[];w(e,t);var r=t.map(e=>e[0]),n=t.map(e=>e[1]);return f([Math.min(...r),Math.min(...n),Math.max(...r),Math.max(...n)])},b=e=>{var t=1609.344,r=e/t;if(r<.5/t){var n=Math.round(e),a=1===n?"metre":"metres";return"".concat(n," ").concat(a)}if(r<10){var o=Number.parseFloat(r.toFixed(1)),i=1===o?"mile":"miles";return"".concat(o," ").concat(i)}var s=Math.round(r),m=1===s?"mile":"miles";return"".concat(s," ").concat(m)};var M={top:0,right:0,bottom:0,left:0};function E(){return(E=e(function*(e,t){if(!e||!t)return[];var r=e.map.layers.filter(e=>e instanceof i);return r.length?(yield e.hitTest(t,{include:r.toArray()})).results.map(e=>({layerId:e.layer.id,layerTitle:e.layer.title||e.layer.id,type:e.layer.type,geometry:e.graphic.geometry,symbol:e.graphic.symbol})):[]})).apply(this,arguments)}function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function T(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?S(Object(n),!0).forEach(function(r){t(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):S(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}class A extends u{constructor(e){var{mapProviderConfig:r={},events:n,eventBus:a}=e;super(),t(this,"_isBaseMapReady",!1),this.events=n,this.eventBus=a,this.capabilities={supportedShortcuts:d,supportsMapSizes:!1},Object.assign(this,r),this.mapEventHandles=[],this.appEventHandles=[]}get name(){return"EsriProvider"}initMap(t){var s=this;return e(function*(){var{container:e,padding:m,mapStyle:l,mapSize:p,maxExtent:c}=t;s.mapStyleId=null==l?void 0:l.id,s.mapSize=p;var{events:u,eventBus:v}=s;s.setupConfig&&(yield s.setupConfig(r));var d=new i({id:"baselayer",url:l.url,visible:!0}),y=new a({layers:[d]}),w=c?f(c):null,x=new o({spatialReference:27700,container:e,map:y,zoom:t.zoom,center:g(t.center),maxExtent:c,constraints:{lods:n.create({spatialReference:{wkid:27700}}).lods,snapToZoom:!1,minZoom:t.minZoom,maxZoom:t.maxZoom,maxScale:0,geometry:w,rotationEnabled:!1},ui:{components:[]},popupEnabled:!1});(e=>{if(e){var t=e.querySelector(".esri-view-surface");t.removeAttribute("role"),t.tabIndex=-1,t.style["outline-color"]="transparent",t.style.touchAction="none"}})(x.container),x.padding=m,t.bounds&&x.when(()=>x.goTo(f(t.bounds),{duration:0})),s.mapEventHandles=h({mapProvider:s,view:x,baseTileLayer:d,events:u,eventBus:v,getZoom:s.getZoom.bind(s),getCenter:s.getCenter.bind(s),getBounds:s.getBounds.bind(s),getResolution:s.getResolution.bind(s)}),s.appEventHandles=function(e){var{baseTileLayer:t,events:r,eventBus:n}=e,a=e=>{t.loadStyle(e.url).then(()=>{n.emit(r.MAP_STYLE_CHANGE,{mapStyleId:e.id})})};return n.on(r.MAP_SET_STYLE,a),{remove(){n.off(r.MAP_SET_STYLE,a)}}}({baseTileLayer:d,events:u,eventBus:v})||[],s.map=y,s.view=x,s.baseTileLayer=d})()}setBaseMapReady(e){this._isBaseMapReady=e}isBaseMapReady(){return this._isBaseMapReady}destroyMap(){var e,t;null===(e=this.mapEvents)||void 0===e||e.remove(),null===(t=this.appEvents)||void 0===t||t.remove(),this.mapEvents=null,this.appEvents=null,this.view&&(this.view.container=null,this.view.destroy(),this.view=null),this.map&&(this.map.removeAll(),this.map=null)}setView(e){var t,{center:r,zoom:n}=e;null===(t=this.view.animation)||void 0===t||t.destroy();var a={center:r?new s({x:r[0],y:r[1],spatialReference:{wkid:27700}}):this.view.center,zoom:null!=n?n:this.view.zoom};this.view.goTo(T(T({},a),{},{duration:v.animationDuration}))}zoomIn(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom+e,duration:v.animationDuration})}zoomOut(e){var t;null===(t=this.view.animation)||void 0===t||t.destroy(),this.view.goTo({zoom:this.view.zoom-e,duration:v.animationDuration})}panBy(e){var{x:t,y:r}=this.view.toScreen(this.view.center),n={x:t+e[0],y:r+e[1]},a=this.view.toMap(n);this.view.goTo({center:a,duration:v.animationDuration})}fitToBounds(e){var t=Array.isArray(e)?f(e):x(e);this.view.goTo(t,{duration:v.DELAY})}setPadding(e){this.view.padding=e}getCenter(){var e=this.view.center;return[e.x,e.y].map(e=>Math.round(100*e)/100)}getZoom(){return this.view.zoom}getBounds(){var{xmin:e,ymin:t,xmax:r,ymax:n}=this.view.extent;return[e,t,r,n].map(e=>Math.round(100*e)/100)}getFeaturesAtPoint(e,t){return function(e,t){return E.apply(this,arguments)}(this.view,e)}getVisibleFeatures(e){return[]}getAreaDimensions(){return(e=>{if(!(e&&e instanceof c))return"";var t=e.xmin,r=e.ymin,n=e.xmax,a=e.ymax-r,o=b(n-t),i=b(a);return"".concat(i," by ").concat(o)})(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:M;if(!e.container)return null;var{width:r,height:n}=e.container.getBoundingClientRect(),a={x:t.left,y:n-t.bottom},o={x:r-t.right,y:t.top},i=e.toMap(a),s=e.toMap(o);return new c({xmin:i.x,ymin:i.y,xmax:s.x,ymax:s.y,spatialReference:i.spatialReference})}(this.view))}getCardinalMove(e,t){return function(e,t){var[r,n]=e,[a,o]=t,i=a-r,s=o-n,m=[];return Math.abs(s)>.1&&m.push("".concat(s>0?"north":"south"," ").concat(b(Math.abs(s)))),Math.abs(i)>.1&&m.push("".concat(i>0?"east":"west"," ").concat(b(Math.abs(i)))),m.join(", ")}(e,t)}getResolution(){return this.view.resolution}mapToScreen(e){var t=g(e),r=this.view.toScreen(t);return{x:r.x,y:r.y}}screenToMap(e){var t=this.view.toMap(e);return[t.x,t.y]}isGeometryObscured(e,t){return((e,t,r)=>{if(null==r||!r.container)return!1;var n=r.container.getBoundingClientRect(),a=x(e),o=[r.toScreen(new s({x:a.xmin,y:a.ymin,spatialReference:a.spatialReference})),r.toScreen(new s({x:a.xmin,y:a.ymax,spatialReference:a.spatialReference})),r.toScreen(new s({x:a.xmax,y:a.ymin,spatialReference:a.spatialReference})),r.toScreen(new s({x:a.xmax,y:a.ymax,spatialReference:a.spatialReference}))],i=Math.min(...o.map(e=>e.x)),m=Math.max(...o.map(e=>e.x)),l=Math.min(...o.map(e=>e.y)),p=Math.max(...o.map(e=>e.y)),c=t.left-n.left,u=t.top-n.top,v=t.right-n.left,d=t.bottom-n.top;return i<v&&m>c&&l<d&&p>u})(e,t,this.view)}}export{A as default};
1
+ import e from"@arcgis/core/config.js";import t from"@arcgis/core/layers/support/TileInfo.js";import n from"@arcgis/core/Map.js";import i from"@arcgis/core/views/MapView.js";import o from"@arcgis/core/layers/VectorTileLayer.js";import a from"@arcgis/core/geometry/Point.js";import{when as s,once as r,watch as m}from"@arcgis/core/core/reactiveUtils.js";import l from"@arcgis/core/geometry/Extent.js";class c{_notImplemented(e){throw new Error(`${this.name} must implement ${e}()`)}isBaseMapReady(){this._notImplemented("isBaseMapReady")}addSymbolsToMap(){this._notImplemented("addSymbolsToMap")}addPatternsToMap(){this._notImplemented("addPatternsToMap")}getActiveSymbolImageId(){this._notImplemented("getActiveSymbolImageId")}getSelectedSymbolImageId(){this._notImplemented("getSelectedSymbolImageId")}}const p={animationDuration:200},u=["showKeyboardHelp","selectControl","moveLarge","nudgeMap","zoomLarge","nudgeZoom"];const h=(e,t)=>{let n=null;const i=(...i)=>{clearTimeout(n),n=setTimeout(()=>{e(...i)},t)};return i.cancel=()=>{n&&(clearTimeout(n),n=null)},i};function d({mapProvider:e,view:t,baseTileLayer:n,events:i,eventBus:o,getZoom:a,getCenter:l,getBounds:c,getResolution:p}){let u=!1;const d=[],y=[],v=e=>{const n=(()=>{if(u||!t||t.destroyed||!t.extent)return null;const{maxZoom:e,minZoom:n}=t.constraints;return{center:l(),bounds:c(),resolution:p(),zoom:a(),isAtMaxZoom:t.zoom+.01>=e,isAtMinZoom:t.zoom-.01<=n}})();n&&o.emit(e,n)};s(()=>n.loaded&&t.resolution>0,()=>v(i.MAP_LOADED)),r(()=>t.ready).then(()=>{u||(e.setBaseMapReady(!0),o.emit(i.MAP_READY,{map:e.map,view:e.view,mapStyleId:e.mapStyleId,mapSize:e.mapSize,crs:e.crs}))}),r(()=>t.stationary).then(()=>v(i.MAP_FIRST_IDLE));const g=h(()=>v(i.MAP_MOVE_END),500);y.push(g),d.push(m(()=>[t.interacting,t.animation],([e,t])=>{(e||t)&&o.emit(i.MAP_MOVE_START),e||t||g()}));const x=((e,t)=>{let n=0;return(...i)=>{const o=Date.now();o-n>=t&&(n=o,e(...i))}})(()=>v(i.MAP_MOVE),10);y.push(x),d.push(m(()=>t.zoom,x)),d.push(m(()=>t.extent,()=>o.emit(i.MAP_RENDER),{initial:!1}));const f=h(()=>v(i.MAP_DATA_CHANGE),500);y.push(f),d.push(m(()=>t.updating,e=>!e&&f()));let w=null,M=null;return d.push(t.on("pointer-down",e=>{w=e.x,M=e.y})),d.push(t.on("pointer-up",n=>{if(0!==n.button)return;if(Math.hypot(n.x-w,n.y-M)>6)return;if("active"===e.sketchViewModel?.state)return;const a={x:n.x,y:n.y},s=t.toMap(a);s&&o.emit(i.MAP_CLICK,{point:a,coords:[s.x,s.y]})})),{remove(){u=!0,y.forEach(e=>e.cancel()),d.forEach(e=>e.remove())}}}const y=e=>e?new l({xmin:e[0],ymin:e[1],xmax:e[2],ymax:e[3],spatialReference:{wkid:27700}}):void 0,v=e=>e?new a({x:e[0],y:e[1],spatialReference:{wkid:27700}}):void 0,g=(e,t)=>{if(e)if("FeatureCollection"===e.type)e.features.forEach(e=>g(e,t));else if("Feature"===e.type)g(e.geometry,t);else if("GeometryCollection"===e.type)e.geometries.forEach(e=>g(e,t));else{const n=e=>{Array.isArray(e)&&("number"==typeof e[0]?t.push(e):e.forEach(n))};n(e.coordinates)}},x=e=>{const t=[];g(e,t);const n=t.map(e=>e[0]),i=t.map(e=>e[1]);return y([Math.min(...n),Math.min(...i),Math.max(...n),Math.max(...i)])},f=e=>{const t=1609.344,n=e/t;if(n<.5/t){const t=Math.round(e);return`${t} ${1===t?"metre":"metres"}`}if(n<10){const e=Number.parseFloat(n.toFixed(1));return`${e} ${1===e?"mile":"miles"}`}const i=Math.round(n);return`${i} ${1===i?"mile":"miles"}`};const w={top:0,right:0,bottom:0,left:0};class M extends c{constructor({mapProviderConfig:e={},events:t,eventBus:n}){super(),this.events=t,this.eventBus=n,this.capabilities={supportedShortcuts:u,supportsMapSizes:!1},Object.assign(this,e),this.mapEventHandles=[],this.appEventHandles=[]}get name(){return"EsriProvider"}async initMap(a){const{container:s,padding:r,mapStyle:m,mapSize:l,maxExtent:c}=a;this.mapStyleId=m?.id,this.mapSize=l;const{events:p,eventBus:u}=this;this.setupConfig&&await this.setupConfig(e);const h=new o({id:"baselayer",url:m.url,visible:!0}),g=new n({layers:[h]}),x=c?y(c):null,f=new i({spatialReference:27700,container:s,map:g,zoom:a.zoom,center:v(a.center),maxExtent:c,constraints:{lods:t.create({spatialReference:{wkid:27700}}).lods,snapToZoom:!1,minZoom:a.minZoom,maxZoom:a.maxZoom,maxScale:0,geometry:x,rotationEnabled:!1},ui:{components:[]},popupEnabled:!1});(e=>{if(!e)return;const t=e.querySelector(".esri-view-surface");t.removeAttribute("role"),t.tabIndex=-1,t.style["outline-color"]="transparent",t.style.touchAction="none"})(f.container),f.padding=r,a.bounds&&f.when(()=>f.goTo(y(a.bounds),{duration:0})),this.mapEventHandles=d({mapProvider:this,view:f,baseTileLayer:h,events:p,eventBus:u,getZoom:this.getZoom.bind(this),getCenter:this.getCenter.bind(this),getBounds:this.getBounds.bind(this),getResolution:this.getResolution.bind(this)}),this.appEventHandles=function({baseTileLayer:e,events:t,eventBus:n}){const i=i=>{e.loadStyle(i.url).then(()=>{n.emit(t.MAP_STYLE_CHANGE,{mapStyleId:i.id})})};return n.on(t.MAP_SET_STYLE,i),{remove(){n.off(t.MAP_SET_STYLE,i)}}}({baseTileLayer:h,events:p,eventBus:u})||[],this.map=g,this.view=f,this.baseTileLayer=h}_isBaseMapReady=!1;setBaseMapReady(e){this._isBaseMapReady=e}isBaseMapReady(){return this._isBaseMapReady}destroyMap(){this.mapEvents?.remove(),this.appEvents?.remove(),this.mapEvents=null,this.appEvents=null,this.view&&(this.view.container=null,this.view.destroy(),this.view=null),this.map&&(this.map.removeAll(),this.map=null)}setView({center:e,zoom:t}){this.view.animation?.destroy();const n={center:e?new a({x:e[0],y:e[1],spatialReference:{wkid:27700}}):this.view.center,zoom:t??this.view.zoom};this.view.goTo({...n,duration:p.animationDuration})}zoomIn(e){this.view.animation?.destroy(),this.view.goTo({zoom:this.view.zoom+e,duration:p.animationDuration})}zoomOut(e){this.view.animation?.destroy(),this.view.goTo({zoom:this.view.zoom-e,duration:p.animationDuration})}panBy(e){const{x:t,y:n}=this.view.toScreen(this.view.center),i={x:t+e[0],y:n+e[1]},o=this.view.toMap(i);this.view.goTo({center:o,duration:p.animationDuration})}fitToBounds(e){const t=Array.isArray(e)?y(e):x(e);this.view.goTo(t,{duration:p.DELAY})}setPadding(e){this.view.padding=e}getCenter(){const e=this.view.center;return[e.x,e.y].map(e=>Math.round(100*e)/100)}getZoom(){return this.view.zoom}getBounds(){const{xmin:e,ymin:t,xmax:n,ymax:i}=this.view.extent;return[e,t,n,i].map(e=>Math.round(100*e)/100)}getFeaturesAtPoint(e,t){return async function(e,t){if(!e||!t)return[];const n=e.map.layers.filter(e=>e instanceof o);return n.length?(await e.hitTest(t,{include:n.toArray()})).results.map(e=>({layerId:e.layer.id,layerTitle:e.layer.title||e.layer.id,type:e.layer.type,geometry:e.graphic.geometry,symbol:e.graphic.symbol})):[]}(this.view,e)}getVisibleFeatures(e){return[]}getAreaDimensions(){return(e=>{if(!(e&&e instanceof l))return"";const t=e.xmin,n=e.ymin,i=e.xmax,o=e.ymax-n,a=f(i-t);return`${f(o)} by ${a}`})(((e,t=w)=>{if(!e.container)return null;const{width:n,height:i}=e.container.getBoundingClientRect(),o={x:t.left,y:i-t.bottom},a={x:n-t.right,y:t.top},s=e.toMap(o),r=e.toMap(a);return new l({xmin:s.x,ymin:s.y,xmax:r.x,ymax:r.y,spatialReference:s.spatialReference})})(this.view))}getCardinalMove(e,t){return function(e,t){const[n,i]=e,[o,a]=t,s=o-n,r=a-i,m=[];return Math.abs(r)>.1&&m.push(`${r>0?"north":"south"} ${f(Math.abs(r))}`),Math.abs(s)>.1&&m.push(`${s>0?"east":"west"} ${f(Math.abs(s))}`),m.join(", ")}(e,t)}getResolution(){return this.view.resolution}mapToScreen(e){const t=v(e),n=this.view.toScreen(t);return{x:n.x,y:n.y}}screenToMap(e){const t=this.view.toMap(e);return[t.x,t.y]}isGeometryObscured(e,t){return((e,t,n)=>{if(!n?.container)return!1;const i=n.container.getBoundingClientRect(),o=x(e),s=[n.toScreen(new a({x:o.xmin,y:o.ymin,spatialReference:o.spatialReference})),n.toScreen(new a({x:o.xmin,y:o.ymax,spatialReference:o.spatialReference})),n.toScreen(new a({x:o.xmax,y:o.ymin,spatialReference:o.spatialReference})),n.toScreen(new a({x:o.xmax,y:o.ymax,spatialReference:o.spatialReference}))],r=Math.min(...s.map(e=>e.x)),m=Math.max(...s.map(e=>e.x)),l=Math.min(...s.map(e=>e.y)),c=Math.max(...s.map(e=>e.y)),p=t.left-i.left,u=t.top-i.top,h=t.right-i.left,d=t.bottom-i.top;return r<h&&m>p&&l<d&&c>u})(e,t,this.view)}}export{M as default};
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/asyncToGenerator";function t(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function o(r){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?t(Object(n),!0).forEach(function(t){e(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))})}return r}var n=document.documentMode,i="Internet Explorer is not supported",p={isSupported:!!Array.prototype.findLast},a=(e=>{if(!window.WebGLRenderingContext)return{isEnabled:!1,error:"WebGL is not supported"};var r=document.createElement("canvas"),t=!1;for(var o of e)try{if((t=r.getContext(o))&&"function"==typeof t.getParameter)return{isEnabled:!0}}catch(e){}return{isEnabled:!1,error:"WebGL is supported, but disabled"}})(["webgl2","webgl1"]);function c(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{checkDeviceCapabilities:()=>({isSupported:p.isSupported&&a.isEnabled&&!n,error:i}),load:(e=r(function*(){var e=o(o({},t),{},{crs:"EPSG:27700"});try{return{MapProvider:(yield import(/* webpackChunkName: "im-esri-provider" */ "./im-esri-provider.js")).default,mapProviderConfig:e}}catch(e){throw console.error("Failed to load map provider",e),e}}),function(){return e.apply(this,arguments)})}}export{c as default};
1
+ import r from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/regenerator";function n(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})),t.push.apply(t,n)}return t}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach(function(t){r(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function i(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return a(r,e);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(r,e):void 0}}(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,o=function(){};return{s:o,n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,c=!1;return{s:function(){t=t.call(r)},n:function(){var r=t.next();return u=r.done,r},e:function(r){c=!0,i=r},f:function(){try{u||null==t.return||t.return()}finally{if(c)throw i}}}}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}var u=document.documentMode,c="Internet Explorer is not supported",p={isSupported:!!Array.prototype.findLast},l=function(r){if(!window.WebGLRenderingContext)return{isEnabled:!1,error:"WebGL is not supported"};var e,t=document.createElement("canvas"),n=!1,o=i(r);try{for(o.s();!(e=o.n()).done;){var a=e.value;try{if((n=t.getContext(a))&&"function"==typeof n.getParameter)return{isEnabled:!0}}catch(r){}}}catch(r){o.e(r)}finally{o.f()}return{isEnabled:!1,error:"WebGL is supported, but disabled"}}(["webgl2","webgl1"]);function f(){var r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{checkDeviceCapabilities:function(){return{isSupported:p.isSupported&&l.isEnabled&&!u,error:c}},load:(r=e(t.mark(function r(){var e,i,a;return t.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return e=o(o({},n),{},{crs:"EPSG:27700"}),r.prev=1,r.next=2,import(/* webpackChunkName: "im-esri-provider" */ "./im-esri-provider.js");case 2:return i=r.sent.default,r.abrupt("return",{MapProvider:i,mapProviderConfig:e});case 3:throw r.prev=3,a=r.catch(1),console.error("Failed to load map provider",a),a;case 4:case"end":return r.stop()}},r,null,[[1,3]])})),function(){return r.apply(this,arguments)})}}export{f as default};
@@ -1 +1 @@
1
- import t from"@babel/runtime/helpers/asyncToGenerator";let e=" ";class r{static get separator(){return e}static set separator(t){e=t}static parse(t){if(!isNaN(parseFloat(t))&&isFinite(t))return Number(t);const e=String(t).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==e[e.length-1]&&e.splice(e.length-1),""==e)return NaN;let r=null;switch(e.length){case 3:r=e[0]/1+e[1]/60+e[2]/3600;break;case 2:r=e[0]/1+e[1]/60;break;case 1:r=e[0];break;default:return NaN}return/^-|[WS]$/i.test(t.trim())&&(r=-r),Number(r)}static toDms(t,e="d",i=void 0){if(isNaN(t))return null;if("string"==typeof t&&""==t.trim())return null;if("boolean"==typeof t)return null;if(t==1/0)return null;if(null==t)return null;if(void 0===i)switch(e){case"d":case"deg":i=4;break;case"dm":case"deg+min":i=2;break;case"dms":case"deg+min+sec":i=0;break;default:e="d",i=4}t=Math.abs(t);let a=null,o=null,n=null,s=null;switch(e){default:case"d":case"deg":o=t.toFixed(i),o<100&&(o="0"+o),o<10&&(o="0"+o),a=o+"°";break;case"dm":case"deg+min":o=Math.floor(t),n=(60*t%60).toFixed(i),60==n&&(n=(0).toFixed(i),o++),o=("000"+o).slice(-3),n<10&&(n="0"+n),a=o+"°"+r.separator+n+"′";break;case"dms":case"deg+min+sec":o=Math.floor(t),n=Math.floor(3600*t/60)%60,s=(3600*t%60).toFixed(i),60==s&&(s=(0).toFixed(i),n++),60==n&&(n=0,o++),o=("000"+o).slice(-3),n=("00"+n).slice(-2),s<10&&(s="0"+s),a=o+"°"+r.separator+n+"′"+r.separator+s+"″"}return a}static toLat(t,e,i){const a=r.toDms(r.wrap90(t),e,i);return null===a?"–":a.slice(1)+r.separator+(t<0?"S":"N")}static toLon(t,e,i){const a=r.toDms(r.wrap180(t),e,i);return null===a?"–":a+r.separator+(t<0?"W":"E")}static toBrng(t,e,i){const a=r.toDms(r.wrap360(t),e,i);return null===a?"–":a.replace("360","0")}static fromLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(r.thousands,"⁜").replace(r.decimal,".").replace("⁜",",")}static toLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(/,([0-9])/,"⁜$1").replace(".",r.decimal).replace("⁜",r.thousands)}static compassPoint(t,e=3){if(![1,2,3].includes(Number(e)))throw new RangeError(`invalid precision ‘${e}’`);t=r.wrap360(t);const i=4*2**(e-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(t*i/360)%i*16/i]}static wrap90(t){if(-90<=t&&t<=90)return t;const e=t,r=360;return 1*Math.abs(((e-90)%r+r)%r-180)-90}static wrap180(t){if(-180<=t&&t<=180)return t;const e=360;return((360*t/e-180)%e+e)%e-180}static wrap360(t){if(0<=t&&t<360)return t;const e=360;return(360*t/e%e+e)%e}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};class i{constructor(t,e,r){if(isNaN(t)||isNaN(e)||isNaN(r))throw new TypeError(`invalid vector [${t},${e},${r}]`);this.x=Number(t),this.y=Number(e),this.z=Number(r)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}plus(t){if(!(t instanceof i))throw new TypeError("v is not Vector3d object");return new i(this.x+t.x,this.y+t.y,this.z+t.z)}minus(t){if(!(t instanceof i))throw new TypeError("v is not Vector3d object");return new i(this.x-t.x,this.y-t.y,this.z-t.z)}times(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new i(this.x*t,this.y*t,this.z*t)}dividedBy(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new i(this.x/t,this.y/t,this.z/t)}dot(t){if(!(t instanceof i))throw new TypeError("v is not Vector3d object");return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){if(!(t instanceof i))throw new TypeError("v is not Vector3d object");const e=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,a=this.x*t.y-this.y*t.x;return new i(e,r,a)}negate(){return new i(-this.x,-this.y,-this.z)}unit(){const t=this.length;if(1==t)return this;if(0==t)return this;const e=this.x/t,r=this.y/t,a=this.z/t;return new i(e,r,a)}angleTo(t,e=void 0){if(!(t instanceof i))throw new TypeError("v is not Vector3d object");if(!(e instanceof i||null==e))throw new TypeError("n is not Vector3d object");const r=null==e||this.cross(t).dot(e)>=0?1:-1,a=this.cross(t).length*r,o=this.dot(t);return Math.atan2(a,o)}rotateAround(t,e){if(!(t instanceof i))throw new TypeError("axis is not Vector3d object");const r=e.toRadians(),a=this.unit(),o=t.unit(),n=Math.sin(r),s=Math.cos(r),l=1-s,c=o.x,h=o.y,u=o.z,d=[[l*c*c+s,l*c*h-n*u,l*c*u+n*h],[l*c*h+n*u,l*h*h+s,l*h*u-n*c],[l*c*u-n*h,l*h*u+n*c,l*u*u+s]],p=[d[0][0]*a.x+d[0][1]*a.y+d[0][2]*a.z,d[1][0]*a.x+d[1][1]*a.y+d[1][2]*a.z,d[2][0]*a.x+d[2][1]*a.y+d[2][2]*a.z];return new i(p[0],p[1],p[2])}toString(t=3){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const a={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},o={WGS84:{ellipsoid:a.WGS84}};Object.freeze(a.WGS84),Object.freeze(o.WGS84);class n{constructor(t,e,i=0){if(isNaN(t)||null==t)throw new TypeError(`invalid lat ‘${t}’`);if(isNaN(e)||null==e)throw new TypeError(`invalid lon ‘${e}’`);if(isNaN(i)||null==i)throw new TypeError(`invalid height ‘${i}’`);this._lat=r.wrap90(Number(t)),this._lon=r.wrap180(Number(e)),this._height=Number(i)}get lat(){return this._lat}get latitude(){return this._lat}set lat(t){if(this._lat=isNaN(t)?r.wrap90(r.parse(t)):r.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${t}’`)}set latitude(t){if(this._lat=isNaN(t)?r.wrap90(r.parse(t)):r.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${t}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(t){if(this._lon=isNaN(t)?r.wrap180(r.parse(t)):r.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${t}’`)}set lng(t){if(this._lon=isNaN(t)?r.wrap180(r.parse(t)):r.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${t}’`)}set longitude(t){if(this._lon=isNaN(t)?r.wrap180(r.parse(t)):r.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${t}’`)}get height(){return this._height}set height(t){if(this._height=Number(t),isNaN(this._height))throw new TypeError(`invalid height ‘${t}’`)}get datum(){return this._datum}set datum(t){this._datum=t}static get ellipsoids(){return a}static get datums(){return o}static parse(...t){if(0==t.length)throw new TypeError("invalid (empty) point");let e,i,a;if("object"==typeof t[0]&&(1==t.length||!isNaN(parseFloat(t[1])))){const o=t[0];if("Point"==o.type&&Array.isArray(o.coordinates)?([i,e,a]=o.coordinates,a=a||0):(null!=o.latitude&&(e=o.latitude),null!=o.lat&&(e=o.lat),null!=o.longitude&&(i=o.longitude),null!=o.lng&&(i=o.lng),null!=o.lon&&(i=o.lon),null!=o.height&&(a=o.height),e=r.wrap90(r.parse(e)),i=r.wrap180(r.parse(i))),null!=t[1]&&(a=t[1]),isNaN(e)||isNaN(i))throw new TypeError(`invalid point ‘${JSON.stringify(t[0])}’`)}if("string"==typeof t[0]&&2==t[0].split(",").length&&([e,i]=t[0].split(","),e=r.wrap90(r.parse(e)),i=r.wrap180(r.parse(i)),a=t[1]||0,isNaN(e)||isNaN(i)))throw new TypeError(`invalid point ‘${t[0]}’`);if(null==e&&null==i&&([e,i]=t,e=r.wrap90(r.parse(e)),i=r.wrap180(r.parse(i)),a=t[2]||0,isNaN(e)||isNaN(i)))throw new TypeError(`invalid point ‘${t.toString()}’`);return new this(e,i,a)}toCartesian(){const t=this.datum?this.datum.ellipsoid:this.referenceFrame?this.referenceFrame.ellipsoid:a.WGS84,e=this.lat.toRadians(),r=this.lon.toRadians(),i=this.height,{a:o,f:n}=t,l=Math.sin(e),c=Math.cos(e),h=Math.sin(r),u=Math.cos(r),d=2*n-n*n,p=o/Math.sqrt(1-d*l*l);return new s((p+i)*c*u,(p+i)*c*h,(p*(1-d)+i)*l)}equals(t){if(!(t instanceof n))throw new TypeError(`invalid point ‘${t}’`);return!(Math.abs(this.lat-t.lat)>Number.EPSILON)&&(!(Math.abs(this.lon-t.lon)>Number.EPSILON)&&(!(Math.abs(this.height-t.height)>Number.EPSILON)&&(this.datum==t.datum&&(this.referenceFrame==t.referenceFrame&&this.epoch==t.epoch))))}toString(t="d",e=void 0,i=null){if(!["d","dm","dms","n"].includes(t))throw new RangeError(`invalid format ‘${t}’`);const a=(this.height>=0?" +":" ")+this.height.toFixed(i)+"m";if("n"==t){null==e&&(e=4);return`${this.lat.toFixed(e)}, ${this.lon.toFixed(e)}${null==i?"":a}`}return`${r.toLat(this.lat,t,e)}, ${r.toLon(this.lon,t,e)}${null==i?"":a}`}}class s extends i{constructor(t,e,r){super(t,e,r)}toLatLon(t=a.WGS84){if(!t||!t.a)throw new TypeError(`invalid ellipsoid ‘${t}’`);const{x:e,y:r,z:i}=this,{a:o,b:s,f:l}=t,c=2*l-l*l,h=c/(1-c),u=Math.sqrt(e*e+r*r),d=s*i/(o*u)*(1+h*s/Math.sqrt(u*u+i*i)),p=d/Math.sqrt(1+d*d),m=p/d,f=isNaN(m)?0:Math.atan2(i+h*s*p*p*p,u-c*o*m*m*m),g=Math.atan2(r,e),y=Math.sin(f),w=u*Math.cos(f)+i*y-o*o/(o/Math.sqrt(1-c*y*y));return new n(f.toDegrees(),g.toDegrees(),w)}toString(t=0){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}const l={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563},Airy1830:{a:6377563.396,b:6356256.909,f:1/299.3249646},AiryModified:{a:6377340.189,b:6356034.448,f:1/299.3249646},Bessel1841:{a:6377397.155,b:6356078.962818,f:1/299.1528128},Clarke1866:{a:6378206.4,b:6356583.8,f:1/294.978698214},Clarke1880IGN:{a:6378249.2,b:6356515,f:1/293.466021294},GRS80:{a:6378137,b:6356752.31414,f:1/298.257222101},Intl1924:{a:6378388,b:6356911.946,f:1/297},WGS72:{a:6378135,b:6356750.5,f:1/298.26}},c={ED50:{ellipsoid:l.Intl1924,transform:[89.5,93.8,123.1,-1.2,0,0,.156]},ETRS89:{ellipsoid:l.GRS80,transform:[0,0,0,0,0,0,0]},Irl1975:{ellipsoid:l.AiryModified,transform:[-482.53,130.596,-564.557,-8.15,1.042,.214,.631]},NAD27:{ellipsoid:l.Clarke1866,transform:[8,-160,-176,0,0,0,0]},NAD83:{ellipsoid:l.GRS80,transform:[.9956,-1.9103,-.5215,-62e-5,.025915,.009426,.011599]},NTF:{ellipsoid:l.Clarke1880IGN,transform:[168,60,-320,0,0,0,0]},OSGB36:{ellipsoid:l.Airy1830,transform:[-446.448,125.157,-542.06,20.4894,-.1502,-.247,-.8421]},Potsdam:{ellipsoid:l.Bessel1841,transform:[-582,-105,-414,-8.3,1.04,.35,-3.08]},TokyoJapan:{ellipsoid:l.Bessel1841,transform:[148,-507,-685,0,0,0,0]},WGS72:{ellipsoid:l.WGS72,transform:[0,0,-4.5,-.22,0,0,.554]},WGS84:{ellipsoid:l.WGS84,transform:[0,0,0,0,0,0,0]}};Object.keys(l).forEach(t=>Object.freeze(l[t])),Object.keys(c).forEach(t=>{Object.freeze(c[t]),Object.freeze(c[t].transform)});class h extends n{constructor(t,e,r=0,i=c.WGS84){if(!i||null==i.ellipsoid)throw new TypeError(`unrecognised datum ‘${i}’`);super(t,e,r),this._datum=i}get datum(){return this._datum}static get ellipsoids(){return l}static get datums(){return c}static parse(...t){let e=c.WGS84;if((4==t.length||3==t.length&&"object"==typeof t[2])&&(e=t.pop()),!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.parse(...t);return r._datum=e,r}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);return this.toCartesian().convertDatum(t).toLatLon()}toCartesian(){const t=super.toCartesian();return new u(t.x,t.y,t.z,this.datum)}}class u extends s{constructor(t,e,r,i=void 0){if(i&&null==i.ellipsoid)throw new TypeError(`unrecognised datum ‘${i}’`);super(t,e,r),i&&(this._datum=i)}get datum(){return this._datum}set datum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);this._datum=t}toLatLon(t=void 0){t&&(console.info("datum parameter to Cartesian_Datum.toLatLon is deprecated: set datum before calling toLatLon()"),this.datum=t);const e=this.datum||c.WGS84;if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.toLatLon(e.ellipsoid);return new h(r.lat,r.lon,r.height,this.datum)}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);if(!this.datum)throw new TypeError("cartesian coordinate has no datum");let e=null,r=null;null!=this.datum&&this.datum!=c.WGS84||(e=this,r=t.transform),t==c.WGS84&&(e=this,r=this.datum.transform.map(t=>-t)),null==r&&(e=this.convertDatum(c.WGS84),r=t.transform);const i=e.applyTransform(r);return i.datum=t,i}applyTransform(t){const{x:e,y:r,z:i}=this,a=t[0],o=t[1],n=t[2],s=t[3]/1e6+1,l=(t[4]/3600).toRadians(),c=(t[5]/3600).toRadians(),h=(t[6]/3600).toRadians();return new u(a+e*s-r*h+i*c,o+e*h+r*s-i*l,n-e*c+r*l+i*s)}}const d={trueOrigin:{lat:49,lon:-2},scaleFactor:.9996012717,ellipsoid:h.ellipsoids.Airy1830};class p{constructor(t,e){if(this.easting=Number(t),this.northing=Number(e),isNaN(t)||this.easting<0||this.easting>7e5)throw new RangeError(`invalid easting ‘${t}’`);if(isNaN(e)||this.northing<0||this.northing>13e5)throw new RangeError(`invalid northing ‘${e}’`)}toLatLon(t=h.datums.WGS84){const{easting:e,northing:r}=this,{a:i,b:a}=d.ellipsoid,o=d.trueOrigin.lat.toRadians(),n=d.trueOrigin.lon.toRadians(),s=-1e5,l=d.scaleFactor,c=1-a*a/(i*i),u=(i-a)/(i+a),p=u*u,f=u*u*u;let g=o,y=0;do{g=(r-s-y)/(i*l)+g;y=a*l*((1+u+5/4*p+5/4*f)*(g-o)-(3*u+3*u*u+21/8*f)*Math.sin(g-o)*Math.cos(g+o)+(15/8*p+15/8*f)*Math.sin(2*(g-o))*Math.cos(2*(g+o))-35/24*f*Math.sin(3*(g-o))*Math.cos(3*(g+o)))}while(Math.abs(r-s-y)>=1e-5);const w=Math.cos(g),N=Math.sin(g),_=i*l/Math.sqrt(1-c*N*N),E=i*l*(1-c)/Math.pow(1-c*N*N,1.5),b=_/E-1,S=Math.tan(g),M=S*S,v=M*M,$=1/w,T=_*_*_,x=T*_*_,G=e-4e5,R=G*G,W=R*G,F=R*R,O=W*R;g=g-S/(2*E*_)*R+S/(24*E*T)*(5+3*M+b-9*M*b)*F-S/(720*E*x)*(61+90*M+45*v)*(F*R);const L=n+$/_*G-$/(6*T)*(_/E+2*M)*W+$/(120*x)*(5+28*M+24*v)*O-$/(5040*(x*_*_))*(61+662*M+1320*v+720*(v*M))*(O*R);let z=new m(g.toDegrees(),L.toDegrees(),0,h.datums.OSGB36);return t!=h.datums.OSGB36&&(z=z.convertDatum(t),z=new m(z.lat,z.lon,z.height,z.datum)),z}static parse(t){let e=(t=String(t).trim()).match(/^(\d+),\s*(\d+)$/);if(e)return new p(e[1],e[2]);if(e=t.match(/^[HNST][ABCDEFGHJKLMNOPQRSTUVWXYZ]\s*[0-9]+\s*[0-9]+$/i),!e)throw new Error(`invalid grid reference ‘${t}’`);let r=t.toUpperCase().charCodeAt(0)-"A".charCodeAt(0),i=t.toUpperCase().charCodeAt(1)-"A".charCodeAt(0);r>7&&r--,i>7&&i--;const a=(r-2)%5*5+i%5,o=19-5*Math.floor(r/5)-Math.floor(i/5);let n=t.slice(2).trim().split(/\s+/);if(1==n.length&&(n=[n[0].slice(0,n[0].length/2),n[0].slice(n[0].length/2)]),n[0].length!=n[1].length)throw new Error(`invalid grid reference ‘${t}’`);n[0]=n[0].padEnd(5,"0"),n[1]=n[1].padEnd(5,"0");const s=a+n[0],l=o+n[1];return new p(s,l)}toString(t=10){if(![0,2,4,6,8,10,12,14,16].includes(Number(t)))throw new RangeError(`invalid precision ‘${t}’`);let{easting:e,northing:r}=this;if(0==t){const t={useGrouping:!1,minimumIntegerDigits:6,maximumFractionDigits:3};return`${e.toLocaleString("en",t)},${r.toLocaleString("en",t)}`}const i=Math.floor(e/1e5),a=Math.floor(r/1e5);let o=19-a-(19-a)%5+Math.floor((i+10)/5),n=5*(19-a)%25+i%5;o>7&&o++,n>7&&n++;const s=String.fromCharCode(o+"A".charCodeAt(0),n+"A".charCodeAt(0));return e=Math.floor(e%1e5/Math.pow(10,5-t/2)),r=Math.floor(r%1e5/Math.pow(10,5-t/2)),e=e.toString().padStart(t/2,"0"),r=r.toString().padStart(t/2,"0"),`${s} ${e} ${r}`}}class m extends h{toOsGrid(){const t=this.datum==h.datums.OSGB36?this:this.convertDatum(h.datums.OSGB36),e=t.lat.toRadians(),r=t.lon.toRadians(),{a:i,b:a}=d.ellipsoid,o=d.trueOrigin.lat.toRadians(),n=d.trueOrigin.lon.toRadians(),s=d.scaleFactor,l=1-a*a/(i*i),c=(i-a)/(i+a),u=c*c,m=c*c*c,f=Math.cos(e),g=Math.sin(e),y=i*s/Math.sqrt(1-l*g*g),w=i*s*(1-l)/Math.pow(1-l*g*g,1.5),N=y/w-1,_=a*s*((1+c+5/4*u+5/4*m)*(e-o)-(3*c+3*c*c+21/8*m)*Math.sin(e-o)*Math.cos(e+o)+(15/8*u+15/8*m)*Math.sin(2*(e-o))*Math.cos(2*(e+o))-35/24*m*Math.sin(3*(e-o))*Math.cos(3*(e+o))),E=f*f*f,b=E*f*f,S=Math.tan(e)*Math.tan(e),M=S*S,v=r-n,$=v*v,T=$*v,x=T*v,G=x*v;let R=_+-1e5+y/2*g*f*$+y/24*g*E*(5-S+9*N)*x+y/720*g*b*(61-58*S+M)*(G*v),W=4e5+y*f*v+y/6*E*(y/w-S)*T+y/120*b*(5-18*S+M+14*N-58*S*N)*G;R=Number(R.toFixed(3)),W=Number(W.toFixed(3));try{return new p(W,R)}catch(e){throw new Error(`${e.message} from (${t.lat.toFixed(6)},${t.lon.toFixed(6)}).toOsGrid()`)}}convertDatum(t){const e=super.convertDatum(t);return new m(e.lat,e.lon,e.height,e.datum)}}var f=function(){var e=t(function*(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://api.os.uk/search/names/v1/nearest?point={easting},{northing}&radius=1000&fq=local_type:Airfield%20local_type:Airport%20local_type:Bus_Station%20local_type:Chemical_Works%20local_type:City%20local_type:Coach_Station%20local_type:Electricity_Distribution%20local_type:Electricity_Production%20local_type:Further_Education%20local_type:Gas_Distribution_or_Storage%20local_type:Hamlet%20local_type:Harbour%20local_type:Helicopter_Station%20local_type:Heliport%20local_type:Higher_or_University_Education%20local_type:Hill_Or_Mountain%20local_type:Hospice%20local_type:Hospital%20local_type:Medical_Care_Accommodation%20local_type:Named_Road%20local_type:Non_State_Primary_Education%20local_type:Non_State_Secondary_Education%20local_type:Other_Settlement%20local_type:Passenger_Ferry_Terminal%20local_type:Port_Consisting_of_Docks_and_Nautical_Berthing%20local_type:Postcode%20local_type:Primary_Education%20local_type:Railway_Station%20local_type:Road_User_Services%20local_type:Secondary_Education%20local_type:Section_Of_Named_Road%20local_type:Section_Of_Numbered_Road%20local_type:Special_Needs_Education%20local_type:Suburban_Area%20local_type:Town%20local_type:Urban_Greenspace%20local_type:Vehicular_Ferry_Terminal%20local_type:Vehicular_Rail_Terminal%20local_type:Village%20local_type:Waterfall%20",e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,i=arguments.length>4?arguments[4]:void 0,a=i;if("EPSG:4326"===r)try{a=[(a=new m(i[1],i[0]).toOsGrid()).easting,a.northing].map(t=>Math.round(t))}catch(t){return console.log(t),null}t=t.replace("{easting}",Math.round(a[0])).replace("{northing}",Math.round(a[1]));var o=new Request(t,{method:"GET"});if(e)try{o=yield e(o)}catch(t){return console.log("Error transforming request:",t),null}var n=yield fetch(o),s=yield n.json(),l=function(t){var{ID:e,NAME1:r,POPULATED_PLACE:i,COUNTY_UNITARY:a,REGION:o,GEOMETRY_X:n,GEOMETRY_Y:s}=t;return{id:e||"",place:"".concat(r).concat(i?", "+i:"").concat(a?", "+a:"",", ").concat(o),county:a||"",coordinates:[n,s]}}(s.results[0].GAZETTEER_ENTRY);if("EPSG:4326"===r){var c=new p(l.coordinates[0],l.coordinates[1]).toLatLon();l.coordinates=[c.lat,c.lon]}var h="Approximate centre ".concat(null==l?void 0:l.place);return s.results?h:null});return function(){return e.apply(this,arguments)}}();export{f as reverseGeocode};
1
+ let t=" ";class e{static get separator(){return t}static set separator(e){t=e}static parse(t){if(!isNaN(parseFloat(t))&&isFinite(t))return Number(t);const e=String(t).trim().replace(/^-/,"").replace(/[NSEW]$/i,"").split(/[^0-9.,]+/);if(""==e[e.length-1]&&e.splice(e.length-1),""==e)return NaN;let r=null;switch(e.length){case 3:r=e[0]/1+e[1]/60+e[2]/3600;break;case 2:r=e[0]/1+e[1]/60;break;case 1:r=e[0];break;default:return NaN}return/^-|[WS]$/i.test(t.trim())&&(r=-r),Number(r)}static toDms(t,r="d",i=void 0){if(isNaN(t))return null;if("string"==typeof t&&""==t.trim())return null;if("boolean"==typeof t)return null;if(t==1/0)return null;if(null==t)return null;if(void 0===i)switch(r){case"d":case"deg":i=4;break;case"dm":case"deg+min":i=2;break;case"dms":case"deg+min+sec":i=0;break;default:r="d",i=4}t=Math.abs(t);let a=null,o=null,n=null,s=null;switch(r){default:case"d":case"deg":o=t.toFixed(i),o<100&&(o="0"+o),o<10&&(o="0"+o),a=o+"°";break;case"dm":case"deg+min":o=Math.floor(t),n=(60*t%60).toFixed(i),60==n&&(n=(0).toFixed(i),o++),o=("000"+o).slice(-3),n<10&&(n="0"+n),a=o+"°"+e.separator+n+"′";break;case"dms":case"deg+min+sec":o=Math.floor(t),n=Math.floor(3600*t/60)%60,s=(3600*t%60).toFixed(i),60==s&&(s=(0).toFixed(i),n++),60==n&&(n=0,o++),o=("000"+o).slice(-3),n=("00"+n).slice(-2),s<10&&(s="0"+s),a=o+"°"+e.separator+n+"′"+e.separator+s+"″"}return a}static toLat(t,r,i){const a=e.toDms(e.wrap90(t),r,i);return null===a?"–":a.slice(1)+e.separator+(t<0?"S":"N")}static toLon(t,r,i){const a=e.toDms(e.wrap180(t),r,i);return null===a?"–":a+e.separator+(t<0?"W":"E")}static toBrng(t,r,i){const a=e.toDms(e.wrap360(t),r,i);return null===a?"–":a.replace("360","0")}static fromLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(r.thousands,"⁜").replace(r.decimal,".").replace("⁜",",")}static toLocale(t){const e=123456.789.toLocaleString(),r={thousands:e.slice(3,4),decimal:e.slice(7,8)};return t.replace(/,([0-9])/,"⁜$1").replace(".",r.decimal).replace("⁜",r.thousands)}static compassPoint(t,r=3){if(![1,2,3].includes(Number(r)))throw new RangeError(`invalid precision ‘${r}’`);t=e.wrap360(t);const i=4*2**(r-1);return["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"][Math.round(t*i/360)%i*16/i]}static wrap90(t){if(-90<=t&&t<=90)return t;const e=t,r=360;return 1*Math.abs(((e-90)%r+r)%r-180)-90}static wrap180(t){if(-180<=t&&t<=180)return t;const e=360;return((360*t/e-180)%e+e)%e-180}static wrap360(t){if(0<=t&&t<360)return t;const e=360;return(360*t/e%e+e)%e}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};class r{constructor(t,e,r){if(isNaN(t)||isNaN(e)||isNaN(r))throw new TypeError(`invalid vector [${t},${e},${r}]`);this.x=Number(t),this.y=Number(e),this.z=Number(r)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}plus(t){if(!(t instanceof r))throw new TypeError("v is not Vector3d object");return new r(this.x+t.x,this.y+t.y,this.z+t.z)}minus(t){if(!(t instanceof r))throw new TypeError("v is not Vector3d object");return new r(this.x-t.x,this.y-t.y,this.z-t.z)}times(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new r(this.x*t,this.y*t,this.z*t)}dividedBy(t){if(isNaN(t))throw new TypeError(`invalid scalar value ‘${t}’`);return new r(this.x/t,this.y/t,this.z/t)}dot(t){if(!(t instanceof r))throw new TypeError("v is not Vector3d object");return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){if(!(t instanceof r))throw new TypeError("v is not Vector3d object");const e=this.y*t.z-this.z*t.y,i=this.z*t.x-this.x*t.z,a=this.x*t.y-this.y*t.x;return new r(e,i,a)}negate(){return new r(-this.x,-this.y,-this.z)}unit(){const t=this.length;if(1==t)return this;if(0==t)return this;const e=this.x/t,i=this.y/t,a=this.z/t;return new r(e,i,a)}angleTo(t,e=void 0){if(!(t instanceof r))throw new TypeError("v is not Vector3d object");if(!(e instanceof r||null==e))throw new TypeError("n is not Vector3d object");const i=null==e||this.cross(t).dot(e)>=0?1:-1,a=this.cross(t).length*i,o=this.dot(t);return Math.atan2(a,o)}rotateAround(t,e){if(!(t instanceof r))throw new TypeError("axis is not Vector3d object");const i=e.toRadians(),a=this.unit(),o=t.unit(),n=Math.sin(i),s=Math.cos(i),l=1-s,c=o.x,h=o.y,u=o.z,d=[[l*c*c+s,l*c*h-n*u,l*c*u+n*h],[l*c*h+n*u,l*h*h+s,l*h*u-n*c],[l*c*u-n*h,l*h*u+n*c,l*u*u+s]],p=[d[0][0]*a.x+d[0][1]*a.y+d[0][2]*a.z,d[1][0]*a.x+d[1][1]*a.y+d[1][2]*a.z,d[2][0]*a.x+d[2][1]*a.y+d[2][2]*a.z];return new r(p[0],p[1],p[2])}toString(t=3){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}Number.prototype.toRadians=function(){return this*Math.PI/180},Number.prototype.toDegrees=function(){return 180*this/Math.PI};const i={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563}},a={WGS84:{ellipsoid:i.WGS84}};Object.freeze(i.WGS84),Object.freeze(a.WGS84);class o{constructor(t,r,i=0){if(isNaN(t)||null==t)throw new TypeError(`invalid lat ‘${t}’`);if(isNaN(r)||null==r)throw new TypeError(`invalid lon ‘${r}’`);if(isNaN(i)||null==i)throw new TypeError(`invalid height ‘${i}’`);this._lat=e.wrap90(Number(t)),this._lon=e.wrap180(Number(r)),this._height=Number(i)}get lat(){return this._lat}get latitude(){return this._lat}set lat(t){if(this._lat=isNaN(t)?e.wrap90(e.parse(t)):e.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid lat ‘${t}’`)}set latitude(t){if(this._lat=isNaN(t)?e.wrap90(e.parse(t)):e.wrap90(Number(t)),isNaN(this._lat))throw new TypeError(`invalid latitude ‘${t}’`)}get lon(){return this._lon}get lng(){return this._lon}get longitude(){return this._lon}set lon(t){if(this._lon=isNaN(t)?e.wrap180(e.parse(t)):e.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lon ‘${t}’`)}set lng(t){if(this._lon=isNaN(t)?e.wrap180(e.parse(t)):e.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid lng ‘${t}’`)}set longitude(t){if(this._lon=isNaN(t)?e.wrap180(e.parse(t)):e.wrap180(Number(t)),isNaN(this._lon))throw new TypeError(`invalid longitude ‘${t}’`)}get height(){return this._height}set height(t){if(this._height=Number(t),isNaN(this._height))throw new TypeError(`invalid height ‘${t}’`)}get datum(){return this._datum}set datum(t){this._datum=t}static get ellipsoids(){return i}static get datums(){return a}static parse(...t){if(0==t.length)throw new TypeError("invalid (empty) point");let r,i,a;if("object"==typeof t[0]&&(1==t.length||!isNaN(parseFloat(t[1])))){const o=t[0];if("Point"==o.type&&Array.isArray(o.coordinates)?([i,r,a]=o.coordinates,a=a||0):(null!=o.latitude&&(r=o.latitude),null!=o.lat&&(r=o.lat),null!=o.longitude&&(i=o.longitude),null!=o.lng&&(i=o.lng),null!=o.lon&&(i=o.lon),null!=o.height&&(a=o.height),r=e.wrap90(e.parse(r)),i=e.wrap180(e.parse(i))),null!=t[1]&&(a=t[1]),isNaN(r)||isNaN(i))throw new TypeError(`invalid point ‘${JSON.stringify(t[0])}’`)}if("string"==typeof t[0]&&2==t[0].split(",").length&&([r,i]=t[0].split(","),r=e.wrap90(e.parse(r)),i=e.wrap180(e.parse(i)),a=t[1]||0,isNaN(r)||isNaN(i)))throw new TypeError(`invalid point ‘${t[0]}’`);if(null==r&&null==i&&([r,i]=t,r=e.wrap90(e.parse(r)),i=e.wrap180(e.parse(i)),a=t[2]||0,isNaN(r)||isNaN(i)))throw new TypeError(`invalid point ‘${t.toString()}’`);return new this(r,i,a)}toCartesian(){const t=this.datum?this.datum.ellipsoid:this.referenceFrame?this.referenceFrame.ellipsoid:i.WGS84,e=this.lat.toRadians(),r=this.lon.toRadians(),a=this.height,{a:o,f:s}=t,l=Math.sin(e),c=Math.cos(e),h=Math.sin(r),u=Math.cos(r),d=2*s-s*s,p=o/Math.sqrt(1-d*l*l);return new n((p+a)*c*u,(p+a)*c*h,(p*(1-d)+a)*l)}equals(t){if(!(t instanceof o))throw new TypeError(`invalid point ‘${t}’`);return!(Math.abs(this.lat-t.lat)>Number.EPSILON)&&(!(Math.abs(this.lon-t.lon)>Number.EPSILON)&&(!(Math.abs(this.height-t.height)>Number.EPSILON)&&(this.datum==t.datum&&(this.referenceFrame==t.referenceFrame&&this.epoch==t.epoch))))}toString(t="d",r=void 0,i=null){if(!["d","dm","dms","n"].includes(t))throw new RangeError(`invalid format ‘${t}’`);const a=(this.height>=0?" +":" ")+this.height.toFixed(i)+"m";if("n"==t){null==r&&(r=4);return`${this.lat.toFixed(r)}, ${this.lon.toFixed(r)}${null==i?"":a}`}return`${e.toLat(this.lat,t,r)}, ${e.toLon(this.lon,t,r)}${null==i?"":a}`}}class n extends r{constructor(t,e,r){super(t,e,r)}toLatLon(t=i.WGS84){if(!t||!t.a)throw new TypeError(`invalid ellipsoid ‘${t}’`);const{x:e,y:r,z:a}=this,{a:n,b:s,f:l}=t,c=2*l-l*l,h=c/(1-c),u=Math.sqrt(e*e+r*r),d=s*a/(n*u)*(1+h*s/Math.sqrt(u*u+a*a)),p=d/Math.sqrt(1+d*d),m=p/d,f=isNaN(m)?0:Math.atan2(a+h*s*p*p*p,u-c*n*m*m*m),g=Math.atan2(r,e),w=Math.sin(f),y=u*Math.cos(f)+a*w-n*n/(n/Math.sqrt(1-c*w*w));return new o(f.toDegrees(),g.toDegrees(),y)}toString(t=0){return`[${this.x.toFixed(t)},${this.y.toFixed(t)},${this.z.toFixed(t)}]`}}const s={WGS84:{a:6378137,b:6356752.314245,f:1/298.257223563},Airy1830:{a:6377563.396,b:6356256.909,f:1/299.3249646},AiryModified:{a:6377340.189,b:6356034.448,f:1/299.3249646},Bessel1841:{a:6377397.155,b:6356078.962818,f:1/299.1528128},Clarke1866:{a:6378206.4,b:6356583.8,f:1/294.978698214},Clarke1880IGN:{a:6378249.2,b:6356515,f:1/293.466021294},GRS80:{a:6378137,b:6356752.31414,f:1/298.257222101},Intl1924:{a:6378388,b:6356911.946,f:1/297},WGS72:{a:6378135,b:6356750.5,f:1/298.26}},l={ED50:{ellipsoid:s.Intl1924,transform:[89.5,93.8,123.1,-1.2,0,0,.156]},ETRS89:{ellipsoid:s.GRS80,transform:[0,0,0,0,0,0,0]},Irl1975:{ellipsoid:s.AiryModified,transform:[-482.53,130.596,-564.557,-8.15,1.042,.214,.631]},NAD27:{ellipsoid:s.Clarke1866,transform:[8,-160,-176,0,0,0,0]},NAD83:{ellipsoid:s.GRS80,transform:[.9956,-1.9103,-.5215,-62e-5,.025915,.009426,.011599]},NTF:{ellipsoid:s.Clarke1880IGN,transform:[168,60,-320,0,0,0,0]},OSGB36:{ellipsoid:s.Airy1830,transform:[-446.448,125.157,-542.06,20.4894,-.1502,-.247,-.8421]},Potsdam:{ellipsoid:s.Bessel1841,transform:[-582,-105,-414,-8.3,1.04,.35,-3.08]},TokyoJapan:{ellipsoid:s.Bessel1841,transform:[148,-507,-685,0,0,0,0]},WGS72:{ellipsoid:s.WGS72,transform:[0,0,-4.5,-.22,0,0,.554]},WGS84:{ellipsoid:s.WGS84,transform:[0,0,0,0,0,0,0]}};Object.keys(s).forEach(t=>Object.freeze(s[t])),Object.keys(l).forEach(t=>{Object.freeze(l[t]),Object.freeze(l[t].transform)});class c extends o{constructor(t,e,r=0,i=l.WGS84){if(!i||null==i.ellipsoid)throw new TypeError(`unrecognised datum ‘${i}’`);super(t,e,r),this._datum=i}get datum(){return this._datum}static get ellipsoids(){return s}static get datums(){return l}static parse(...t){let e=l.WGS84;if((4==t.length||3==t.length&&"object"==typeof t[2])&&(e=t.pop()),!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.parse(...t);return r._datum=e,r}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);return this.toCartesian().convertDatum(t).toLatLon()}toCartesian(){const t=super.toCartesian();return new h(t.x,t.y,t.z,this.datum)}}class h extends n{constructor(t,e,r,i=void 0){if(i&&null==i.ellipsoid)throw new TypeError(`unrecognised datum ‘${i}’`);super(t,e,r),i&&(this._datum=i)}get datum(){return this._datum}set datum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);this._datum=t}toLatLon(t=void 0){t&&(console.info("datum parameter to Cartesian_Datum.toLatLon is deprecated: set datum before calling toLatLon()"),this.datum=t);const e=this.datum||l.WGS84;if(!e||null==e.ellipsoid)throw new TypeError(`unrecognised datum ‘${e}’`);const r=super.toLatLon(e.ellipsoid);return new c(r.lat,r.lon,r.height,this.datum)}convertDatum(t){if(!t||null==t.ellipsoid)throw new TypeError(`unrecognised datum ‘${t}’`);if(!this.datum)throw new TypeError("cartesian coordinate has no datum");let e=null,r=null;null!=this.datum&&this.datum!=l.WGS84||(e=this,r=t.transform),t==l.WGS84&&(e=this,r=this.datum.transform.map(t=>-t)),null==r&&(e=this.convertDatum(l.WGS84),r=t.transform);const i=e.applyTransform(r);return i.datum=t,i}applyTransform(t){const{x:e,y:r,z:i}=this,a=t[0],o=t[1],n=t[2],s=t[3]/1e6+1,l=(t[4]/3600).toRadians(),c=(t[5]/3600).toRadians(),u=(t[6]/3600).toRadians();return new h(a+e*s-r*u+i*c,o+e*u+r*s-i*l,n-e*c+r*l+i*s)}}const u={trueOrigin:{lat:49,lon:-2},scaleFactor:.9996012717,ellipsoid:c.ellipsoids.Airy1830};class d{constructor(t,e){if(this.easting=Number(t),this.northing=Number(e),isNaN(t)||this.easting<0||this.easting>7e5)throw new RangeError(`invalid easting ‘${t}’`);if(isNaN(e)||this.northing<0||this.northing>13e5)throw new RangeError(`invalid northing ‘${e}’`)}toLatLon(t=c.datums.WGS84){const{easting:e,northing:r}=this,{a:i,b:a}=u.ellipsoid,o=u.trueOrigin.lat.toRadians(),n=u.trueOrigin.lon.toRadians(),s=-1e5,l=u.scaleFactor,h=1-a*a/(i*i),d=(i-a)/(i+a),m=d*d,f=d*d*d;let g=o,w=0;do{g=(r-s-w)/(i*l)+g;w=a*l*((1+d+5/4*m+5/4*f)*(g-o)-(3*d+3*d*d+21/8*f)*Math.sin(g-o)*Math.cos(g+o)+(15/8*m+15/8*f)*Math.sin(2*(g-o))*Math.cos(2*(g+o))-35/24*f*Math.sin(3*(g-o))*Math.cos(3*(g+o)))}while(Math.abs(r-s-w)>=1e-5);const y=Math.cos(g),N=Math.sin(g),_=i*l/Math.sqrt(1-h*N*N),E=i*l*(1-h)/Math.pow(1-h*N*N,1.5),S=_/E-1,b=Math.tan(g),M=b*b,$=M*M,T=1/y,x=_*_*_,v=x*_*_,G=e-4e5,R=G*G,W=R*G,F=R*R,O=W*R;g=g-b/(2*E*_)*R+b/(24*E*x)*(5+3*M+S-9*M*S)*F-b/(720*E*v)*(61+90*M+45*$)*(F*R);const L=n+T/_*G-T/(6*x)*(_/E+2*M)*W+T/(120*v)*(5+28*M+24*$)*O-T/(5040*(v*_*_))*(61+662*M+1320*$+720*($*M))*(O*R);let z=new p(g.toDegrees(),L.toDegrees(),0,c.datums.OSGB36);return t!=c.datums.OSGB36&&(z=z.convertDatum(t),z=new p(z.lat,z.lon,z.height,z.datum)),z}static parse(t){let e=(t=String(t).trim()).match(/^(\d+),\s*(\d+)$/);if(e)return new d(e[1],e[2]);if(e=t.match(/^[HNST][ABCDEFGHJKLMNOPQRSTUVWXYZ]\s*[0-9]+\s*[0-9]+$/i),!e)throw new Error(`invalid grid reference ‘${t}’`);let r=t.toUpperCase().charCodeAt(0)-"A".charCodeAt(0),i=t.toUpperCase().charCodeAt(1)-"A".charCodeAt(0);r>7&&r--,i>7&&i--;const a=(r-2)%5*5+i%5,o=19-5*Math.floor(r/5)-Math.floor(i/5);let n=t.slice(2).trim().split(/\s+/);if(1==n.length&&(n=[n[0].slice(0,n[0].length/2),n[0].slice(n[0].length/2)]),n[0].length!=n[1].length)throw new Error(`invalid grid reference ‘${t}’`);n[0]=n[0].padEnd(5,"0"),n[1]=n[1].padEnd(5,"0");const s=a+n[0],l=o+n[1];return new d(s,l)}toString(t=10){if(![0,2,4,6,8,10,12,14,16].includes(Number(t)))throw new RangeError(`invalid precision ‘${t}’`);let{easting:e,northing:r}=this;if(0==t){const t={useGrouping:!1,minimumIntegerDigits:6,maximumFractionDigits:3};return`${e.toLocaleString("en",t)},${r.toLocaleString("en",t)}`}const i=Math.floor(e/1e5),a=Math.floor(r/1e5);let o=19-a-(19-a)%5+Math.floor((i+10)/5),n=5*(19-a)%25+i%5;o>7&&o++,n>7&&n++;const s=String.fromCharCode(o+"A".charCodeAt(0),n+"A".charCodeAt(0));return e=Math.floor(e%1e5/Math.pow(10,5-t/2)),r=Math.floor(r%1e5/Math.pow(10,5-t/2)),e=e.toString().padStart(t/2,"0"),r=r.toString().padStart(t/2,"0"),`${s} ${e} ${r}`}}class p extends c{toOsGrid(){const t=this.datum==c.datums.OSGB36?this:this.convertDatum(c.datums.OSGB36),e=t.lat.toRadians(),r=t.lon.toRadians(),{a:i,b:a}=u.ellipsoid,o=u.trueOrigin.lat.toRadians(),n=u.trueOrigin.lon.toRadians(),s=u.scaleFactor,l=1-a*a/(i*i),h=(i-a)/(i+a),p=h*h,m=h*h*h,f=Math.cos(e),g=Math.sin(e),w=i*s/Math.sqrt(1-l*g*g),y=i*s*(1-l)/Math.pow(1-l*g*g,1.5),N=w/y-1,_=a*s*((1+h+5/4*p+5/4*m)*(e-o)-(3*h+3*h*h+21/8*m)*Math.sin(e-o)*Math.cos(e+o)+(15/8*p+15/8*m)*Math.sin(2*(e-o))*Math.cos(2*(e+o))-35/24*m*Math.sin(3*(e-o))*Math.cos(3*(e+o))),E=f*f*f,S=E*f*f,b=Math.tan(e)*Math.tan(e),M=b*b,$=r-n,T=$*$,x=T*$,v=x*$,G=v*$;let R=_+-1e5+w/2*g*f*T+w/24*g*E*(5-b+9*N)*v+w/720*g*S*(61-58*b+M)*(G*$),W=4e5+w*f*$+w/6*E*(w/y-b)*x+w/120*S*(5-18*b+M+14*N-58*b*N)*G;R=Number(R.toFixed(3)),W=Number(W.toFixed(3));try{return new d(W,R)}catch(e){throw new Error(`${e.message} from (${t.lat.toFixed(6)},${t.lon.toFixed(6)}).toOsGrid()`)}}convertDatum(t){const e=super.convertDatum(t);return new p(e.lat,e.lon,e.height,e.datum)}}const m=async(t="https://api.os.uk/search/names/v1/nearest?point={easting},{northing}&radius=1000&fq=local_type:Airfield%20local_type:Airport%20local_type:Bus_Station%20local_type:Chemical_Works%20local_type:City%20local_type:Coach_Station%20local_type:Electricity_Distribution%20local_type:Electricity_Production%20local_type:Further_Education%20local_type:Gas_Distribution_or_Storage%20local_type:Hamlet%20local_type:Harbour%20local_type:Helicopter_Station%20local_type:Heliport%20local_type:Higher_or_University_Education%20local_type:Hill_Or_Mountain%20local_type:Hospice%20local_type:Hospital%20local_type:Medical_Care_Accommodation%20local_type:Named_Road%20local_type:Non_State_Primary_Education%20local_type:Non_State_Secondary_Education%20local_type:Other_Settlement%20local_type:Passenger_Ferry_Terminal%20local_type:Port_Consisting_of_Docks_and_Nautical_Berthing%20local_type:Postcode%20local_type:Primary_Education%20local_type:Railway_Station%20local_type:Road_User_Services%20local_type:Secondary_Education%20local_type:Section_Of_Named_Road%20local_type:Section_Of_Numbered_Road%20local_type:Special_Needs_Education%20local_type:Suburban_Area%20local_type:Town%20local_type:Urban_Greenspace%20local_type:Vehicular_Ferry_Terminal%20local_type:Vehicular_Rail_Terminal%20local_type:Village%20local_type:Waterfall%20",e,r,i,a)=>{let o=a;if("EPSG:4326"===r)try{o=new p(a[1],a[0]).toOsGrid(),o=[o.easting,o.northing].map(t=>Math.round(t))}catch(t){return console.log(t),null}t=t.replace("{easting}",Math.round(o[0])).replace("{northing}",Math.round(o[1]));let n=new Request(t,{method:"GET"});if(e)try{n=await e(n)}catch(t){return console.log("Error transforming request:",t),null}const s=await fetch(n),l=await s.json(),c=function({ID:t,NAME1:e,POPULATED_PLACE:r,COUNTY_UNITARY:i,REGION:a,GEOMETRY_X:o,GEOMETRY_Y:n}){return{id:t||"",place:`${e}${r?", "+r:""}${i?", "+i:""}, ${a}`,county:i||"",coordinates:[o,n]}}(l.results[0].GAZETTEER_ENTRY);if("EPSG:4326"===r){const t=new d(c.coordinates[0],c.coordinates[1]).toLatLon();c.coordinates=[t.lat,t.lon]}const h=`Approximate centre ${c?.place}`;return l.results?h:null};export{m as reverseGeocode};
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/defineProperty";function t(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function o(e){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?t(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function n(){var r;return o(o({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{load:(r=e(function*(){return(yield import(/* webpackChunkName: "im-reverse-geocode" */ "./im-reverse-geocode.js")).reverseGeocode}),function(){return r.apply(this,arguments)})})}export{n as default};
1
+ import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/regenerator";function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach(function(t){r(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function c(){var r;return o(o({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{load:(r=e(t.mark(function e(){var r;return t.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,import(/* webpackChunkName: "im-reverse-geocode" */ "./im-reverse-geocode.js");case 1:return r=e.sent,e.abrupt("return",r.reverseGeocode);case 2:case"end":return e.stop()}},e)})),function(){return r.apply(this,arguments)})})}export{c as default};