@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.
- package/assets/templates/add-polygons.njk +1 -1
- package/assets/templates/add-symbols.njk +4 -4
- package/assets/templates/draw-tools.njk +7 -7
- package/assets/templates/marker-panel.njk +5 -5
- package/assets/templates/place-marker.njk +8 -8
- package/assets/templates/search-control.njk +1 -1
- package/assets/templates/select-feature.njk +7 -7
- package/assets/templates/style-switcher.njk +4 -4
- package/assets/templates/toggle-marker-label.njk +3 -3
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/im-core.js.LICENSE.txt +0 -30
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.LICENSE.txt +0 -20
- package/docs/api/context.md +12 -0
- package/docs/api.md +14 -16
- package/docs/building-a-plugin.md +2 -2
- package/docs/examples/add-marker-with-panel.mdx +46 -44
- package/docs/examples/add-polygons.mdx +100 -98
- package/docs/examples/add-symbols.mdx +75 -73
- package/docs/examples/basic-map.mdx +16 -14
- package/docs/examples/button-map.mdx +16 -14
- package/docs/examples/draw-tools.mdx +119 -117
- package/docs/examples/place-marker.mdx +51 -49
- package/docs/examples/search-control.mdx +22 -20
- package/docs/examples/select-feature.mdx +107 -105
- package/docs/examples/style-switcher.mdx +47 -45
- package/docs/examples/toggle-marker-label.mdx +30 -28
- package/docs/getting-started.md +26 -24
- package/docs/plugins/datasets.md +2 -0
- package/docs/plugins/draw.md +10 -10
- package/docs/plugins/interact.md +9 -9
- package/docs/plugins/map-key.md +41 -0
- package/docs/plugins/plugin-descriptor.md +1 -1
- package/docs/plugins/search.md +3 -3
- package/docusaurus.config.cjs +23 -0
- package/package.json +3 -7
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-es/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/index.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/index.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/esm/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/esm/index.js +1 -1
- package/plugins/beta/frame/dist/umd/im-frame-plugin.js +1 -1
- package/plugins/beta/frame/dist/umd/index.js +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/esm/index.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/esm/index.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/im-scale-bar-plugin.js +1 -1
- package/plugins/beta/scale-bar/dist/umd/index.js +1 -1
- package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/esm/index.js +1 -1
- package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
- package/plugins/beta/use-location/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-esri-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
- package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +1 -3
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +0 -12
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +2 -2
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +1 -2
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +3 -3
- package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/defaults.js +12 -24
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +21 -16
- package/plugins/datasets/src/registry/dataset.test.js +101 -11
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapters/maplibre/styles.js +3 -2
- package/plugins/draw/src/adapters/maplibre/styles.test.js +3 -3
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/esm/index.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/css/index.css +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/esm/index.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +34 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +5 -5
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +4 -4
- package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
- package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
- package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
- package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
- package/plugins/map-key/src/index.js +34 -0
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/dist/esm/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/esm/index.js +1 -1
- package/plugins/menu/dist/umd/im-menu-plugin.js +1 -1
- package/plugins/menu/dist/umd/index.js +1 -1
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/esm/index.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +0 -1
- package/plugins/search/src/components/Form/Form.jsx +3 -3
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
- package/plugins/search/src/defaults.js +3 -0
- package/plugins/search/src/events/formHandlers.js +3 -9
- package/plugins/search/src/events/formHandlers.test.js +6 -9
- package/plugins/search/src/events/inputHandlers.js +8 -2
- package/plugins/search/src/events/inputHandlers.test.js +20 -0
- package/plugins/search/src/events/suggestionHandlers.js +3 -5
- package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
- package/plugins/search/src/utils/showResult.js +9 -0
- package/plugins/search/src/utils/showResult.test.js +16 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/esri/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/esm/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/esm/index.js +1 -1
- package/providers/beta/open-names/dist/umd/im-reverse-geocode.js +1 -1
- package/providers/beta/open-names/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/index.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/index.js +27 -4
- package/providers/beta/openlayers/src/index.test.js +47 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-framework.js.LICENSE.txt +3 -3
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-worker.js +2 -0
- package/providers/maplibre/dist/umd/im-maplibre-worker.js.LICENSE.txt +4 -0
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +41 -12
- package/providers/maplibre/src/index.test.js +43 -12
- package/providers/maplibre/src/utils/detectModuleWorker.js +25 -0
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +40 -0
- package/providers/maplibre/src/utils/spatial.js +22 -12
- package/providers/maplibre/src/utils/spatial.test.js +6 -6
- package/providers/maplibre/src/utils/workerUrl.js +15 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -0
- package/rollup.esm.mjs +38 -1
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Viewport/Viewport.jsx +6 -4
- package/src/App/components/Viewport/Viewport.test.jsx +18 -1
- package/src/App/hooks/useMapAnnouncements.js +7 -2
- package/src/App/hooks/useMapAnnouncements.test.js +13 -2
- package/src/App/hooks/useModalPanelBehaviour.js +3 -1
- package/src/App/initialiseApp.js +1 -1
- package/src/App/store/ServiceProvider.jsx +7 -1
- package/src/App/store/ServiceProvider.test.jsx +15 -0
- package/src/InteractiveMap/InteractiveMap.js +5 -4
- package/src/InteractiveMap/InteractiveMap.test.js +9 -2
- package/src/InteractiveMap/domStateManager.js +21 -1
- package/src/InteractiveMap/domStateManager.test.js +48 -1
- package/src/InteractiveMap/polyfills.js +4 -3
- package/src/InteractiveMap/polyfills.test.js +12 -0
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/types.js +5 -7
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/webpack.dev.mjs +2 -0
- 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.maplibreProvider=r())}(this,()
|
|
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.maplibreProvider=r())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var e,r,t={21:function(e,r,t){e.exports=t.p+"im-maplibre-worker.js"}},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=function(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=function(e){return Promise.all(Object.keys(o.f).reduce(function(r,t){return o.f[t](e,r),r},[]))},o.u=function(e){return{649:"im-maplibre-framework",772:"im-maplibre-provider"}[e]+".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,r){return Object.prototype.hasOwnProperty.call(e,r)},e={},r="defra.maplibreProvider:",o.l=function(t,n,i,u){if(e[t])e[t].push(n);else{var a,c;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==t||p.getAttribute("data-webpack")==r+i){a=p;break}}a||(c=!0,(a=document.createElement("script")).charset="utf-8",o.nc&&a.setAttribute("nonce",o.nc),a.setAttribute("data-webpack",r+i),a.src=t),e[t]=[n];var s=function(r,n){a.onerror=a.onload=null,clearTimeout(d);var o=e[t];if(delete e[t],a.parentNode&&a.parentNode.removeChild(a),o&&o.forEach(function(e){return e(n)}),r)return r(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=s.bind(null,a.onerror),a.onload=s.bind(null,a.onload),c&&document.head.appendChild(a)}},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 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}(),function(){o.b="undefined"!=typeof document&&document.baseURI||self.location.href;var e={57:0};o.f.j=function(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(function(t,o){n=e[r]=[t,o]});t.push(n[2]=i);var u=o.p+o.u(r),a=new Error;o.l(u,function(t){if(o.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var i=t&&("load"===t.type?"missing":t.type),u=t&&t.target&&t.target.src;a.message="Loading chunk "+r+" failed.\n("+i+": "+u+")",a.name="ChunkLoadError",a.type=i,a.request=u,n[1](a)}},"chunk-"+r,r)}};var r=function(r,t){var n,i,u=t[0],a=t[1],c=t[2],f=0;if(u.some(function(r){return 0!==e[r]})){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);c&&c(o)}for(r&&r(t);f<u.length;f++)i=u[f],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0},t=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))}();var i={};function u(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}o.d(i,{default:function(){return m}});var a=function(e){if(!window.WebGLRenderingContext)return{isEnabled:!1,error:"WebGL is not supported"};var r,t=document.createElement("canvas"),n=!1,o=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return u(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?u(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},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,a=!0,c=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==t.return||t.return()}finally{if(c)throw i}}}}(e);try{for(o.s();!(r=o.n()).done;){var i=r.value;try{if((n=t.getContext(i))&&"function"==typeof n.getParameter)return{isEnabled:!0}}catch(e){}}}catch(e){o.e(e)}finally{o.f()}return{isEnabled:!1,error:"WebGL is supported, but disabled"}},c=function(){if("undefined"==typeof Worker)return!1;var e=!1,r={get type(){return e=!0,"module"}};try{new Worker("blob://",r).terminate()}catch(e){}return e},f=function(e){var r=new URL(o(21),o.b);return r.searchParams.set("v",e),r.href};function l(e){return l="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},l(e)}function p(){var e,r,t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",o=t.toStringTag||"@@toStringTag";function i(t,n,o,i){var c=n&&n.prototype instanceof a?n:a,f=Object.create(c.prototype);return s(f,"_invoke",function(t,n,o){var i,a,c,f=0,l=o||[],p=!1,s={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(r,t){return i=r,a=0,c=e,s.n=t,u}};function d(t,n){for(a=t,c=n,r=0;!p&&f&&!o&&r<l.length;r++){var o,i=l[r],d=s.p,b=i[2];t>3?(o=b===n)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=t<2&&d<i[1])?(a=0,s.v=n,s.n=i[1]):d<b&&(o=t<3||i[0]>n||n>b)&&(i[4]=t,i[5]=n,s.n=b,a=0))}if(o||t>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),a=l,c=b;(r=a<2?e:c)||!p;){i||(a?a<3?(a>1&&(s.n=-1),d(a,c)):s.n=c:s.v=c);try{if(f=2,i){if(a||(o="next"),r=i[o]){if(!(r=r.call(i,c)))throw TypeError("iterator result is not an object");if(!r.done)return r;c=r.value,a<2&&(a=0)}else 1===a&&(r=i.return)&&r.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=e}else if((r=(p=s.n<0)?c:t.call(n,s))!==u)break}catch(r){i=e,a=1,c=r}finally{f=1}}return{value:r,done:p}}}(t,o,i),!0),f}var u={};function a(){}function c(){}function f(){}r=Object.getPrototypeOf;var l=[][n]?r(r([][n]())):(s(r={},n,function(){return this}),r),d=f.prototype=a.prototype=Object.create(l);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,s(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return c.prototype=f,s(d,"constructor",f),s(f,"constructor",c),c.displayName="GeneratorFunction",s(f,o,"GeneratorFunction"),s(d),s(d,o,"Generator"),s(d,n,function(){return this}),s(d,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:b}})()}function s(e,r,t,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}s=function(e,r,t,n){function i(r,t){s(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))},s(e,r,t,n)}function d(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 b(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?d(Object(t),!0).forEach(function(r){y(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function y(e,r,t){return(r=function(e){var r=function(e){if("object"!=l(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var t=r.call(e,"string");if("object"!=l(t))return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==l(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function v(e,r,t,n,o,i,u){try{var a=e[i](u),c=a.value}catch(e){return void t(e)}a.done?r(c):Promise.resolve(c).then(n,o)}function m(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{checkDeviceCapabilities:function(){var e=function(){if(document.documentMode)return"Internet Explorer is not supported";var e=a(["webgl2"]);return e.isEnabled?function(){if("function"!=typeof(null===Intl||void 0===Intl?void 0:Intl.supportedValuesOf))return!1;try{return new RegExp("(?<=a)b").test("ab")}catch(e){return!1}}()?c()?void 0:"Browser does not support module workers":"Browser does not support the JavaScript features MapLibre requires":e.error}();return{isSupported:!e,error:e}},load:(e=p().m(function e(){var r,n,i;return p().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.e(649).then(o.bind(o,868));case 1:return(r=e.v).setWorkerUrl(t.workerUrl||f(r.getVersion())),e.n=2,o.e(772).then(o.bind(o,988));case 2:return n=e.v.default,i=b(b({},t),{},{crs:"EPSG:4326"}),e.a(2,{MapProvider:n,mapProviderConfig:i,mapFramework:r})}},e)}),r=function(){var r=this,t=arguments;return new Promise(function(n,o){var i=e.apply(r,t);function u(e){v(i,n,o,u,a,"next",e)}function a(e){v(i,n,o,u,a,"throw",e)}u(void 0)})},function(){return r.apply(this,arguments)})}}return i.default}()});
|
|
@@ -6,17 +6,49 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { getWebGL } from './utils/detectWebgl.js'
|
|
9
|
+
import { supportsModuleWorkers } from './utils/detectModuleWorker.js'
|
|
10
|
+
import { getWorkerUrl } from './utils/workerUrl.js'
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
|
-
* Checks whether the browser
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Checks whether the browser can parse and run MapLibre. Its newest syntax is class
|
|
14
|
+
* static blocks (Chrome 94 / Firefox 93 / Safari 16.4), which cannot be detected
|
|
15
|
+
* without `eval`, so two proxies that polyfills don't provide are used:
|
|
16
|
+
* `Intl.supportedValuesOf` (Chrome 99 / Firefox 93) and RegExp lookbehind, which
|
|
17
|
+
* Safari gained in 16.4.
|
|
15
18
|
*
|
|
16
19
|
* @returns {boolean} true if modern syntax is supported, false otherwise
|
|
17
20
|
*/
|
|
18
21
|
function supportsModernMaplibre () {
|
|
19
|
-
|
|
22
|
+
if (typeof Intl?.supportedValuesOf !== 'function') {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return new RegExp('(?<=a)b').test('ab') // eslint-disable-line prefer-regex-literals -- NOSONAR: a literal would be a syntax error in browsers without lookbehind
|
|
27
|
+
} catch (_) { // NOSONAR - a SyntaxError means lookbehind is unsupported
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the reason the device cannot run MapLibre, or undefined if it can.
|
|
34
|
+
*
|
|
35
|
+
* @returns {string|undefined}
|
|
36
|
+
*/
|
|
37
|
+
function getUnsupportedReason () {
|
|
38
|
+
if (document.documentMode) {
|
|
39
|
+
return 'Internet Explorer is not supported'
|
|
40
|
+
}
|
|
41
|
+
const webGL = getWebGL(['webgl2'])
|
|
42
|
+
if (!webGL.isEnabled) {
|
|
43
|
+
return webGL.error
|
|
44
|
+
}
|
|
45
|
+
if (!supportsModernMaplibre()) {
|
|
46
|
+
return 'Browser does not support the JavaScript features MapLibre requires'
|
|
47
|
+
}
|
|
48
|
+
if (!supportsModuleWorkers()) {
|
|
49
|
+
return 'Browser does not support module workers'
|
|
50
|
+
}
|
|
51
|
+
return undefined
|
|
20
52
|
}
|
|
21
53
|
|
|
22
54
|
/**
|
|
@@ -28,20 +60,17 @@ function supportsModernMaplibre () {
|
|
|
28
60
|
export default function createMapLibreProvider (config = {}) {
|
|
29
61
|
return {
|
|
30
62
|
checkDeviceCapabilities: () => {
|
|
31
|
-
const
|
|
32
|
-
const isIE = document.documentMode
|
|
63
|
+
const error = getUnsupportedReason()
|
|
33
64
|
return {
|
|
34
|
-
isSupported:
|
|
35
|
-
error
|
|
65
|
+
isSupported: !error,
|
|
66
|
+
error
|
|
36
67
|
}
|
|
37
68
|
},
|
|
38
69
|
/** @returns {Promise<MapProviderLoadResult>} */
|
|
39
70
|
load: async () => {
|
|
40
71
|
const mapFramework = await import(/* webpackChunkName: "im-maplibre-framework" */ 'maplibre-gl')
|
|
41
72
|
|
|
42
|
-
|
|
43
|
-
mapFramework.setWorkerUrl(config.workerUrl)
|
|
44
|
-
}
|
|
73
|
+
mapFramework.setWorkerUrl(config.workerUrl || getWorkerUrl(mapFramework.getVersion()))
|
|
45
74
|
|
|
46
75
|
const MapProvider = (await import(/* webpackChunkName: "im-maplibre-provider" */ './maplibreProvider.js')).default
|
|
47
76
|
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import createMapLibreProvider from './index.js'
|
|
2
2
|
import { getWebGL } from './utils/detectWebgl.js'
|
|
3
|
+
import { supportsModuleWorkers } from './utils/detectModuleWorker.js'
|
|
3
4
|
import * as maplibreGl from 'maplibre-gl'
|
|
4
5
|
|
|
5
6
|
jest.mock('./utils/detectWebgl.js', () => ({ getWebGL: jest.fn() }))
|
|
6
|
-
jest.mock('
|
|
7
|
+
jest.mock('./utils/detectModuleWorker.js', () => ({ supportsModuleWorkers: jest.fn() }))
|
|
8
|
+
jest.mock('./utils/workerUrl.js', () => ({ getWorkerUrl: (version) => `http://localhost/maplibre-gl-worker.mjs?v=${version}` }))
|
|
9
|
+
jest.mock('maplibre-gl', () => ({ getVersion: () => '6.0.0', setWorkerUrl: jest.fn() }))
|
|
7
10
|
jest.mock('./maplibreProvider.js', () => ({ default: class MockProvider {} }))
|
|
8
11
|
|
|
9
12
|
describe('createMapLibreProvider', () => {
|
|
10
13
|
beforeEach(() => {
|
|
11
14
|
getWebGL.mockReturnValue({ isEnabled: true, error: null })
|
|
15
|
+
supportsModuleWorkers.mockReturnValue(true)
|
|
12
16
|
})
|
|
13
17
|
|
|
14
18
|
afterEach(() => {
|
|
15
19
|
jest.clearAllMocks()
|
|
16
20
|
})
|
|
17
21
|
|
|
18
|
-
test('checkDeviceCapabilities:
|
|
22
|
+
test('checkDeviceCapabilities: WebGL2, modern browser, module workers, no IE → isSupported true', () => {
|
|
19
23
|
const result = createMapLibreProvider().checkDeviceCapabilities()
|
|
20
24
|
|
|
21
25
|
expect(result.isSupported).toBe(true)
|
|
22
26
|
expect(result.error).toBeFalsy()
|
|
23
|
-
expect(getWebGL).toHaveBeenCalledWith(['webgl2'
|
|
27
|
+
expect(getWebGL).toHaveBeenCalledWith(['webgl2'])
|
|
24
28
|
})
|
|
25
29
|
|
|
26
30
|
test('checkDeviceCapabilities: WebGL disabled → isSupported false, returns webGL error', () => {
|
|
@@ -40,6 +44,7 @@ describe('createMapLibreProvider', () => {
|
|
|
40
44
|
|
|
41
45
|
try {
|
|
42
46
|
const result = createMapLibreProvider().checkDeviceCapabilities()
|
|
47
|
+
expect(result.isSupported).toBe(false)
|
|
43
48
|
expect(result.error).toBe('Internet Explorer is not supported')
|
|
44
49
|
} finally {
|
|
45
50
|
Object.defineProperty(document, 'documentMode', {
|
|
@@ -49,14 +54,40 @@ describe('createMapLibreProvider', () => {
|
|
|
49
54
|
}
|
|
50
55
|
})
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
// Not Object.hasOwn: polyfills.js adds it before this check runs
|
|
58
|
+
test('checkDeviceCapabilities: no Intl.supportedValuesOf → isSupported false', () => {
|
|
59
|
+
const restoreSupportedValuesOf = Intl.supportedValuesOf
|
|
60
|
+
delete Intl.supportedValuesOf
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const result = createMapLibreProvider().checkDeviceCapabilities()
|
|
64
|
+
expect(result.isSupported).toBe(false)
|
|
65
|
+
expect(result.error).toBe('Browser does not support the JavaScript features MapLibre requires')
|
|
66
|
+
} finally {
|
|
67
|
+
Intl.supportedValuesOf = restoreSupportedValuesOf
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('checkDeviceCapabilities: no RegExp lookbehind → isSupported false', () => {
|
|
72
|
+
const NativeRegExp = globalThis.RegExp
|
|
73
|
+
globalThis.RegExp = function () { throw new SyntaxError('Invalid regular expression') }
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const result = createMapLibreProvider().checkDeviceCapabilities()
|
|
77
|
+
expect(result.isSupported).toBe(false)
|
|
78
|
+
expect(result.error).toBe('Browser does not support the JavaScript features MapLibre requires')
|
|
79
|
+
} finally {
|
|
80
|
+
globalThis.RegExp = NativeRegExp
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('checkDeviceCapabilities: no module workers → isSupported false', () => {
|
|
85
|
+
supportsModuleWorkers.mockReturnValue(false)
|
|
55
86
|
|
|
56
87
|
const result = createMapLibreProvider().checkDeviceCapabilities()
|
|
57
88
|
|
|
58
89
|
expect(result.isSupported).toBe(false)
|
|
59
|
-
|
|
90
|
+
expect(result.error).toBe('Browser does not support module workers')
|
|
60
91
|
})
|
|
61
92
|
|
|
62
93
|
test('load returns MapProvider, mapFramework, and merged mapProviderConfig', async () => {
|
|
@@ -76,15 +107,15 @@ describe('createMapLibreProvider', () => {
|
|
|
76
107
|
expect(mapProviderConfig).toEqual({ crs: 'EPSG:4326' })
|
|
77
108
|
})
|
|
78
109
|
|
|
79
|
-
test('load
|
|
80
|
-
await createMapLibreProvider({ workerUrl: '/assets/maplibre-gl-
|
|
110
|
+
test('load sets the configured workerUrl when provided', async () => {
|
|
111
|
+
await createMapLibreProvider({ workerUrl: '/assets/maplibre-gl-worker.mjs' }).load()
|
|
81
112
|
|
|
82
|
-
expect(maplibreGl.setWorkerUrl).toHaveBeenCalledWith('/assets/maplibre-gl-
|
|
113
|
+
expect(maplibreGl.setWorkerUrl).toHaveBeenCalledWith('/assets/maplibre-gl-worker.mjs')
|
|
83
114
|
})
|
|
84
115
|
|
|
85
|
-
test('load
|
|
116
|
+
test('load sets the bundled worker URL when workerUrl is not provided', async () => {
|
|
86
117
|
await createMapLibreProvider().load()
|
|
87
118
|
|
|
88
|
-
expect(maplibreGl.setWorkerUrl).
|
|
119
|
+
expect(maplibreGl.setWorkerUrl).toHaveBeenCalledWith('http://localhost/maplibre-gl-worker.mjs?v=6.0.0')
|
|
89
120
|
})
|
|
90
121
|
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the browser can run module workers (`new Worker(url, { type: 'module' })`).
|
|
3
|
+
*
|
|
4
|
+
* Browsers that support module workers read the `type` option while converting the options
|
|
5
|
+
* object, before the URL is validated, so the getter is called even though construction fails.
|
|
6
|
+
*
|
|
7
|
+
* @returns {boolean} true if module workers are supported, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
export const supportsModuleWorkers = () => {
|
|
10
|
+
if (typeof Worker === 'undefined') {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
let supported = false
|
|
14
|
+
const options = {
|
|
15
|
+
get type () {
|
|
16
|
+
supported = true
|
|
17
|
+
return 'module'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
new Worker('blob://', options).terminate()
|
|
22
|
+
} catch (_) { // NOSONAR - construction is expected to fail; only the getter call matters
|
|
23
|
+
}
|
|
24
|
+
return supported
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { supportsModuleWorkers } from './detectModuleWorker.js'
|
|
2
|
+
|
|
3
|
+
describe('supportsModuleWorkers', () => {
|
|
4
|
+
const originalWorker = globalThis.Worker
|
|
5
|
+
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
globalThis.Worker = originalWorker
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('returns false when Worker is not available', () => {
|
|
11
|
+
delete globalThis.Worker
|
|
12
|
+
expect(supportsModuleWorkers()).toBe(false)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns true when the Worker constructor reads the type option', () => {
|
|
16
|
+
globalThis.Worker = function (url, options) {
|
|
17
|
+
if (options.type !== 'module') {
|
|
18
|
+
throw new Error('unexpected type')
|
|
19
|
+
}
|
|
20
|
+
throw new TypeError('Invalid URL')
|
|
21
|
+
}
|
|
22
|
+
expect(supportsModuleWorkers()).toBe(true)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('terminates the worker if construction succeeds', () => {
|
|
26
|
+
const terminate = jest.fn()
|
|
27
|
+
globalThis.Worker = function (url, options) {
|
|
28
|
+
return { type: options.type, terminate }
|
|
29
|
+
}
|
|
30
|
+
expect(supportsModuleWorkers()).toBe(true)
|
|
31
|
+
expect(terminate).toHaveBeenCalled()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('returns false when the Worker constructor ignores the type option', () => {
|
|
35
|
+
globalThis.Worker = function () {
|
|
36
|
+
throw new TypeError('Invalid URL')
|
|
37
|
+
}
|
|
38
|
+
expect(supportsModuleWorkers()).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
// src/utils/spatial.js
|
|
2
|
-
import LatLon from 'geodesy/latlon-spherical.js'
|
|
3
2
|
import turfBbox from '@turf/bbox'
|
|
4
3
|
|
|
5
4
|
// -----------------------------------------------------------------------------
|
|
6
5
|
// Internal (not exported)
|
|
7
6
|
// -----------------------------------------------------------------------------
|
|
8
7
|
|
|
8
|
+
const EARTH_RADIUS_METRES = 6371e3
|
|
9
|
+
const DEGREES_PER_HALF_TURN = 180
|
|
10
|
+
const RADIANS_PER_DEGREE = Math.PI / DEGREES_PER_HALF_TURN
|
|
11
|
+
const MIN_MOVE_DEGREES = 0.0001 // moves smaller than this aren't announced
|
|
12
|
+
|
|
13
|
+
const toRadians = (degrees) => degrees * RADIANS_PER_DEGREE
|
|
14
|
+
|
|
9
15
|
/**
|
|
10
|
-
* Calculate distance in metres between two [lng, lat] coordinates
|
|
16
|
+
* Calculate distance in metres between two [lng, lat] coordinates (haversine)
|
|
11
17
|
*/
|
|
12
18
|
const getDistance = (from, to) => {
|
|
13
19
|
const [lng1, lat1] = from
|
|
14
20
|
const [lng2, lat2] = to
|
|
15
21
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
22
|
+
const lat1Rad = toRadians(lat1)
|
|
23
|
+
const lat2Rad = toRadians(lat2)
|
|
24
|
+
const dLat = lat2Rad - lat1Rad
|
|
25
|
+
const dLng = toRadians(lng2 - lng1)
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
const haversine = Math.sin(dLat / 2) ** 2 + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.sin(dLng / 2) ** 2
|
|
28
|
+
const centralAngle = 2 * Math.atan2(Math.sqrt(haversine), Math.sqrt(1 - haversine))
|
|
29
|
+
return EARTH_RADIUS_METRES * centralAngle
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
/**
|
|
@@ -95,12 +105,12 @@ const getCardinalMove = (from, to) => {
|
|
|
95
105
|
|
|
96
106
|
const moves = []
|
|
97
107
|
|
|
98
|
-
if (Math.abs(dLat) >
|
|
108
|
+
if (Math.abs(dLat) > MIN_MOVE_DEGREES) {
|
|
99
109
|
const metres = Math.round(getDistance([lng1, lat1], [lng1, lat2]))
|
|
100
110
|
moves.push(`${dLat > 0 ? 'north' : 'south'} ${formatDimension(metres)}`)
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
if (Math.abs(dLng) >
|
|
113
|
+
if (Math.abs(dLng) > MIN_MOVE_DEGREES) {
|
|
104
114
|
const metres = Math.round(getDistance([lng1, lat1], [lng2, lat1]))
|
|
105
115
|
moves.push(`${dLng > 0 ? 'east' : 'west'} ${formatDimension(metres)}`)
|
|
106
116
|
}
|
|
@@ -113,7 +123,7 @@ const getResolution = (center, zoom) => {
|
|
|
113
123
|
const TILE_SIZE = 512
|
|
114
124
|
const lat = center.lat
|
|
115
125
|
const scale = Math.pow(2, zoom)
|
|
116
|
-
const resolution = (EARTH_CIRCUMFERENCE * Math.cos((lat
|
|
126
|
+
const resolution = (EARTH_CIRCUMFERENCE * Math.cos(toRadians(lat))) / (scale * TILE_SIZE)
|
|
117
127
|
return resolution
|
|
118
128
|
}
|
|
119
129
|
|
|
@@ -161,10 +171,10 @@ const isGeometryObscured = (geojson, panelRect, map) => {
|
|
|
161
171
|
map.project([east, north])
|
|
162
172
|
]
|
|
163
173
|
|
|
164
|
-
const screenMinX = Math.min(...corners.map(
|
|
165
|
-
const screenMaxX = Math.max(...corners.map(
|
|
166
|
-
const screenMinY = Math.min(...corners.map(
|
|
167
|
-
const screenMaxY = Math.max(...corners.map(
|
|
174
|
+
const screenMinX = Math.min(...corners.map(corner => corner.x))
|
|
175
|
+
const screenMaxX = Math.max(...corners.map(corner => corner.x))
|
|
176
|
+
const screenMinY = Math.min(...corners.map(corner => corner.y))
|
|
177
|
+
const screenMaxY = Math.max(...corners.map(corner => corner.y))
|
|
168
178
|
|
|
169
179
|
// Convert panelRect from viewport coords to map-container-relative coords
|
|
170
180
|
const panelLeft = panelRect.left - containerRect.left
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
// tests/utils/spatial.test.js
|
|
2
2
|
import * as spatial from '../../src/utils/spatial.js'
|
|
3
3
|
|
|
4
|
-
jest.mock('geodesy/latlon-spherical.js', () =>
|
|
5
|
-
jest.fn().mockImplementation((lat, lng) => ({
|
|
6
|
-
distanceTo: jest.fn((other) => Math.abs(lat - (other.lat || 0)) * 1609 + Math.abs(lng - (other.lon || 0)) * 1609)
|
|
7
|
-
}))
|
|
8
|
-
)
|
|
9
|
-
|
|
10
4
|
jest.mock('@turf/bbox', () => jest.fn(() => [-1, 50, 1, 52]))
|
|
11
5
|
|
|
12
6
|
describe('spatial utils', () => {
|
|
@@ -53,6 +47,12 @@ describe('spatial utils', () => {
|
|
|
53
47
|
expect(spatial.getCardinalMove([0, 0], [0.00001, 0.00001])).toBe('')
|
|
54
48
|
})
|
|
55
49
|
|
|
50
|
+
test('cardinal moves use great-circle distance', () => {
|
|
51
|
+
// 1 degree of latitude on a 6371 km sphere is 111,195 metres (69.09 miles)
|
|
52
|
+
expect(spatial.getCardinalMove([0, 0], [0, 1])).toBe('north 69 miles')
|
|
53
|
+
expect(spatial.getCardinalMove([-0.12, 51.5], [-0.12, 51.5009])).toBe('north 100 metres')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
56
|
test('getResolution returns positive value', () => {
|
|
57
57
|
expect(spatial.getResolution({ lat: 0 }, 1)).toBeGreaterThan(0)
|
|
58
58
|
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the URL of MapLibre's worker script.
|
|
3
|
+
*
|
|
4
|
+
* MapLibre looks for its worker next to its own module, which bundlers move and rename. Written as
|
|
5
|
+
* a static `new URL(..., import.meta.url)` so webpack and Vite emit the worker file and rewrite this
|
|
6
|
+
* URL to it. The version query stops browsers reusing a cached worker from another MapLibre release.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} version - MapLibre version, from `getVersion()`.
|
|
9
|
+
* @returns {string} The worker URL.
|
|
10
|
+
*/
|
|
11
|
+
export const getWorkerUrl = (version) => {
|
|
12
|
+
const url = new URL('maplibre-gl/dist/maplibre-gl-worker.mjs', import.meta.url)
|
|
13
|
+
url.searchParams.set('v', version)
|
|
14
|
+
return url.href
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getWorkerUrl } from './workerUrl.js'
|
|
2
|
+
|
|
3
|
+
describe('getWorkerUrl', () => {
|
|
4
|
+
test('resolves the maplibre-gl worker file relative to this module', () => {
|
|
5
|
+
const url = new URL(getWorkerUrl('6.0.0'))
|
|
6
|
+
|
|
7
|
+
expect(url.protocol).toBe('file:')
|
|
8
|
+
expect(url.pathname).toMatch(/\/maplibre-gl\/dist\/maplibre-gl-worker\.mjs$/)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('adds the MapLibre version as a cache-busting query', () => {
|
|
12
|
+
expect(new URL(getWorkerUrl('6.0.0')).searchParams.get('v')).toBe('6.0.0')
|
|
13
|
+
})
|
|
14
|
+
})
|
package/rollup.esm.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import replace from '@rollup/plugin-replace'
|
|
|
10
10
|
import terser from '@rollup/plugin-terser'
|
|
11
11
|
import postcss from 'rollup-plugin-postcss'
|
|
12
12
|
import { visualizer } from 'rollup-plugin-visualizer'
|
|
13
|
+
import { transformAsync } from '@babel/core'
|
|
13
14
|
|
|
14
15
|
const __dirname = dirname(fileURLToPath(import.meta.url)) // NOSONAR - Standard Node.js convention in bundler configs
|
|
15
16
|
|
|
@@ -29,6 +30,40 @@ const cleanPlugin = (dirs) => ({
|
|
|
29
30
|
}
|
|
30
31
|
})
|
|
31
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Compiles the chunks that load before the device check (entries and the chunks
|
|
35
|
+
* they import statically) to ES5, so older browsers can parse them and show the
|
|
36
|
+
* not-supported message. Hosts' bundlers usually don't transpile node_modules.
|
|
37
|
+
* Lazily loaded chunks keep modern syntax; they only load once the check passes.
|
|
38
|
+
* import/export, import() and import.meta are left for the host's bundler.
|
|
39
|
+
*/
|
|
40
|
+
const es5InitialChunksPlugin = () => ({
|
|
41
|
+
name: 'es5-initial-chunks',
|
|
42
|
+
async renderChunk (code, chunk, _outputOptions, { chunks }) {
|
|
43
|
+
const initial = new Set()
|
|
44
|
+
const addWithStaticImports = (fileName) => {
|
|
45
|
+
if (initial.has(fileName)) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
initial.add(fileName)
|
|
49
|
+
chunks[fileName]?.imports.forEach(addWithStaticImports)
|
|
50
|
+
}
|
|
51
|
+
Object.values(chunks).filter(c => c.isEntry).forEach(c => addWithStaticImports(c.fileName))
|
|
52
|
+
|
|
53
|
+
if (!initial.has(chunk.fileName)) {
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
const result = await transformAsync(code, {
|
|
57
|
+
babelrc: false,
|
|
58
|
+
configFile: false,
|
|
59
|
+
sourceType: 'module',
|
|
60
|
+
presets: [['@babel/preset-env', { targets: { ie: '11' }, modules: false }]],
|
|
61
|
+
plugins: ['@babel/plugin-transform-runtime']
|
|
62
|
+
})
|
|
63
|
+
return { code: result.code, map: null }
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
32
67
|
// Adds webpackChunkName magic comments to all relative dynamic imports in the
|
|
33
68
|
// output, deriving the name from the imported file's basename.
|
|
34
69
|
// Must run AFTER terser() so the comments survive minification.
|
|
@@ -158,7 +193,7 @@ const createESMConfig = (entryPath, outDir, isCore = false, manualChunks = null,
|
|
|
158
193
|
// This avoids transpiling classes, arrow functions, async/await etc.
|
|
159
194
|
// into verbose ES5 — the single biggest driver of ESM bundle size.
|
|
160
195
|
presets: [
|
|
161
|
-
['@babel/preset-env', { targets: {
|
|
196
|
+
['@babel/preset-env', { targets: { chrome: '92', edge: '92', firefox: '90', safari: '15.4', ios: '15.4' }, bugfixes: true }],
|
|
162
197
|
['@babel/preset-react', { runtime: 'automatic' }]
|
|
163
198
|
]
|
|
164
199
|
}),
|
|
@@ -171,6 +206,8 @@ const createESMConfig = (entryPath, outDir, isCore = false, manualChunks = null,
|
|
|
171
206
|
minimize: true
|
|
172
207
|
}),
|
|
173
208
|
|
|
209
|
+
es5InitialChunksPlugin(),
|
|
210
|
+
|
|
174
211
|
terser(),
|
|
175
212
|
|
|
176
213
|
// webpackChunkNamesPlugin must come after terser so comments survive
|
|
@@ -22,7 +22,7 @@ export const Viewport = () => {
|
|
|
22
22
|
const { id, mapProvider, mapLabel, keyboardHintText, focusOnMount } = useConfig()
|
|
23
23
|
const { layoutRefs, safeZoneInset, dispatch } = useApp()
|
|
24
24
|
const { mapSize, isMapReady } = useMap()
|
|
25
|
-
const { eventBus, hints } = useService()
|
|
25
|
+
const { eventBus, hints, mapFocus } = useService()
|
|
26
26
|
|
|
27
27
|
const mapContainerRef = useRef(null)
|
|
28
28
|
const spatialListRef = useRef(null)
|
|
@@ -75,7 +75,7 @@ export const Viewport = () => {
|
|
|
75
75
|
return (
|
|
76
76
|
<>
|
|
77
77
|
<MapController mapContainerRef={mapContainerRef} />
|
|
78
|
-
<div
|
|
78
|
+
<div // NOSONAR - role="application" is interactive: the map handles its own keyboard and pointer input
|
|
79
79
|
id={`${id}-viewport`}
|
|
80
80
|
className={`im-c-viewport im-c-viewport--${mapSize}`}
|
|
81
81
|
aria-label={mapLabel}
|
|
@@ -83,10 +83,12 @@ export const Viewport = () => {
|
|
|
83
83
|
tabIndex='0' // nosonar
|
|
84
84
|
data-map-keyboard-scope
|
|
85
85
|
onFocus={handleFocus}
|
|
86
|
-
onBlur={handleBlur}
|
|
86
|
+
onBlur={(event) => { handleBlur(event); mapFocus.clear() }}
|
|
87
|
+
onKeyDown={() => mapFocus.releaseAnnouncements()}
|
|
88
|
+
onPointerDown={() => mapFocus.releaseAnnouncements()}
|
|
87
89
|
ref={layoutRefs.viewportRef}
|
|
88
90
|
aria-describedby={`${id}-keyboard-desc`}
|
|
89
|
-
aria-controls={`${id}-
|
|
91
|
+
aria-controls={`${id}-spatial-list`}
|
|
90
92
|
>
|
|
91
93
|
<div className='im-c-viewport__map-container' ref={mapContainerRef} aria-hidden='true' />
|
|
92
94
|
<MapStatus />
|
|
@@ -46,7 +46,8 @@ function setupHookMocks (mainEl, viewportEl) {
|
|
|
46
46
|
useService.mockReturnValue({
|
|
47
47
|
announce: jest.fn(),
|
|
48
48
|
hints: { show: jest.fn(), dismiss: jest.fn(), subscribe: jest.fn(() => jest.fn()) },
|
|
49
|
-
eventBus: { on: jest.fn(), off: jest.fn(), emit: jest.fn() }
|
|
49
|
+
eventBus: { on: jest.fn(), off: jest.fn(), emit: jest.fn() },
|
|
50
|
+
mapFocus: { clear: jest.fn(), releaseAnnouncements: jest.fn() }
|
|
50
51
|
})
|
|
51
52
|
useKeyboardHint.mockImplementation(({ onViewportFocusChange }) => ({
|
|
52
53
|
handleFocus: () => onViewportFocusChange(true),
|
|
@@ -114,6 +115,22 @@ describe('Viewport rendering', () => {
|
|
|
114
115
|
expect(viewport).toHaveAttribute('aria-describedby', 'test-map-keyboard-desc')
|
|
115
116
|
})
|
|
116
117
|
|
|
118
|
+
it('restores the map label via mapFocus when the viewport loses focus', () => {
|
|
119
|
+
const { mapFocus } = useService()
|
|
120
|
+
const { viewport } = renderViewport()
|
|
121
|
+
fireEvent.blur(viewport)
|
|
122
|
+
expect(mapFocus.clear).toHaveBeenCalled()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('releases held map announcements on a key or pointer press in the viewport', () => {
|
|
126
|
+
const { mapFocus } = useService()
|
|
127
|
+
const { viewport } = renderViewport()
|
|
128
|
+
fireEvent.keyDown(viewport, { key: 'ArrowUp' })
|
|
129
|
+
fireEvent.pointerDown(viewport)
|
|
130
|
+
expect(mapFocus.releaseAnnouncements).toHaveBeenCalledTimes(2)
|
|
131
|
+
expect(mapFocus.clear).not.toHaveBeenCalled()
|
|
132
|
+
})
|
|
133
|
+
|
|
117
134
|
it('calls hints.show() with keyboardHintText when viewport gains keyboard focus', () => {
|
|
118
135
|
const { hints } = useService()
|
|
119
136
|
renderViewport()
|
|
@@ -40,7 +40,7 @@ const resolveMessage = (previous, current, mapProvider) => {
|
|
|
40
40
|
|
|
41
41
|
export function useMapAnnouncements () {
|
|
42
42
|
const { mapProvider } = useConfig()
|
|
43
|
-
const { eventBus, announce } = useService()
|
|
43
|
+
const { eventBus, announce, mapFocus } = useService()
|
|
44
44
|
|
|
45
45
|
useEffect(() => {
|
|
46
46
|
const handleAnnounceStateUpdate = ({ previous, current }) => {
|
|
@@ -48,6 +48,11 @@ export function useMapAnnouncements () {
|
|
|
48
48
|
return
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// A map focus message already describes this move
|
|
52
|
+
if (mapFocus.isHoldingAnnouncements()) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
const message = resolveMessage(previous, current, mapProvider)
|
|
52
57
|
if (message) {
|
|
53
58
|
announce(message, 'action')
|
|
@@ -59,5 +64,5 @@ export function useMapAnnouncements () {
|
|
|
59
64
|
return () => {
|
|
60
65
|
eventBus.off(events.MAP_STATE_UPDATED, handleAnnounceStateUpdate)
|
|
61
66
|
}
|
|
62
|
-
}, [mapProvider, announce])
|
|
67
|
+
}, [mapProvider, announce, mapFocus])
|
|
63
68
|
}
|