@defra/interactive-map 0.0.52-alpha → 0.0.53-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 (147) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/dist/umd/index.js +1 -1
  4. package/docs/api/context.md +18 -12
  5. package/docs/api/marker-config.md +16 -8
  6. package/docs/api/symbol-config.md +24 -9
  7. package/docs/api/symbol-registry.md +49 -14
  8. package/docs/plugins/datasets.md +4 -10
  9. package/docs/plugins/draw.md +2 -1
  10. package/docs/plugins/map-key.md +6 -4
  11. package/package.json +1 -1
  12. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  13. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  14. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  15. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  16. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
  17. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  18. package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  20. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  21. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  22. package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +9 -9
  23. package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +19 -3
  24. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
  25. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
  26. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
  27. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +19 -26
  28. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +15 -67
  29. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +32 -105
  30. package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
  31. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
  32. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
  33. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +99 -11
  34. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +26 -26
  35. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +48 -29
  36. package/plugins/datasets/src/initialise/defaults.js +4 -3
  37. package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
  38. package/plugins/datasets/src/registry/dataset.js +2 -1
  39. package/plugins/datasets/src/registry/dataset.test.js +13 -0
  40. package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
  41. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
  42. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  43. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  44. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  45. package/plugins/draw/dist/esm/index.js +1 -1
  46. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  47. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  48. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  49. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  50. package/plugins/draw/dist/umd/index.js +1 -1
  51. package/plugins/draw/src/DrawInit.jsx +7 -5
  52. package/plugins/draw/src/DrawInit.test.jsx +18 -2
  53. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
  54. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
  55. package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
  56. package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
  57. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
  58. package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
  59. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
  60. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
  61. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
  62. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
  63. package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
  64. package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
  65. package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
  66. package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
  67. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
  68. package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
  69. package/plugins/draw/src/defaults.js +2 -6
  70. package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
  71. package/plugins/draw/src/utils/symbolKeys.js +3 -4
  72. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  73. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  74. package/plugins/interact/dist/umd/index.js +1 -1
  75. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  76. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
  77. package/plugins/map-key/dist/umd/index.js +1 -1
  78. package/plugins/map-key/src/components/Key/Key.jsx +8 -4
  79. package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +3 -1
  80. package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
  81. package/plugins/map-key/src/components/Key/KeySvg.jsx +15 -14
  82. package/plugins/map-key/src/components/Key/KeySvg.test.jsx +21 -14
  83. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
  84. package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
  85. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
  86. package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
  87. package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
  88. package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
  89. package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
  90. package/plugins/map-key/src/registry/index.js +0 -2
  91. package/plugins/map-key/src/registry/index.test.js +1 -9
  92. package/plugins/menu/src/registry/index.js +0 -2
  93. package/plugins/menu/src/registry/index.test.js +1 -9
  94. package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
  95. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  96. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  97. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  98. package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
  99. package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
  100. package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
  101. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
  102. package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
  103. package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
  104. package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
  105. package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
  106. package/providers/mapProvider.js +53 -1
  107. package/providers/mapProvider.test.js +6 -0
  108. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  109. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  110. package/providers/maplibre/dist/umd/index.js +1 -1
  111. package/providers/maplibre/src/maplibreProvider.js +50 -17
  112. package/providers/maplibre/src/maplibreProvider.test.js +74 -20
  113. package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
  114. package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
  115. package/providers/maplibre/src/utils/patternImages.js +46 -29
  116. package/providers/maplibre/src/utils/patternImages.test.js +52 -4
  117. package/providers/maplibre/src/utils/symbolImages.js +80 -39
  118. package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
  119. package/src/App/components/Markers/Markers.jsx +16 -25
  120. package/src/App/components/Markers/Markers.test.jsx +34 -48
  121. package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
  122. package/src/App/components/Markers/SymbolMarker.jsx +1 -1
  123. package/src/App/store/ServiceProvider.jsx +6 -3
  124. package/src/App/store/ServiceProvider.test.jsx +24 -0
  125. package/src/config/appConfig.js +1 -5
  126. package/src/config/mapSizeScales.js +8 -0
  127. package/src/config/symbolConfig.js +101 -25
  128. package/src/services/patternRegistry.js +97 -76
  129. package/src/services/patternRegistry.test.js +19 -1
  130. package/src/services/symbolComposer.js +184 -0
  131. package/src/services/symbolComposer.test.js +132 -0
  132. package/src/services/symbolRegistry.js +326 -155
  133. package/src/services/symbolRegistry.test.js +334 -32
  134. package/src/types.js +9 -3
  135. package/src/utils/hashString.js +23 -0
  136. package/src/utils/hashString.test.js +29 -0
  137. package/src/utils/imageDataCache.js +43 -0
  138. package/src/utils/imageDataCache.test.js +38 -0
  139. package/src/utils/pathBounds.js +330 -0
  140. package/src/utils/pathBounds.test.js +145 -0
  141. package/src/utils/patternUtils.js +0 -8
  142. package/src/utils/patternUtils.test.js +0 -25
  143. package/src/utils/recentImageSets.js +35 -0
  144. package/src/utils/recentImageSets.test.js +46 -0
  145. package/src/utils/symbolUtils.js +26 -29
  146. package/src/utils/symbolUtils.test.js +27 -41
  147. package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
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.drawPlugin=t())}(this,()=>(()=>{"use strict";var e,t,r={738(e){e.exports=preactCompat},287(e){e.exports=preactJsxRuntime}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(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=e=>Promise.all(Object.keys(o.f).reduce((t,r)=>(o.f[r](e,t),t),[])),o.u=e=>({356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[e]+".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,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="defra.drawPlugin:",o.l=(r,n,i,a)=>{if(e[r])e[r].push(n);else{var u,c;if(void 0!==i)for(var f=document.getElementsByTagName("script"),p=0;p<f.length;p++){var l=f[p];if(l.getAttribute("src")==r||l.getAttribute("data-webpack")==t+i){u=l;break}}u||(c=!0,(u=document.createElement("script")).charset="utf-8",o.nc&&u.setAttribute("nonce",o.nc),u.setAttribute("data-webpack",t+i),u.src=r),e[r]=[n];var s=(t,n)=>{u.onerror=u.onload=null,clearTimeout(d);var o=e[r];if(delete e[r],u.parentNode&&u.parentNode.removeChild(u),o&&o.forEach(e=>e(n)),t)return t(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:u}),12e4);u.onerror=s.bind(null,u.onerror),u.onload=s.bind(null,u.onload),c&&document.head.appendChild(u)}},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 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})(),(()=>{var e={57:0};o.f.j=(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((r,o)=>n=e[t]=[r,o]);r.push(n[2]=i);var a=o.p+o.u(t),u=new Error;o.l(a,r=>{if(o.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;u.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",u.name="ChunkLoadError",u.type=i,u.request=a,n[1](u)}},"chunk-"+t,t)}};var t=(t,r)=>{var n,i,[a,u,c]=r,f=0;if(a.some(t=>0!==e[t])){for(n in u)o.o(u,n)&&(o.m[n]=u[n]);c&&c(o)}for(t&&t(r);f<a.length;f++)i=a[f],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=this.webpackChunkdefra_DefraMap=this.webpackChunkdefra_DefraMap||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var i={};function a(e){return a="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},a(e)}function u(){var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof f?n:f,p=Object.create(u.prototype);return c(p,"_invoke",function(r,n,o){var i,u,c,f=0,p=o||[],l=!1,s={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(t,r){return i=t,u=0,c=e,s.n=r,a}};function d(r,n){for(u=r,c=n,t=0;!l&&f&&!o&&t<p.length;t++){var o,i=p[t],d=s.p,b=i[2];r>3?(o=b===n)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(u=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,u=0))}if(o||r>1)return a;throw l=!0,n}return function(o,p,b){if(f>1)throw TypeError("Generator is already running");for(l&&1===p&&d(p,b),u=p,c=b;(t=u<2?e:c)||!l;){i||(u?u<3?(u>1&&(s.n=-1),d(u,c)):s.n=c:s.v=c);try{if(f=2,i){if(u||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=i.return)&&t.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=e}else if((t=(l=s.n<0)?c:r.call(n,s))!==a)break}catch(t){i=e,u=1,c=t}finally{f=1}}return{value:t,done:l}}}(r,o,i),!0),p}var a={};function f(){}function p(){}function l(){}t=Object.getPrototypeOf;var s=[][n]?t(t([][n]())):(c(t={},n,function(){return this}),t),d=l.prototype=f.prototype=Object.create(s);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return p.prototype=l,c(d,"constructor",l),c(l,"constructor",p),p.displayName="GeneratorFunction",c(l,o,"GeneratorFunction"),c(d),c(d,o,"Generator"),c(d,n,function(){return this}),c(d,"toString",function(){return"[object Generator]"}),(u=function(){return{w:i,m:b}})()}function c(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}c=function(e,t,r,n){function i(t,r){c(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))},c(e,t,r,n)}function f(e,t,r,n,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function p(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 l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function s(e,t,r){return(t=function(e){var t=function(e){if("object"!=a(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=a(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==a(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(){var e,t;return l(l({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(e=u().m(function e(){var t;return u().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.e(568).then(o.bind(o,908));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 a(e){f(i,n,o,a,u,"next",e)}function u(e){f(i,n,o,a,u,"throw",e)}a(void 0)})},function(){return t.apply(this,arguments)})})}return o.d(i,{default:()=>d}),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.drawPlugin=t())}(this,()=>(()=>{"use strict";var e,t,r={738(e){e.exports=preactCompat}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=(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=e=>Promise.all(Object.keys(o.f).reduce((t,r)=>(o.f[r](e,t),t),[])),o.u=e=>({356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[e]+".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,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="defra.drawPlugin:",o.l=(r,n,i,a)=>{if(e[r])e[r].push(n);else{var u,c;if(void 0!==i)for(var f=document.getElementsByTagName("script"),p=0;p<f.length;p++){var l=f[p];if(l.getAttribute("src")==r||l.getAttribute("data-webpack")==t+i){u=l;break}}u||(c=!0,(u=document.createElement("script")).charset="utf-8",o.nc&&u.setAttribute("nonce",o.nc),u.setAttribute("data-webpack",t+i),u.src=r),e[r]=[n];var s=(t,n)=>{u.onerror=u.onload=null,clearTimeout(d);var o=e[r];if(delete e[r],u.parentNode&&u.parentNode.removeChild(u),o&&o.forEach(e=>e(n)),t)return t(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:u}),12e4);u.onerror=s.bind(null,u.onerror),u.onload=s.bind(null,u.onload),c&&document.head.appendChild(u)}},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 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})(),(()=>{var e={57:0};o.f.j=(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((r,o)=>n=e[t]=[r,o]);r.push(n[2]=i);var a=o.p+o.u(t),u=new Error;o.l(a,r=>{if(o.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;u.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",u.name="ChunkLoadError",u.type=i,u.request=a,n[1](u)}},"chunk-"+t,t)}};var t=(t,r)=>{var n,i,[a,u,c]=r,f=0;if(a.some(t=>0!==e[t])){for(n in u)o.o(u,n)&&(o.m[n]=u[n]);c&&c(o)}for(t&&t(r);f<a.length;f++)i=a[f],o.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=this.webpackChunkdefra_DefraMap=this.webpackChunkdefra_DefraMap||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var i={};function a(e){return a="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},a(e)}function u(){var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof f?n:f,p=Object.create(u.prototype);return c(p,"_invoke",function(r,n,o){var i,u,c,f=0,p=o||[],l=!1,s={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function(t,r){return i=t,u=0,c=e,s.n=r,a}};function d(r,n){for(u=r,c=n,t=0;!l&&f&&!o&&t<p.length;t++){var o,i=p[t],d=s.p,b=i[2];r>3?(o=b===n)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(u=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,u=0))}if(o||r>1)return a;throw l=!0,n}return function(o,p,b){if(f>1)throw TypeError("Generator is already running");for(l&&1===p&&d(p,b),u=p,c=b;(t=u<2?e:c)||!l;){i||(u?u<3?(u>1&&(s.n=-1),d(u,c)):s.n=c:s.v=c);try{if(f=2,i){if(u||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=i.return)&&t.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=e}else if((t=(l=s.n<0)?c:r.call(n,s))!==a)break}catch(t){i=e,u=1,c=t}finally{f=1}}return{value:t,done:l}}}(r,o,i),!0),p}var a={};function f(){}function p(){}function l(){}t=Object.getPrototypeOf;var s=[][n]?t(t([][n]())):(c(t={},n,function(){return this}),t),d=l.prototype=f.prototype=Object.create(s);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,c(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return p.prototype=l,c(d,"constructor",l),c(l,"constructor",p),p.displayName="GeneratorFunction",c(l,o,"GeneratorFunction"),c(d),c(d,o,"Generator"),c(d,n,function(){return this}),c(d,"toString",function(){return"[object Generator]"}),(u=function(){return{w:i,m:b}})()}function c(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}c=function(e,t,r,n){function i(t,r){c(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))},c(e,t,r,n)}function f(e,t,r,n,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function p(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 l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function s(e,t,r){return(t=function(e){var t=function(e){if("object"!=a(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=a(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==a(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(){var e,t;return l(l({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(e=u().m(function e(){var t;return u().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.e(568).then(o.bind(o,957));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 a(e){f(i,n,o,a,u,"next",e)}function u(e){f(i,n,o,a,u,"throw",e)}a(void 0)})},function(){return t.apply(this,arguments)})})}return o.d(i,{default:()=>d}),i.default})());
@@ -4,10 +4,11 @@ import { loadDrawAdapter } from './adapters/loadDrawAdapter.js'
4
4
  import { attachEvents } from './events.js'
5
5
  import { useSpatialList } from './hooks/useSpatialList.js'
6
6
  import { APPLICATION_MODE_ID } from './defaults.js'
7
+ import { logger } from '../../../src/services/logger.js'
7
8
 
8
9
  // Loads the draw adapter once the map is ready; tears it down (and releases MapControls' D-pad)
9
10
  // on cleanup.
10
- function useLoadDrawAdapter ({ mapState, pluginConfig, pluginState, mapProvider, eventBus }) {
11
+ function useLoadDrawAdapter ({ mapState, pluginConfig, pluginState, mapProvider, eventBus, symbolRegistry }) {
11
12
  useEffect(() => {
12
13
  if (!mapState.isMapReady) {
13
14
  return undefined
@@ -20,13 +21,14 @@ function useLoadDrawAdapter ({ mapState, pluginConfig, pluginState, mapProvider,
20
21
  snapLayers: pluginConfig.snapLayers,
21
22
  pluginConfig,
22
23
  events: EVENTS,
23
- eventBus
24
+ eventBus,
25
+ symbolRegistry
24
26
  }).then(adapter => {
25
27
  if (!isMounted) { return }
26
28
  mapProvider.draw = adapter
27
29
  pluginState.dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: pluginConfig.snapLayers?.length > 0 })
28
30
  eventBus.emit('draw:ready')
29
- })
31
+ }).catch((error) => logger.error('[draw] failed to load the draw adapter', error))
30
32
 
31
33
  return () => {
32
34
  isMounted = false
@@ -39,7 +41,7 @@ function useLoadDrawAdapter ({ mapState, pluginConfig, pluginState, mapProvider,
39
41
  }
40
42
 
41
43
  export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginState, services, mapProvider, buttonConfig, setApplicationMode, clearApplicationMode }) => {
42
- const { eventBus, hints } = services
44
+ const { eventBus, hints, symbolRegistry } = services
43
45
  const { crossHair } = mapState
44
46
  const isTouchOrKeyboard = ['touch', 'keyboard'].includes(appState.interfaceType)
45
47
 
@@ -51,7 +53,7 @@ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginSt
51
53
  shouldShowCrosshairRef.current = ['draw_polygon', 'draw_line', 'draw_point'].includes(pluginState.mode) &&
52
54
  (isTouchOrKeyboard || appState.expandedButtons?.has('mapControls'))
53
55
 
54
- useLoadDrawAdapter({ mapState, pluginConfig, pluginState, mapProvider, eventBus })
56
+ useLoadDrawAdapter({ mapState, pluginConfig, pluginState, mapProvider, eventBus, symbolRegistry })
55
57
 
56
58
  // Enters the 'draw' application mode (declared in the manifest) in any draw/edit mode, and leaves it
57
59
  // when the draw/edit mode ends. useLayoutEffect so the class lands in the same paint as the change.
@@ -1,3 +1,4 @@
1
+ import { logger } from '../../../src/services/logger.js'
1
2
  import { render, act } from '@testing-library/react'
2
3
  import { EVENTS } from '../../../src/config/events.js'
3
4
  import { DrawInit } from './DrawInit.jsx'
@@ -6,6 +7,7 @@ import { attachEvents } from './events.js'
6
7
  import { useSpatialList } from './hooks/useSpatialList.js'
7
8
 
8
9
  jest.mock('./adapters/loadDrawAdapter.js', () => ({ loadDrawAdapter: jest.fn() }))
10
+ jest.mock('../../../src/services/logger.js', () => ({ logger: { error: jest.fn() } }))
9
11
  jest.mock('./events.js', () => ({ attachEvents: jest.fn(() => jest.fn()) }))
10
12
  jest.mock('./hooks/useSpatialList.js', () => ({ useSpatialList: jest.fn() }))
11
13
 
@@ -23,7 +25,7 @@ const makeProps = (overrides = {}) => {
23
25
  },
24
26
  pluginConfig: { snapLayers: ['a'] },
25
27
  pluginState: { dispatch: jest.fn(), mode: null },
26
- services: { eventBus: { emit: jest.fn() } },
28
+ services: { eventBus: { emit: jest.fn() }, symbolRegistry: { id: 'app-symbol-registry' } },
27
29
  mapProvider: { draw: null },
28
30
  buttonConfig: {},
29
31
  setApplicationMode: jest.fn(),
@@ -38,6 +40,18 @@ const renderInit = async (props) => render(<DrawInit {...props} />)
38
40
  beforeEach(() => jest.clearAllMocks())
39
41
 
40
42
  describe('adapter lifecycle', () => {
43
+ test('logs, rather than leaving unhandled, a failure to load the adapter', async () => {
44
+ const { props } = makeProps()
45
+ const failure = new Error('no adapter for this provider')
46
+ loadDrawAdapter.mockRejectedValueOnce(failure)
47
+
48
+ await renderInit(props)
49
+ await new Promise((resolve) => setTimeout(resolve, 0))
50
+
51
+ expect(logger.error).toHaveBeenCalledWith('[draw] failed to load the draw adapter', failure)
52
+ expect(props.services.eventBus.emit).not.toHaveBeenCalledWith('draw:ready')
53
+ })
54
+
41
55
  test('loads the adapter and announces readiness when the map is ready', async () => {
42
56
  const { props, adapter } = makeProps()
43
57
 
@@ -47,7 +61,9 @@ describe('adapter lifecycle', () => {
47
61
  mapStyle: props.mapState.mapStyle,
48
62
  snapLayers: props.pluginConfig.snapLayers,
49
63
  events: EVENTS,
50
- eventBus: props.services.eventBus
64
+ eventBus: props.services.eventBus,
65
+ // the app's registry, so drawn points see its symbols and defaults
66
+ symbolRegistry: props.services.symbolRegistry
51
67
  }))
52
68
  expect(props.mapProvider.draw).toBe(adapter)
53
69
  expect(props.pluginState.dispatch).toHaveBeenCalledWith({ type: 'SET_HAS_SNAP_LAYERS', payload: true })
@@ -5,8 +5,10 @@ import { MAPBOX_DRAW_EVENTS, CUSTOM_DRAW_EVENTS, STYLE_DATA_EVENT } from './draw
5
5
  import { ADAPTER_EVENTS } from '../../adapterEvents.js'
6
6
  import { createLiveStroke } from '../../validation/liveStroke.js'
7
7
  import { createLiveDrawChecks } from '../../validation/liveDrawChecks.js'
8
- import { resolvePointSymbol, hasSymbolStyle } from './pointSymbolImages.js'
8
+ import { resolvePointSymbol } from './pointSymbolImages.js'
9
+ import { hasSymbol } from '../../../../../src/utils/symbolUtils.js'
9
10
  import { getCoords, getMidpointCoords } from './modes/editVertexMode/geometryHelpers.js'
11
+ import { logger } from '../../../../../src/services/logger.js'
10
12
 
11
13
  const polygonFeature = (coordinates) => ({ type: 'Feature', geometry: { type: 'Polygon', coordinates } })
12
14
  const lineFeature = (coordinates) => ({ type: 'Feature', geometry: { type: 'LineString', coordinates } })
@@ -72,6 +74,7 @@ export class MaplibreDrawAdapter {
72
74
  constructor (mapProvider, options) {
73
75
  this._mapProvider = mapProvider
74
76
  this._map = mapProvider.map
77
+ this._symbolRegistry = options.symbolRegistry
75
78
  this._bus = createEventBus()
76
79
  this._editingFeatureId = null
77
80
  // Assigned once per feature, on creation only (see styles.js's SORT_KEY_PROP) — drives
@@ -81,6 +84,7 @@ export class MaplibreDrawAdapter {
81
84
  const { draw, remove } = createMapboxDraw({
82
85
  mapStyle: options.mapStyle,
83
86
  mapProvider,
87
+ symbolRegistry: options.symbolRegistry,
84
88
  events: options.events,
85
89
  eventBus: options.eventBus,
86
90
  snapLayers: options.snapLayers,
@@ -181,10 +185,12 @@ export class MaplibreDrawAdapter {
181
185
  this._handleModeChange({ mode: name })
182
186
  }
183
187
 
184
- // Resolves and registers the feature's symbol-config icon, then writes the resolved image
185
- // id/anchor back so styles.js's point-symbol layer can render it.
188
+ // Resolves and registers the feature's symbol-config icon in the background, then writes the
189
+ // resolved image id/anchor back so styles.js's point-symbol layer can render it. A failure
190
+ // leaves the point without its icon, so it's logged rather than lost.
186
191
  _resolvePointSymbol (featureId, properties) {
187
- return resolvePointSymbol({ draw: this._draw, mapProvider: this._mapProvider, map: this._map, featureId, properties })
192
+ resolvePointSymbol({ draw: this._draw, mapProvider: this._mapProvider, map: this._map, symbolRegistry: this._symbolRegistry, featureId, properties })
193
+ .catch((error) => logger.error('[draw] failed to resolve point symbol', featureId, error))
188
194
  }
189
195
 
190
196
  // Live invalid-stroke driver, called on every rubber-band move (draw) and vertex drag/nudge
@@ -333,7 +339,7 @@ export class MaplibreDrawAdapter {
333
339
  : feature.properties
334
340
  const withSortKey = { ...feature, properties }
335
341
  const ids = this._draw.add(withSortKey)
336
- if (withSortKey.geometry?.type === 'Point' && hasSymbolStyle(properties)) {
342
+ if (withSortKey.geometry?.type === 'Point' && hasSymbol(properties)) {
337
343
  this._resolvePointSymbol(ids[0], properties)
338
344
  }
339
345
  return ids
@@ -1,7 +1,8 @@
1
1
  import { createMapboxDraw } from './mapboxDraw.js'
2
2
  import { getSnapInstance, clearSnapState, clearSnapIndicator } from './utils/snapHelpers.js'
3
3
  import { createEventBus } from '../../utils/eventBus.js'
4
- import { resolvePointSymbol, hasSymbolStyle } from './pointSymbolImages.js'
4
+ import { resolvePointSymbol } from './pointSymbolImages.js'
5
+ import { logger } from '../../../../../src/services/logger.js'
5
6
  import { MAPBOX_DRAW_EVENTS, CUSTOM_DRAW_EVENTS, STYLE_DATA_EVENT } from './drawEvents.js'
6
7
  import { MaplibreDrawAdapter, displayedShape } from './MaplibreDrawAdapter.js'
7
8
 
@@ -13,16 +14,15 @@ jest.mock('./utils/snapHelpers.js', () => ({
13
14
  }))
14
15
  jest.mock('../../utils/eventBus.js', () => ({ createEventBus: jest.fn() }))
15
16
  jest.mock('./pointSymbolImages.js', () => ({
16
- resolvePointSymbol: jest.fn(),
17
- refreshAllPointSymbols: jest.fn(),
18
- hasSymbolStyle: jest.fn()
17
+ resolvePointSymbol: jest.fn(() => Promise.resolve()),
18
+ refreshAllPointSymbols: jest.fn()
19
19
  }))
20
20
 
21
21
  const SNAP_LAYER = 'snap-helper-circle'
22
22
 
23
23
  const onHandler = (map, event) => map.on.mock.calls.find(([name]) => name === event)?.[1]
24
24
 
25
- const setup = () => {
25
+ const setup = (extraOptions = {}) => {
26
26
  const map = {
27
27
  on: jest.fn(),
28
28
  off: jest.fn(),
@@ -54,7 +54,8 @@ const setup = () => {
54
54
  mapStyle: 'light',
55
55
  events: { MAP_SET_STYLE: 'mss' },
56
56
  eventBus: { on: jest.fn() },
57
- snapLayers: ['layer-a']
57
+ snapLayers: ['layer-a'],
58
+ ...extraOptions
58
59
  }
59
60
  const adapter = new MaplibreDrawAdapter(mapProvider, options)
60
61
 
@@ -78,6 +79,12 @@ describe('construction', () => {
78
79
  })
79
80
  })
80
81
 
82
+ test('passes the app\'s symbol registry through to createMapboxDraw', () => {
83
+ const symbolRegistry = { id: 'app-symbol-registry' }
84
+ setup({ symbolRegistry })
85
+ expect(createMapboxDraw).toHaveBeenCalledWith(expect.objectContaining({ symbolRegistry }))
86
+ })
87
+
81
88
  test('forwards a provided pluginConfig through to createMapboxDraw', () => {
82
89
  const map = {
83
90
  on: jest.fn(),
@@ -621,22 +628,33 @@ describe('simple delegations', () => {
621
628
  test('resolves the symbol for a Point feature with symbol properties, using the id draw.add() returns', () => {
622
629
  const { adapter, draw, map, mapProvider } = setup()
623
630
  draw.add.mockReturnValue(['generated-id'])
624
- hasSymbolStyle.mockReturnValue(true)
625
631
  const feature = { geometry: { type: 'Point', coordinates: [0, 0] }, properties: { symbol: 'pin' } }
626
632
 
627
633
  const result = adapter.add(feature)
628
634
 
629
- expect(hasSymbolStyle).toHaveBeenCalledWith({ symbol: 'pin', sortKey: 1 })
630
635
  expect(resolvePointSymbol).toHaveBeenCalledWith({
631
636
  draw, mapProvider, map, featureId: 'generated-id', properties: { symbol: 'pin', sortKey: 1 }
632
637
  })
633
638
  expect(result).toEqual(['generated-id'])
634
639
  })
635
640
 
641
+ test('logs a failed resolution rather than leaving the rejection unhandled', async () => {
642
+ const { adapter, draw } = setup()
643
+ draw.add.mockReturnValue(['p1'])
644
+ const error = new Error('rasterise failed')
645
+ resolvePointSymbol.mockRejectedValueOnce(error)
646
+ const loggerError = jest.spyOn(logger, 'error').mockImplementation(() => {})
647
+
648
+ adapter.add({ geometry: { type: 'Point', coordinates: [0, 0] }, properties: { symbol: 'pin' } })
649
+ await Promise.resolve()
650
+
651
+ expect(loggerError).toHaveBeenCalledWith('[draw] failed to resolve point symbol', 'p1', error)
652
+ loggerError.mockRestore()
653
+ })
654
+
636
655
  test('does not attempt resolution for a Point with no symbol properties', () => {
637
656
  const { adapter, draw } = setup()
638
657
  draw.add.mockReturnValue(['id-1'])
639
- hasSymbolStyle.mockReturnValue(false)
640
658
  adapter.add({ geometry: { type: 'Point', coordinates: [0, 0] }, properties: {} })
641
659
  expect(resolvePointSymbol).not.toHaveBeenCalled()
642
660
  })
@@ -645,7 +663,6 @@ describe('simple delegations', () => {
645
663
  const { adapter, draw } = setup()
646
664
  draw.add.mockReturnValue(['id-1'])
647
665
  adapter.add({ geometry: { type: 'Polygon', coordinates: [[]] }, properties: { symbol: 'pin' } })
648
- expect(hasSymbolStyle).not.toHaveBeenCalled()
649
666
  expect(resolvePointSymbol).not.toHaveBeenCalled()
650
667
  })
651
668
 
@@ -708,7 +725,6 @@ describe('simple delegations', () => {
708
725
  const feature = { id: 'p1', type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] }, properties: { symbol: 'pin' } }
709
726
  draw.get.mockReturnValue(feature)
710
727
  draw.add.mockReturnValue(['p1'])
711
- hasSymbolStyle.mockReturnValue(true)
712
728
 
713
729
  adapter.setStyle('p1', { symbolBackgroundColor: '#ca3535' })
714
730
 
@@ -13,6 +13,7 @@ import { applyTouchVertexColors } from './modes/editVertexMode/touchHandlers.js'
13
13
  import { resolveColors } from '../../utils/resolveColors.js'
14
14
  import { TOLERANCES, MAP_SIZE_SCALES } from './defaults.js'
15
15
  import { refreshAllPointSymbols } from './pointSymbolImages.js'
16
+ import { logger } from '../../../../../src/services/logger.js'
16
17
 
17
18
  // map.setStyle() discards MapLibre's entire previous Style, wiping every programmatically
18
19
  // added source/layer/image — including mapbox-gl-draw's own, which it never re-adds itself.
@@ -40,7 +41,7 @@ const ensureDrawSourcesAndLayers = (map, draw) => {
40
41
  // actually ran), not MAP_SET_STYLE (fired the instant a change is *requested*, before setStyle
41
42
  // may have run) — registering map.once('idle', ...) too early can catch the map still idle
42
43
  // from the *previous* style and consume itself before the real wipe happens.
43
- const settleStyleChange = ({ map, draw, mapProvider, pluginConfig, onDone }) => {
44
+ const settleStyleChange = ({ map, draw, mapProvider, symbolRegistry, pluginConfig, onDone }) => {
44
45
  const mapStyle = map._drawCurrentMapStyle
45
46
  map.once('idle', () => {
46
47
  const sourcesWereMissing = ensureDrawSourcesAndLayers(map, draw)
@@ -49,7 +50,7 @@ const settleStyleChange = ({ map, draw, mapProvider, pluginConfig, onDone }) =>
49
50
  applyTouchVertexColors(svg, mapStyle, pluginConfig)
50
51
  // Rasterised point symbol images are style-scoped (colours resolve per map style) —
51
52
  // re-resolve every drawn point's icon now the new style has settled.
52
- refreshAllPointSymbols({ draw, mapProvider, map }).then(() => {
53
+ refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry }).then(() => {
53
54
  if (sourcesWereMissing) {
54
55
  // draw's own feature store still holds everything; push it back now the new style's
55
56
  // image ids are resolved — exactly one write, with final data.
@@ -60,13 +61,13 @@ const settleStyleChange = ({ map, draw, mapProvider, pluginConfig, onDone }) =>
60
61
  // cursor's queryRenderedFeatures results) right after a style reload — force it.
61
62
  map.triggerRepaint()
62
63
  onDone()
63
- })
64
+ }).catch((error) => logger.error('[draw] failed to refresh point symbols after a style change', error))
64
65
  })
65
66
  }
66
67
 
67
68
  // Wires MAP_SET_STYLE (stashes the incoming style) and MAP_STYLE_CHANGE (settles it) onto the
68
69
  // event bus. Returns both handlers so createMapboxDraw's remove() can unsubscribe them.
69
- const wireStyleChangeHandling = ({ map, draw, mapProvider, pluginConfig, eventBus, events, notifyPointSymbolsRefreshed }) => {
70
+ const wireStyleChangeHandling = ({ map, draw, mapProvider, symbolRegistry, pluginConfig, eventBus, events, notifyPointSymbolsRefreshed }) => {
70
71
  const handleSetMapStyle = (e) => {
71
72
  map._drawCurrentMapStyle = e
72
73
  }
@@ -84,6 +85,7 @@ const wireStyleChangeHandling = ({ map, draw, mapProvider, pluginConfig, eventBu
84
85
  map,
85
86
  draw,
86
87
  mapProvider,
88
+ symbolRegistry,
87
89
  pluginConfig,
88
90
  onDone: () => {
89
91
  settlePending = false
@@ -112,7 +114,7 @@ const wireStyleChangeHandling = ({ map, draw, mapProvider, pluginConfig, eventBu
112
114
  * @param {Object} [options.pluginConfig] - Plugin-level colour/size overrides — see resolveColors()
113
115
  * @returns {{ draw: MapboxDraw, remove: Function }} draw instance and cleanup function
114
116
  */
115
- export const createMapboxDraw = ({ mapStyle, mapProvider, events, eventBus, snapLayers, pluginConfig = {} }) => {
117
+ export const createMapboxDraw = ({ mapStyle, mapProvider, symbolRegistry, events, eventBus, snapLayers, pluginConfig = {} }) => {
116
118
  const { map } = mapProvider
117
119
 
118
120
  // --- Configure MapLibre GL Draw CSS classes ---
@@ -182,7 +184,7 @@ export const createMapboxDraw = ({ mapStyle, mapProvider, events, eventBus, snap
182
184
 
183
185
  // --- Update colour scheme ---
184
186
  const { handleSetMapStyle, handleStyleChanged } = wireStyleChangeHandling({
185
- map, draw, mapProvider, pluginConfig, eventBus, events, notifyPointSymbolsRefreshed
187
+ map, draw, mapProvider, symbolRegistry, pluginConfig, eventBus, events, notifyPointSymbolsRefreshed
186
188
  })
187
189
 
188
190
  // --- Update map scale ---
@@ -193,12 +195,13 @@ export const createMapboxDraw = ({ mapStyle, mapProvider, events, eventBus, snap
193
195
 
194
196
  // --- Update point symbol resolution for the new pixel ratio ---
195
197
  // MAP_SET_PIXEL_RATIO carries the freshly computed pixel ratio itself, fired right after
196
- // MAP_SET_SIZE — that's the value this needs, not map.getPixelRatio() (unchanged since init).
198
+ // MAP_SET_SIZE — using it directly doesn't depend on the provider's own listener having already
199
+ // applied it to the map.
197
200
  const handleSetPixelRatio = (pixelRatio) => {
198
- refreshAllPointSymbols({ draw, mapProvider, map, pixelRatioOverride: pixelRatio }).then(() => {
201
+ refreshAllPointSymbols({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride: pixelRatio }).then(() => {
199
202
  map.triggerRepaint()
200
203
  notifyPointSymbolsRefreshed()
201
- })
204
+ }).catch((error) => logger.error('[draw] failed to refresh point symbols', error))
202
205
  }
203
206
  eventBus.on(events.MAP_SET_PIXEL_RATIO, handleSetPixelRatio)
204
207
 
@@ -7,6 +7,7 @@ import { applyTouchVertexColors } from './modes/editVertexMode/touchHandlers.js'
7
7
  import { resolveColors } from '../../utils/resolveColors.js'
8
8
  import { TOLERANCES, MAP_SIZE_SCALES } from './defaults.js'
9
9
  import { refreshAllPointSymbols } from './pointSymbolImages.js'
10
+ import { logger } from '../../../../../src/services/logger.js'
10
11
  import { createMapboxDraw } from './mapboxDraw.js'
11
12
 
12
13
  jest.mock('@mapbox/mapbox-gl-draw', () => {
@@ -31,6 +32,7 @@ jest.mock('./modes/drawPolygonMode.js', () => ({ DrawPolygonMode: { id: 'draw_po
31
32
  jest.mock('./modes/drawLineMode.js', () => ({ DrawLineMode: { id: 'draw_line' } }))
32
33
  jest.mock('./modes/drawPointMode.js', () => ({ DrawPointMode: { id: 'draw_point' } }))
33
34
  jest.mock('./pointSymbolImages.js', () => ({ refreshAllPointSymbols: jest.fn(() => Promise.resolve()) }))
35
+ jest.mock('../../../../../src/services/logger.js', () => ({ logger: { error: jest.fn() } }))
34
36
  jest.mock('./styles.js', () => ({
35
37
  createDrawStyles: jest.fn(() => ['style']),
36
38
  updateDrawStyles: jest.fn()
@@ -384,6 +386,22 @@ describe('createMapboxDraw – event handlers', () => {
384
386
  // app calls map.setPixelRatio() off MAP_SET_SIZE alone, so a point-symbol refresh here
385
387
  // would run before the map actually knows about the new size. MAP_SET_PIXEL_RATIO (fired
386
388
  // separately, after MAP_SET_SIZE, carrying the freshly computed value) owns that instead.
389
+ test('logs, rather than leaving unhandled, a failure to refresh point symbols', async () => {
390
+ const { eventBus, map } = setup()
391
+ const failure = new Error('rasterise failed')
392
+
393
+ refreshAllPointSymbols.mockReturnValueOnce(Promise.reject(failure))
394
+ handlerFor(eventBus.on, EVENTS.MAP_SET_PIXEL_RATIO)(2)
395
+ await new Promise((resolve) => setTimeout(resolve, 0))
396
+ expect(logger.error).toHaveBeenCalledWith('[draw] failed to refresh point symbols', failure)
397
+
398
+ refreshAllPointSymbols.mockReturnValueOnce(Promise.reject(failure))
399
+ handlerFor(eventBus.on, EVENTS.MAP_STYLE_CHANGE)()
400
+ handlerFor(map.once, 'idle')()
401
+ await new Promise((resolve) => setTimeout(resolve, 0))
402
+ expect(logger.error).toHaveBeenCalledWith('[draw] failed to refresh point symbols after a style change', failure)
403
+ })
404
+
387
405
  test('MAP_SET_SIZE does not refresh point symbols — MAP_SET_PIXEL_RATIO owns that', () => {
388
406
  const { eventBus } = setup()
389
407
  handlerFor(eventBus.on, EVENTS.MAP_SET_SIZE)('medium')
@@ -1,6 +1,5 @@
1
- import { symbolRegistry } from '../../../../../src/services/symbolRegistry.js'
2
- import { getSymbolAnchor, getSymbolViewBox } from '../../../../../src/utils/symbolUtils.js'
3
- import { anchorToMaplibre, anchorToMaplibreOffset } from '../../../../../providers/maplibre/src/utils/symbolImages.js'
1
+ import { logger } from '../../../../../src/services/logger.js'
2
+ import { hasSymbol } from '../../../../../src/utils/symbolUtils.js'
4
3
 
5
4
  /**
6
5
  * Resolves and registers a drawn point's symbol-config icon (same schema as addMarker/dataset
@@ -9,9 +8,8 @@ import { anchorToMaplibre, anchorToMaplibreOffset } from '../../../../../provide
9
8
  * separately below since it can't safely be a per-feature property.
10
9
  */
11
10
 
12
- export const hasSymbolStyle = (properties) => !!(properties?.symbol || properties?.symbolSvgContent)
13
-
14
11
  const POINT_SYMBOL_LAYER_ID = 'point-symbol'
12
+ const POINT_SYMBOL_LAYER_IDS = new Set([`${POINT_SYMBOL_LAYER_ID}.hot`, `${POINT_SYMBOL_LAYER_ID}.cold`])
15
13
 
16
14
  // icon-offset can't be a raw per-feature `get` on an array property — MapLibre's GeoJSON
17
15
  // sources silently JSON.stringify arrays, so it reads back a string at render time. Instead
@@ -25,67 +23,90 @@ const buildIconOffsetExpression = (offsetsByImageId) => {
25
23
  return expression
26
24
  }
27
25
 
28
- const registerSymbolIconOffset = (map, symbolImageId, offset) => {
29
- map._symbolIconOffsetMap ??= {}
30
- if (map._symbolIconOffsetMap[symbolImageId]) {
31
- return // offset is deterministic per id — already registered, nothing changed
32
- }
33
- map._symbolIconOffsetMap[symbolImageId] = offset
26
+ // Written to both the live layers and draw.options.styles — the definitions mapbox-gl-draw
27
+ // builds its layers from, and that mapboxDraw.js's ensureDrawSourcesAndLayers re-adds them
28
+ // from after a style change. Without the latter, any rebuild (or a point resolved before the
29
+ // layers first exist) would leave the layers on pointSymbol()'s [0, 0] default.
30
+ const applyIconOffsetExpression = (map, draw) => {
34
31
  const expression = buildIconOffsetExpression(map._symbolIconOffsetMap)
35
- ;['hot', 'cold'].forEach((suffix) => {
36
- const layerId = `${POINT_SYMBOL_LAYER_ID}.${suffix}`
32
+ draw.options?.styles?.forEach((style) => {
33
+ if (POINT_SYMBOL_LAYER_IDS.has(style.id)) {
34
+ style.layout = { ...style.layout, 'icon-offset': expression }
35
+ }
36
+ })
37
+ POINT_SYMBOL_LAYER_IDS.forEach((layerId) => {
37
38
  if (map.getLayer(layerId)) {
38
39
  map.setLayoutProperty(layerId, 'icon-offset', expression)
39
40
  }
40
41
  })
41
42
  }
42
43
 
43
- // map.getPixelRatio() is only set once at map construction, so it won't reflect a later
44
- // map-size change on its own. Callers reacting to MAP_SET_PIXEL_RATIO should pass the fresh
45
- // value through as pixelRatioOverride instead.
44
+ const registerSymbolIconOffset = (map, draw, symbolImageId, offset) => {
45
+ map._symbolIconOffsetMap ??= {}
46
+ if (map._symbolIconOffsetMap[symbolImageId]) {
47
+ return // offset is deterministic per id — already registered, nothing changed
48
+ }
49
+ map._symbolIconOffsetMap[symbolImageId] = offset
50
+ applyIconOffsetExpression(map, draw)
51
+ }
52
+
53
+ // A style or pixel-ratio change gives every point a new image id, so the old ids' offsets are
54
+ // dead weight in the match expression — drop any id no drawn point uses any more.
55
+ const pruneSymbolIconOffsets = (map, draw) => {
56
+ const offsets = map._symbolIconOffsetMap
57
+ if (!offsets) {
58
+ return
59
+ }
60
+ const inUse = new Set(draw.getAll().features.map((feature) => feature.properties?.symbolImageId))
61
+ const unused = Object.keys(offsets).filter((imageId) => !inUse.has(imageId))
62
+ if (!unused.length) {
63
+ return
64
+ }
65
+ unused.forEach((imageId) => delete offsets[imageId])
66
+ applyIconOffsetExpression(map, draw)
67
+ }
68
+
69
+ // The map's current pixel ratio (device pixel ratio × map-size scale factor). Callers reacting to
70
+ // MAP_SET_PIXEL_RATIO pass the event's value through as pixelRatioOverride instead, so they don't
71
+ // depend on the provider's listener having applied it to the map first.
46
72
  export const getPixelRatio = (map) => map.getPixelRatio?.() || 1
47
73
 
48
74
  // Does the async work for one point without touching the store — draw.add() is left to the
49
75
  // caller so refreshAllPointSymbols can batch every point into one call (see its comment why).
50
76
  // Returns null if there's nothing to write back (no symbol config, feature gone, or unresolvable id).
51
- const resolvePointSymbolFeature = async ({ draw, mapProvider, map, featureId, properties, pixelRatioOverride }) => {
52
- if (!hasSymbolStyle(properties)) {
77
+ const resolvePointSymbolFeature = async ({ draw, mapProvider, map, symbolRegistry, featureId, properties, pixelRatioOverride }) => {
78
+ if (!hasSymbol(properties)) {
53
79
  return null
54
80
  }
55
81
 
56
82
  const mapStyle = map._drawCurrentMapStyle
57
83
  const pixelRatio = pixelRatioOverride ?? getPixelRatio(map)
58
84
 
59
- await mapProvider.addSymbolsToMap([properties], mapStyle, symbolRegistry)
85
+ await mapProvider.addSymbolsToMap([properties], mapStyle, symbolRegistry, pixelRatio)
60
86
 
61
87
  const feature = draw.get(featureId)
62
88
  if (!feature) {
63
89
  return null
64
90
  }
65
91
 
66
- const symbolImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, false, pixelRatio)
92
+ const symbolImageId = symbolRegistry.getSymbolImageId(properties, mapStyle, 'normal', pixelRatio)
67
93
  if (!symbolImageId) {
68
94
  return null
69
95
  }
70
- // addSymbolsToMap() (just awaited above) already mapped this id's active/selected variants
71
- // into map._activeSymbolImageMap/_selectedSymbolImageMap — read them back so the highlight
72
- // ring (highlightFeatures.js) can reference each point's own precomputed variant directly.
73
- const symbolActiveImageId = map._activeSymbolImageMap?.[symbolImageId] ?? null
74
- const symbolSelectedImageId = map._selectedSymbolImageMap?.[symbolImageId] ?? null
75
- const symbolDef = symbolRegistry.getSymbolDef(properties)
76
- const rawAnchor = getSymbolAnchor(properties, symbolDef)
77
- const anchor = anchorToMaplibre(rawAnchor)
78
- // icon-anchor only has 9 discrete positions, so an off-grid anchor (e.g. pin's [0.5, 0.9])
79
- // loses precision snapping to the nearest one — icon-offset corrects that gap.
80
- const offset = anchorToMaplibreOffset(rawAnchor, getSymbolViewBox(properties, symbolDef))
81
- registerSymbolIconOffset(map, symbolImageId, offset)
96
+ // addSymbolsToMap() (just awaited above) also registered this id's active/selected variants —
97
+ // read them back so the highlight ring (highlightFeatures.js) can reference each point's own
98
+ // precomputed variant directly.
99
+ const symbolActiveImageId = mapProvider.getActiveSymbolImageId(symbolImageId)
100
+ const symbolSelectedImageId = mapProvider.getSelectedSymbolImageId(symbolImageId)
101
+ const iconLayout = mapProvider.getSymbolIconLayout(symbolRegistry.getSymbolDef(properties))
102
+ registerSymbolIconOffset(map, draw, symbolImageId, iconLayout['icon-offset'])
82
103
 
83
104
  return {
84
105
  ...feature,
85
106
  properties: {
86
107
  ...properties,
87
108
  symbolImageId,
88
- symbolIconAnchor: anchor,
109
+ symbolIconAnchor: iconLayout['icon-anchor'],
89
110
  symbolActiveImageId,
90
111
  symbolSelectedImageId
91
112
  }
@@ -98,29 +119,24 @@ const resolvePointSymbolFeature = async ({ draw, mapProvider, map, featureId, pr
98
119
  *
99
120
  * @param {Object} params
100
121
  * @param {Object} params.draw - the raw MapboxDraw instance (needs get/add)
101
- * @param {Object} params.mapProvider - MapLibreProvider (needs addSymbolsToMap)
122
+ * @param {Object} params.mapProvider - MapLibreProvider (needs addSymbolsToMap, getActiveSymbolImageId, getSelectedSymbolImageId, getSymbolIconLayout)
102
123
  * @param {Object} params.map - MapLibre map instance (needs _drawCurrentMapStyle, getPixelRatio)
124
+ * @param {Object} params.symbolRegistry - the app's symbol registry (services.symbolRegistry)
103
125
  * @param {string} params.featureId
104
126
  * @param {Object} params.properties - the point feature's current properties
105
127
  * @param {number} [params.pixelRatioOverride] - use this instead of map.getPixelRatio(), for
106
128
  * callers (map-size refresh) that already know the freshly computed value
107
- * @returns {Promise<void>}
129
+ * @returns {Promise<void>} rejects if the symbol's images couldn't be registered
108
130
  */
109
131
  export const resolvePointSymbol = async (params) => {
110
- try {
111
- const feature = await resolvePointSymbolFeature(params)
112
- if (!feature) {
113
- return
114
- }
115
- // draw.setFeatureProperty() only marks the feature dirty for mapbox-gl-draw's own mode-
116
- // dispatch loop, which won't run again until the next interaction. draw.add() on an
117
- // existing id updates its properties and renders unconditionally, so it's used instead.
118
- params.draw.add(feature)
119
- } catch (err) {
120
- // A silent failure here means a point simply never gets/keeps an icon, with nothing in
121
- // the UI to explain why — surface it instead of letting the rejection vanish.
122
- console.error('[draw] failed to resolve point symbol', params.featureId, err) // NOSONAR
132
+ const feature = await resolvePointSymbolFeature(params)
133
+ if (!feature) {
134
+ return
123
135
  }
136
+ // draw.setFeatureProperty() only marks the feature dirty for mapbox-gl-draw's own mode-
137
+ // dispatch loop, which won't run again until the next interaction. draw.add() on an
138
+ // existing id updates its properties and renders unconditionally, so it's used instead.
139
+ params.draw.add(feature)
124
140
  }
125
141
 
126
142
  /**
@@ -131,28 +147,37 @@ export const resolvePointSymbol = async (params) => {
131
147
  * @param {Object} params.draw - the raw MapboxDraw instance (needs getAll)
132
148
  * @param {Object} params.mapProvider
133
149
  * @param {Object} params.map
150
+ * @param {Object} params.symbolRegistry
134
151
  * @param {number} [params.pixelRatioOverride] - see resolvePointSymbol
135
152
  * @returns {Promise<void>}
136
153
  */
137
- export const refreshAllPointSymbols = async ({ draw, mapProvider, map, pixelRatioOverride }) => {
154
+ export const refreshAllPointSymbols = async ({ draw, mapProvider, map, symbolRegistry, pixelRatioOverride }) => {
155
+ // Refreshes overlap when the map size or style changes again before one finishes; only the
156
+ // latest may write back, so an older one finishing last can't restore its stale image ids
157
+ map._pointSymbolRefreshId = (map._pointSymbolRefreshId ?? 0) + 1
158
+ const refreshId = map._pointSymbolRefreshId
138
159
  const points = draw.getAll().features.filter(
139
- (f) => f.geometry.type === 'Point' && hasSymbolStyle(f.properties)
160
+ (feature) => feature.geometry.type === 'Point' && hasSymbol(feature.properties)
140
161
  )
141
- const results = await Promise.allSettled(points.map((f) =>
142
- resolvePointSymbolFeature({ draw, mapProvider, map, featureId: f.id, properties: f.properties, pixelRatioOverride })
162
+ const results = await Promise.allSettled(points.map((feature) =>
163
+ resolvePointSymbolFeature({ draw, mapProvider, map, symbolRegistry, featureId: feature.id, properties: feature.properties, pixelRatioOverride })
143
164
  ))
144
165
 
145
- results.filter((r) => r.status === 'rejected').forEach((r) => {
146
- console.error('[draw] failed to resolve point symbol', r.reason) // NOSONAR
166
+ results.filter((result) => result.status === 'rejected').forEach((result) => {
167
+ logger.error('[draw] failed to resolve point symbol', result.reason)
147
168
  })
169
+ if (map._pointSymbolRefreshId !== refreshId) {
170
+ return
171
+ }
148
172
 
149
173
  // One combined draw.add() call triggers a single render. Adding one point at a time here
150
174
  // would let mapbox-gl-draw's debounced render fire mid-batch, painting a not-yet-resolved
151
175
  // point with its stale, now-unregistered image id ("Image X could not be loaded").
152
176
  const features = results
153
- .filter((r) => r.status === 'fulfilled' && r.value)
154
- .map((r) => r.value)
177
+ .filter((result) => result.status === 'fulfilled' && result.value)
178
+ .map((result) => result.value)
155
179
  if (features.length) {
156
180
  draw.add({ type: 'FeatureCollection', features })
157
181
  }
182
+ pruneSymbolIconOffsets(map, draw)
158
183
  }