@defra/interactive-map 0.0.58-alpha → 0.0.60-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 (140) hide show
  1. package/assets/templates/add-polygons.njk +2 -2
  2. package/assets/templates/add-symbols.njk +2 -2
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/panel-definition.md +30 -0
  9. package/docs/api/symbol-config.md +12 -0
  10. package/docs/api.md +21 -2
  11. package/docs/assets/images/slot-map.svg +3 -3
  12. package/docs/plugins/datasets.md +11 -1
  13. package/docs/plugins/draw.md +95 -13
  14. package/package.json +1 -1
  15. package/plugins/datasets/dist/esm/index.js +1 -1
  16. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  17. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  18. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  20. package/plugins/datasets/dist/umd/index.js +1 -1
  21. package/plugins/datasets/src/index.js +0 -1
  22. package/plugins/datasets/src/index.test.js +2 -8
  23. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  24. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  25. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  26. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  27. package/plugins/draw/dist/esm/index.js +1 -1
  28. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  29. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  30. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  31. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  32. package/plugins/draw/dist/umd/index.js +1 -1
  33. package/plugins/draw/src/adapterEvents.js +2 -0
  34. package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
  35. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
  36. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  37. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
  38. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
  39. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
  40. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
  41. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
  42. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
  43. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
  44. package/plugins/draw/src/api/addFeature.js +9 -6
  45. package/plugins/draw/src/api/addFeature.test.js +37 -10
  46. package/plugins/draw/src/api/editFeature.js +1 -1
  47. package/plugins/draw/src/api/recheckGeometry.js +1 -1
  48. package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
  49. package/plugins/draw/src/api/setProperties.js +39 -0
  50. package/plugins/draw/src/api/setProperties.test.js +74 -0
  51. package/plugins/draw/src/api/setStyle.js +16 -19
  52. package/plugins/draw/src/api/setStyle.test.js +17 -2
  53. package/plugins/draw/src/api/split.js +7 -4
  54. package/plugins/draw/src/api/split.test.js +25 -2
  55. package/plugins/draw/src/events.js +95 -53
  56. package/plugins/draw/src/events.test.js +425 -6
  57. package/plugins/draw/src/manifest.js +6 -4
  58. package/plugins/draw/src/manifest.test.js +20 -26
  59. package/plugins/draw/src/reducer.js +7 -0
  60. package/plugins/draw/src/reducer.test.js +11 -0
  61. package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
  62. package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
  63. package/plugins/draw/src/utils/isPlainObject.js +14 -0
  64. package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
  65. package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
  66. package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
  67. package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
  68. package/plugins/draw/src/validation/commitChecks.js +29 -11
  69. package/plugins/draw/src/validation/commitChecks.test.js +67 -11
  70. package/plugins/draw/src/validation/validateGeometry.js +12 -5
  71. package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
  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/map-key/dist/esm/im-map-key-plugin.js +1 -1
  75. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  76. package/plugins/search/dist/css/index.css +1 -1
  77. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  78. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  79. package/providers/esri/src/esriProvider.js +10 -21
  80. package/providers/esri/src/utils/coords.js +37 -7
  81. package/providers/esri/src/utils/coords.test.js +22 -1
  82. package/providers/esri/src/utils/spatial.js +1 -47
  83. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  84. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  85. package/providers/maplibre/src/maplibreProvider.js +5 -14
  86. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  87. package/providers/maplibre/src/utils/spatial.js +0 -40
  88. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  89. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  90. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  91. package/providers/openlayers/src/openlayersProvider.js +5 -14
  92. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  93. package/providers/openlayers/src/utils/spatial.js +0 -39
  94. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  95. package/src/App/components/Hints/Hints.jsx +9 -21
  96. package/src/App/components/Hints/Hints.test.jsx +20 -33
  97. package/src/App/components/Panel/Panel.jsx +16 -1
  98. package/src/App/components/Panel/Panel.test.jsx +44 -0
  99. package/src/App/hooks/useCrossHairAPI.js +27 -28
  100. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  101. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  102. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  103. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  104. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  105. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  106. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  107. package/src/App/hooks/useVisibleGeometry.js +35 -45
  108. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  109. package/src/App/layout/Layout.jsx +4 -4
  110. package/src/App/layout/layout.module.scss +124 -61
  111. package/src/App/store/AppProvider.jsx +3 -0
  112. package/src/App/store/MapProvider.jsx +1 -0
  113. package/src/App/store/MapProvider.test.jsx +25 -0
  114. package/src/App/store/appDispatchMiddleware.js +18 -10
  115. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  116. package/src/App/store/mapActionsMap.js +6 -0
  117. package/src/App/store/mapActionsMap.test.js +7 -0
  118. package/src/App/store/mapReducer.js +2 -0
  119. package/src/App/store/mapReducer.test.js +2 -0
  120. package/src/InteractiveMap/InteractiveMap.js +3 -2
  121. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  122. package/src/config/events.js +1 -1
  123. package/src/config/mapPanelSlots.js +8 -0
  124. package/src/config/symbolConfig.js +1 -1
  125. package/src/services/symbolRegistry.js +1 -1
  126. package/src/services/symbolRegistry.test.js +19 -0
  127. package/src/types.js +29 -8
  128. package/src/utils/getFitMove.js +73 -0
  129. package/src/utils/getFitMove.test.js +114 -0
  130. package/src/utils/getSafeZoneInset.js +122 -77
  131. package/src/utils/getSafeZoneInset.test.js +241 -54
  132. package/src/utils/getValueForStyle.js +10 -5
  133. package/src/utils/getValueForStyle.test.js +13 -2
  134. package/src/utils/renderedBoxes.js +25 -0
  135. package/src/utils/renderedBoxes.test.js +61 -0
  136. package/src/utils/screenBox.js +70 -0
  137. package/src/utils/screenBox.test.js +69 -0
  138. package/src/utils/symbolUtils.js +9 -9
  139. package/src/utils/symbolUtils.test.js +21 -0
  140. package/providers/esri/src/utils/spatial.test.js +0 -58
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("defra",[],e):"object"==typeof exports?exports.defra=e():(t.defra=t.defra||{},t.defra.drawPlugin=e())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var t,e,r={738:function(t){t.exports=preactCompat}},n={};function o(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=function(t,e){for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=function(t){return Promise.all(Object.keys(o.f).reduce(function(e,r){return o.f[r](t,e),e},[]))},o.u=function(t){return{356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[t]+".js"},o.miniCssF=function(t){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t={},e="defra.drawPlugin:",o.l=function(r,n,i,u){if(t[r])t[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==r||p.getAttribute("data-webpack")==e+i){c=p;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",e+i),c.src=r),t[r]=[n];var s=function(e,n){c.onerror=c.onload=null,clearTimeout(d);var o=t[r];if(delete t[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(t){return t(n)}),e)return e(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=s.bind(null,c.onerror),c.onload=s.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},function(){var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t}(),function(){var t={57:0};o.f.j=function(e,r){var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=t[e]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(e),c=new Error;o.l(u,function(r){if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+e,e)}};var e=function(e,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(e){return 0!==t[e]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(e&&e(r);f<u.length;f++)i=u[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))}();var i={};function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof f?n:f,l=Object.create(c.prototype);return a(l,"_invoke",function(r,n,o){var i,c,a,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,c=0,a=t,s.n=r,u}};function d(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<l.length;e++){var o,i=l[e],d=s.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),c=l,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=s.n<0)?a:r.call(n,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),l}var u={};function f(){}function l(){}function p(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),d=p.prototype=f.prototype=Object.create(s);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t}return l.prototype=p,a(d,"constructor",p),a(p,"constructor",l),l.displayName="GeneratorFunction",a(p,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,n,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:b}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function f(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(){var t,e;return p(p({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=c().m(function t(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,o.e(568).then(o.bind(o,362));case 1:return e=t.v.manifest,t.a(2,e)}},t)}),e=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){f(i,n,o,u,c,"next",t)}function c(t){f(i,n,o,u,c,"throw",t)}u(void 0)})},function(){return e.apply(this,arguments)})})}return o.d(i,{default:function(){return d}}),i.default}()});
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("defra",[],e):"object"==typeof exports?exports.defra=e():(t.defra=t.defra||{},t.defra.drawPlugin=e())}(Object("undefined"!=typeof self?self:this),function(){return function(){"use strict";var t,e,r={738:function(t){t.exports=preactCompat}},n={};function o(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,o),i.exports}o.m=r,o.d=function(t,e){for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=function(t){return Promise.all(Object.keys(o.f).reduce(function(e,r){return o.f[r](t,e),e},[]))},o.u=function(t){return{356:"im-draw-ml-adapter",568:"im-draw-plugin",722:"im-draw-ol-adapter"}[t]+".js"},o.miniCssF=function(t){},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t={},e="defra.drawPlugin:",o.l=function(r,n,i,u){if(t[r])t[r].push(n);else{var c,a;if(void 0!==i)for(var f=document.getElementsByTagName("script"),l=0;l<f.length;l++){var p=f[l];if(p.getAttribute("src")==r||p.getAttribute("data-webpack")==e+i){c=p;break}}c||(a=!0,(c=document.createElement("script")).charset="utf-8",o.nc&&c.setAttribute("nonce",o.nc),c.setAttribute("data-webpack",e+i),c.src=r),t[r]=[n];var s=function(e,n){c.onerror=c.onload=null,clearTimeout(d);var o=t[r];if(delete t[r],c.parentNode&&c.parentNode.removeChild(c),o&&o.forEach(function(t){return t(n)}),e)return e(n)},d=setTimeout(s.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=s.bind(null,c.onerror),c.onload=s.bind(null,c.onload),a&&document.head.appendChild(c)}},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},function(){var t;o.g.importScripts&&(t=o.g.location+"");var e=o.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=t}(),function(){var t={57:0};o.f.j=function(e,r){var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise(function(r,o){n=t[e]=[r,o]});r.push(n[2]=i);var u=o.p+o.u(e),c=new Error;o.l(u,function(r){if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+i+": "+u+")",c.name="ChunkLoadError",c.type=i,c.request=u,n[1](c)}},"chunk-"+e,e)}};var e=function(e,r){var n,i,u=r[0],c=r[1],a=r[2],f=0;if(u.some(function(e){return 0!==t[e]})){for(n in c)o.o(c,n)&&(o.m[n]=c[n]);a&&a(o)}for(e&&e(r);f<u.length;f++)i=u[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap=Object("undefined"!=typeof self?self:this).webpackChunkdefra_DefraMap||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))}();var i={};function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof f?n:f,l=Object.create(c.prototype);return a(l,"_invoke",function(r,n,o){var i,c,a,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return i=e,c=0,a=t,s.n=r,u}};function d(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<l.length;e++){var o,i=l[e],d=s.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,s.v=n,s.n=i[1]):d<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,s.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,l,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&d(l,b),c=l,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=s.n<0)?a:r.call(n,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),l}var u={};function f(){}function l(){}function p(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(a(e={},n,function(){return this}),e),d=p.prototype=f.prototype=Object.create(s);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t}return l.prototype=p,a(d,"constructor",p),a(p,"constructor",l),l.displayName="GeneratorFunction",a(p,o,"GeneratorFunction"),a(d),a(d,o,"Generator"),a(d,n,function(){return this}),a(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:b}})()}function a(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}a=function(t,e,r,n){function i(e,r){a(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},a(t,e,r,n)}function f(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){s(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(){var t,e;return p(p({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(t=c().m(function t(){var e;return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,o.e(568).then(o.bind(o,806));case 1:return e=t.v.manifest,t.a(2,e)}},t)}),e=function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function u(t){f(i,n,o,u,c,"next",t)}function c(t){f(i,n,o,u,c,"throw",t)}u(void 0)})},function(){return e.apply(this,arguments)})})}return o.d(i,{default:function(){return d}}),i.default}()});
@@ -88,6 +88,8 @@ export const CHANGE_PHASE = 'change'
88
88
  * @property {boolean} [recheckOnFinish] - deprecated, use onGeometryFinish.
89
89
  * `onGeometryChange` only: don't reuse this result when the shape is finished, check
90
90
  * it again with phase 'create' or 'edit-finish'
91
+ * @property {object} [properties] - `onGeometryFinish` only, on a passing result: merged
92
+ * into the finished shape's properties (utils/mergeFeatureProperties.js)
91
93
  */
92
94
 
93
95
  /**
@@ -25,6 +25,7 @@ const CONTRACT_METHODS = [
25
25
  'setSnapLayers',
26
26
  'isSnapEnabled',
27
27
  'setFeatureProperty',
28
+ 'setProperties',
28
29
  'setCanFinish',
29
30
  'setInvalid',
30
31
  'on',
@@ -7,6 +7,7 @@ import { createLiveStroke } from '../../validation/liveStroke.js'
7
7
  import { createLiveDrawChecks } from '../../validation/liveDrawChecks.js'
8
8
  import { resolvePointSymbol } from './pointSymbolImages.js'
9
9
  import { hasSymbol } from '../../../../../src/utils/symbolUtils.js'
10
+ import { definedOnly } from '../../utils/flattenStyleProperties.js'
10
11
  import { getCoords, getMidpointCoords } from './modes/editVertexMode/geometryHelpers.js'
11
12
  import { logger } from '../../../../../src/services/logger.js'
12
13
 
@@ -65,7 +66,7 @@ export const displayedShape = (mode, coordinates) => {
65
66
  * nudgeSelectedVertex(dx, dy, isLargeStep)
66
67
  * getVertexItems() / selectVertex(index) / insertVertexAtMidpoint(index)
67
68
  * setGeometry(geometry)
68
- * get(id) / add(feature) / setStyle(id, properties) / delete(id) / deleteAll()
69
+ * get(id) / add(feature) / setStyle(id, properties) / setProperties(id, properties) / delete(id) / deleteAll()
69
70
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
70
71
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
71
72
  * on(event, handler) / off(event, handler)
@@ -354,13 +355,14 @@ export class MaplibreDrawAdapter {
354
355
  }
355
356
 
356
357
  // Patches an existing feature's style properties and re-renders via add(), so a Point's
357
- // icon gets re-resolved the same way a directly-added one does.
358
+ // icon gets re-resolved the same way a directly-added one does. A key patched to undefined
359
+ // is removed — add() replaces the feature's properties as a whole.
358
360
  setStyle (id, properties) {
359
361
  const feature = this._draw.get(id)
360
362
  if (!feature) {
361
363
  return
362
364
  }
363
- this.add({ ...feature, properties: { ...feature.properties, ...properties } })
365
+ this.add({ ...feature, properties: definedOnly({ ...feature.properties, ...properties }) })
364
366
  }
365
367
 
366
368
  delete (id) { this._draw.delete(id) }
@@ -397,6 +399,16 @@ export class MaplibreDrawAdapter {
397
399
  this._draw.setFeatureProperty(id, property, value)
398
400
  }
399
401
 
402
+ // Merges data properties into an existing feature (a shallow merge; setStyle handles style).
403
+ // Written in place rather than re-added like setStyle, so it's safe while the feature is
404
+ // still in an edit mode.
405
+ setProperties (id, properties) {
406
+ if (!this._draw.get(id)) { return }
407
+ for (const [key, value] of Object.entries(properties)) {
408
+ this._draw.setFeatureProperty(id, key, value)
409
+ }
410
+ }
411
+
400
412
  // Tags the in-progress rubber-band feature (no stable id yet) with a property and
401
413
  // re-renders — used for live preview styling, e.g. split's valid/invalid line colour.
402
414
  setDrawingPreviewProperty (property, value) {
@@ -743,6 +743,16 @@ describe('simple delegations', () => {
743
743
  }))
744
744
  })
745
745
 
746
+ test('removes a key patched to undefined', () => {
747
+ const { adapter, draw } = setup()
748
+ draw.get.mockReturnValue({ id: 'a', type: 'Feature', geometry: { type: 'Polygon', coordinates: [[]] }, properties: { stroke: 'red', strokeDark: 'tan', sortKey: 7 } })
749
+ draw.add.mockReturnValue(['a'])
750
+
751
+ adapter.setStyle('a', { stroke: 'blue', strokeDark: undefined })
752
+
753
+ expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({ properties: { stroke: 'blue', sortKey: 7 } }))
754
+ })
755
+
746
756
  test('does nothing for an id with no existing feature', () => {
747
757
  const { adapter, draw } = setup()
748
758
  draw.get.mockReturnValue(undefined)
@@ -751,6 +761,23 @@ describe('simple delegations', () => {
751
761
  })
752
762
  })
753
763
 
764
+ describe('setProperties()', () => {
765
+ test('writes each property in place, without re-adding the feature', () => {
766
+ const { adapter, draw } = setup()
767
+ adapter.setProperties('a', { name: 'North field', ref: null })
768
+ expect(draw.setFeatureProperty).toHaveBeenCalledWith('a', 'name', 'North field')
769
+ expect(draw.setFeatureProperty).toHaveBeenCalledWith('a', 'ref', null)
770
+ expect(draw.add).not.toHaveBeenCalled()
771
+ })
772
+
773
+ test('does nothing for an id with no existing feature', () => {
774
+ const { adapter, draw } = setup()
775
+ draw.get.mockReturnValue(undefined)
776
+ adapter.setProperties('missing', { name: 'x' })
777
+ expect(draw.setFeatureProperty).not.toHaveBeenCalled()
778
+ })
779
+ })
780
+
754
781
  test('setDrawingPreviewProperty tags the in-progress feature and re-renders', () => {
755
782
  const { adapter, map } = setup()
756
783
  const render = jest.fn()
@@ -3,6 +3,7 @@ import { isActiveFeature } from '../../../../../../../node_modules/@mapbox/mapbo
3
3
  import {
4
4
  getSnapInstance, isSnapEnabled, getSnapLngLat, triggerSnapAtPoint, clearSnapState, setAutoSnapSuspended
5
5
  } from '../../utils/snapHelpers.js'
6
+ import { handleEditModeDrag } from '../../utils/editModeEvents.js'
6
7
  import { validatePlacement, toPlacementBlocked } from '../../../../validation/validateGeometry.js'
7
8
 
8
9
  const MODE = 'edit_point'
@@ -87,27 +88,15 @@ export const pointerHandlers = {
87
88
  return current[0] !== state._moveStartPosition[0] || current[1] !== state._moveStartPosition[1]
88
89
  },
89
90
 
91
+ // Without an active snap, selectedCoordPaths is [] for a point (see editPointMode.js), so
92
+ // DirectSelect.onDrag routes the drag to dragFeature, its built-in whole-feature delta move,
93
+ // which already handles a Point feature correctly.
90
94
  onDrag (state, e) {
91
- if (state.interfaceType === 'touch') {
92
- return
93
- }
94
-
95
- this.map.fire('draw.geometrychange', state.feature)
96
-
97
- const snap = getSnapInstance(this.map)
98
- if (snap) {
99
- snap.snapStatus = false
100
- snap.snapCoords = null
101
- }
102
-
103
- if (!isSnapEnabled(state) || !snap?.status) {
104
- // selectedCoordPaths is [] for a point (see editPointMode.js) — DirectSelect.onDrag's
105
- // own selectedCoordPaths.length > 0 check routes this to dragFeature, its built-in
106
- // whole-feature delta move, which already handles a Point feature correctly.
107
- DirectSelect.onDrag.call(this, state, e)
108
- return
109
- }
95
+ handleEditModeDrag(this, state, e, this._snapDrag)
96
+ },
110
97
 
98
+ // Moves the point to the snapped position
99
+ _snapDrag (state, e, snap) {
111
100
  if (!state.canDragMove) {
112
101
  return
113
102
  }
@@ -101,6 +101,26 @@ describe('pointerHandlers', () => {
101
101
  expect(map._undoStack).toHaveLength(0)
102
102
  })
103
103
 
104
+ test('onDrag that pans the map (point not grabbed) fires no geometrychange, with or without snap', () => {
105
+ const { ctx, state, map } = createHarness()
106
+ state.canDragMove = false
107
+ ctx.onDrag(state, dragEvt(2, 2))
108
+ state.getSnapEnabled = () => true
109
+ map._snapInstance = { status: true, snapStatus: false, snapCoords: null, snapToClosestPoint: jest.fn() }
110
+ ctx.onDrag(state, dragEvt(3, 3))
111
+ expect(map.fire).not.toHaveBeenCalledWith('draw.geometrychange', expect.anything())
112
+ expect(state.feature.coordinates).toEqual([5, 5])
113
+ })
114
+
115
+ test('onDrag fires geometrychange after the point moves, carrying the new position', () => {
116
+ const { ctx, state, map } = createHarness()
117
+ Object.assign(state, { canDragMove: true, dragMoveLocation: { lng: 0, lat: 0 } })
118
+ const fired = []
119
+ map.on('draw.geometrychange', (feature) => fired.push([...feature.coordinates]))
120
+ ctx.onDrag(state, dragEvt(2, 2))
121
+ expect(fired).toEqual([[7, 7]])
122
+ })
123
+
104
124
  test('onDrag skips touch, delegates without snap, and snaps when enabled', () => {
105
125
  const { ctx, state, map } = createHarness()
106
126
  ctx.onDrag({ ...state, interfaceType: 'touch' }, dragEvt(1, 1))
@@ -1,7 +1,8 @@
1
1
  import DirectSelect from '../../../../../../../node_modules/@mapbox/mapbox-gl-draw/src/modes/direct_select.js' // NOSONAR
2
2
  import {
3
- getSnapInstance, isSnapEnabled, getSnapLngLat, triggerSnapAtPoint, clearSnapState
3
+ getSnapInstance, getSnapLngLat, triggerSnapAtPoint, clearSnapState
4
4
  } from '../../utils/snapHelpers.js'
5
+ import { handleEditModeDrag } from '../../utils/editModeEvents.js'
5
6
  import { getCoords, coordPathToFlatIndex } from './geometryHelpers.js'
6
7
  import { CUSTOM_DRAW_EVENTS } from '../../drawEvents.js'
7
8
 
@@ -128,23 +129,11 @@ export const pointerHandlers = {
128
129
  },
129
130
 
130
131
  onDrag (state, e) {
131
- if (state.interfaceType === 'touch') {
132
- return
133
- }
134
-
135
- this.map.fire('draw.geometrychange', state.feature)
136
-
137
- const snap = getSnapInstance(this.map)
138
- if (snap) {
139
- snap.snapStatus = false
140
- snap.snapCoords = null
141
- }
142
-
143
- if (!isSnapEnabled(state) || !snap?.status) {
144
- DirectSelect.onDrag.call(this, state, e)
145
- return
146
- }
132
+ handleEditModeDrag(this, state, e, this._snapDrag)
133
+ },
147
134
 
135
+ // Moves the dragged vertex to the snapped position
136
+ _snapDrag (state, e, snap) {
148
137
  if (!state.selectedCoordPaths?.length || !state.canDragMove) {
149
138
  return
150
139
  }
@@ -63,6 +63,25 @@ describe('pointerHandlers', () => {
63
63
  expect(h.map._undoStack.pop()).toMatchObject({ type: 'move_vertex', vertexIndex: 1 })
64
64
  })
65
65
 
66
+ test('onDrag that pans the map (nothing dragging) fires no geometrychange, with or without snap', () => {
67
+ const { ctx, state, map } = createHarness()
68
+ Object.assign(state, { canDragMove: false, selectedCoordPaths: ['0.1'] })
69
+ ctx.onDrag(state, dragEvt(2, 2))
70
+ state.getSnapEnabled = () => true
71
+ map._snapInstance = { status: true, snapStatus: false, snapCoords: null, snapToClosestPoint: jest.fn() }
72
+ ctx.onDrag(state, dragEvt(3, 3))
73
+ expect(map.fire).not.toHaveBeenCalledWith('draw.geometrychange', expect.anything())
74
+ })
75
+
76
+ test('onDrag fires geometrychange after the vertex moves, carrying the new position', () => {
77
+ const { ctx, state, map } = createHarness()
78
+ Object.assign(state, { canDragMove: true, selectedCoordPaths: ['0.1'], dragMoveLocation: { lng: 10, lat: 0 } })
79
+ const fired = []
80
+ map.on('draw.geometrychange', (feature) => fired.push(feature.getCoordinate('0.1')))
81
+ ctx.onDrag(state, dragEvt(12, 2))
82
+ expect(fired).toEqual([[12, 2]])
83
+ })
84
+
66
85
  test('onDrag skips touch, delegates without snap, and snaps when enabled', () => {
67
86
  const { ctx, state, map } = createHarness()
68
87
  ctx.onDrag({ ...state, interfaceType: 'touch' }, { originalEvent: { stopPropagation: jest.fn() }, lngLat: { lng: 1, lat: 1 }, point: { x: 10, y: 10 } })
@@ -1,5 +1,6 @@
1
+ import DirectSelect from '../../../../../../node_modules/@mapbox/mapbox-gl-draw/src/modes/direct_select.js' // NOSONAR
1
2
  import { CUSTOM_DRAW_EVENTS } from '../drawEvents.js'
2
- import { getSnapInstance, clearSnapIndicator } from './snapHelpers.js'
3
+ import { getSnapInstance, clearSnapIndicator, isSnapEnabled } from './snapHelpers.js'
3
4
 
4
5
  // Builds the `handlers` map both modes' setupEventListeners bind to bindEditModeListeners —
5
6
  // the base set of window/container/scale/move/interface-type-change handlers is identical
@@ -79,3 +80,30 @@ export const clearActiveSnapIndicator = (map) => {
79
80
  clearSnapIndicator(snap, map)
80
81
  }
81
82
  }
83
+
84
+ // Shared mouse drag for edit_point and edit_vertex (touch drags go through each mode's
85
+ // own onTouchmove). Without an active snap, DirectSelect moves the vertex or the whole
86
+ // feature; with one, the mode's `snapDrag` moves it to the snapped position.
87
+ // geometrychange fires only once something moved — a map pan never sets dragMoving, so it
88
+ // never reaches the live checks or onGeometryPreview.
89
+ export const handleEditModeDrag = (mode, state, e, snapDrag) => {
90
+ if (state.interfaceType === 'touch') {
91
+ return
92
+ }
93
+
94
+ const snap = getSnapInstance(mode.map)
95
+ if (snap) {
96
+ snap.snapStatus = false
97
+ snap.snapCoords = null
98
+ }
99
+
100
+ if (isSnapEnabled(state) && snap?.status) {
101
+ snapDrag.call(mode, state, e, snap)
102
+ } else {
103
+ DirectSelect.onDrag.call(mode, state, e)
104
+ }
105
+
106
+ if (state.dragMoving) {
107
+ mode.map.fire(CUSTOM_DRAW_EVENTS.GEOMETRY_CHANGE, state.feature)
108
+ }
109
+ }
@@ -1,5 +1,6 @@
1
1
  import { createOLDraw } from './olDraw.js'
2
2
  import { hasSymbol } from '../../../../../src/utils/symbolUtils.js'
3
+ import { definedOnly } from '../../utils/flattenStyleProperties.js'
3
4
 
4
5
  // split.js passes this literal — MapLibre's own always-present "already-drawn
5
6
  // shapes" style layer id — as a snapLayers entry so the split line snaps to the
@@ -28,7 +29,7 @@ const DRAW_OUTLINE_STYLE_LAYER = 'stroke-inactive.cold'
28
29
  * nudgeSelectedVertex(dx, dy, isLargeStep)
29
30
  * getVertexItems() / selectVertex(index) / insertVertexAtMidpoint(index)
30
31
  * setGeometry(geometry)
31
- * get(id) / add(feature) / setStyle(id, properties) / delete(id) / deleteAll()
32
+ * get(id) / add(feature) / setStyle(id, properties) / setProperties(id, properties) / delete(id) / deleteAll()
32
33
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
33
34
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
34
35
  * on(event, handler) / off(event, handler)
@@ -113,13 +114,17 @@ export class OLDrawAdapter {
113
114
 
114
115
  // Patches an existing feature's style properties (stroke/fill/strokeWidth or symbol-family
115
116
  // keys) and re-renders — setProperties() must not be called silently, since VectorSource
116
- // only redraws in response to the propertychange event that triggers.
117
+ // only redraws in response to the propertychange event that triggers. A key patched to
118
+ // undefined is removed.
117
119
  setStyle (id, properties) {
118
120
  const olFeature = this._manager.store.getOL(id)
119
121
  if (!olFeature) {
120
122
  return
121
123
  }
122
- olFeature.setProperties(properties)
124
+ for (const [key, value] of Object.entries(properties)) {
125
+ if (value === undefined) { olFeature.unset(key) }
126
+ }
127
+ olFeature.setProperties(definedOnly(properties))
123
128
  if (olFeature.getGeometry()?.getType() === 'Point' && hasSymbol(olFeature.getProperties())) {
124
129
  this._manager.updatePointSymbol(olFeature)
125
130
  }
@@ -143,6 +148,11 @@ export class OLDrawAdapter {
143
148
  setFeatureProperty () { /* not implemented for OL */ }
144
149
  setDrawingPreviewProperty (property, value) { this._manager.setDrawingPreviewProperty(property, value) }
145
150
 
151
+ // Merges data properties into an existing feature (a shallow merge; setStyle handles style)
152
+ setProperties (id, properties) {
153
+ this._manager.store.getOL(id)?.setProperties(properties)
154
+ }
155
+
146
156
  on (type, handler) { this._manager.on(type, handler) }
147
157
  off (type, handler) { this._manager.off(type, handler) }
148
158
 
@@ -194,6 +194,7 @@ describe('add() and point symbol resolution', () => {
194
194
  describe('setStyle()', () => {
195
195
  const fakeOLFeature = (geometryType, properties = {}) => ({
196
196
  setProperties: jest.fn(),
197
+ unset: jest.fn(),
197
198
  getGeometry: jest.fn(() => ({ getType: () => geometryType })),
198
199
  getProperties: jest.fn(() => properties)
199
200
  })
@@ -209,6 +210,17 @@ describe('setStyle()', () => {
209
210
  expect(olFeature.setProperties).toHaveBeenCalledWith({ stroke: 'blue' })
210
211
  })
211
212
 
213
+ test('unsets a key patched to undefined', () => {
214
+ const { manager, adapter } = setup()
215
+ const olFeature = fakeOLFeature('Polygon')
216
+ manager.store.getOL.mockReturnValue(olFeature)
217
+
218
+ adapter.setStyle('a', { stroke: 'blue', strokeDark: undefined })
219
+
220
+ expect(olFeature.unset).toHaveBeenCalledWith('strokeDark')
221
+ expect(olFeature.setProperties).toHaveBeenCalledWith({ stroke: 'blue' })
222
+ })
223
+
212
224
  // setStyle re-resolves a Point's icon the same way add() does for a directly-added one.
213
225
  test('re-resolves the icon for a Point patched with symbol properties', () => {
214
226
  const { manager, adapter } = setup()
@@ -236,6 +248,22 @@ describe('setStyle()', () => {
236
248
  })
237
249
  })
238
250
 
251
+ describe('setProperties()', () => {
252
+ test('merges the properties into the OL feature', () => {
253
+ const { manager, adapter } = setup()
254
+ const olFeature = { setProperties: jest.fn() }
255
+ manager.store.getOL.mockReturnValue(olFeature)
256
+ adapter.setProperties('a', { name: 'North field', ref: null })
257
+ expect(olFeature.setProperties).toHaveBeenCalledWith({ name: 'North field', ref: null })
258
+ })
259
+
260
+ test('does nothing for an id with no existing feature', () => {
261
+ const { manager, adapter } = setup()
262
+ manager.store.getOL.mockReturnValue(null)
263
+ expect(() => adapter.setProperties('missing', { name: 'x' })).not.toThrow()
264
+ })
265
+ })
266
+
239
267
  test('setCanFinish records validity on the manager for finish gating', () => {
240
268
  const { adapter, manager } = setup()
241
269
  adapter.setCanFinish(false)
@@ -1,4 +1,4 @@
1
- import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
1
+ import { flattenStyleProperties, toStyleChanges, definedOnly, mapStyleIds } from '../utils/flattenStyleProperties.js'
2
2
  import { stripInternalProperties } from '../utils/stripInternalProperties.js'
3
3
  import { logger } from '../../../../src/services/logger.js'
4
4
 
@@ -9,7 +9,7 @@ const SUPPORTED_GEOMETRY_TYPES = new Set(['Point', 'LineString', 'Polygon'])
9
9
  const isValidFeature = (feature) =>
10
10
  SUPPORTED_GEOMETRY_TYPES.has(feature.geometry?.type) && feature.geometry?.coordinates !== undefined
11
11
 
12
- export const addFeature = ({ mapProvider, services }, feature) => {
12
+ export const addFeature = ({ mapState, mapProvider, services }, feature) => {
13
13
  const { draw } = mapProvider
14
14
  const { eventBus } = services
15
15
 
@@ -17,14 +17,17 @@ export const addFeature = ({ mapProvider, services }, feature) => {
17
17
  return
18
18
  }
19
19
 
20
+ // A saved feature carries its style in properties, already flattened; a top-level
21
+ // stroke/fill/strokeWidth, when given, replaces that prop's saved values.
20
22
  const { stroke, fill, strokeWidth, properties, ...featureRest } = feature
23
+ const savedProperties = flattenStyleProperties(properties)
21
24
  const flatFeature = {
22
25
  type: 'Feature',
23
26
  ...featureRest,
24
- properties: {
25
- ...properties,
26
- ...flattenStyleProperties({ stroke, fill, strokeWidth })
27
- }
27
+ properties: definedOnly({
28
+ ...savedProperties,
29
+ ...toStyleChanges(savedProperties, { stroke, fill, strokeWidth }, mapStyleIds(mapState))
30
+ })
28
31
  }
29
32
 
30
33
  if (!isValidFeature(flatFeature)) {
@@ -1,17 +1,13 @@
1
1
  import { addFeature } from './addFeature.js'
2
- import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
3
2
  import { logger } from '../../../../src/services/logger.js'
4
3
 
5
- jest.mock('../utils/flattenStyleProperties.js', () => ({
6
- flattenStyleProperties: jest.fn(() => ({ _flat: true }))
7
- }))
8
4
  jest.mock('../../../../src/services/logger.js', () => ({
9
5
  logger: { warn: jest.fn(), error: jest.fn() }
10
6
  }))
11
7
 
12
- const setup = (draw) => {
8
+ const setup = (draw, mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]) => {
13
9
  const eventBus = { emit: jest.fn() }
14
- return { context: { mapProvider: { draw }, services: { eventBus } }, eventBus }
10
+ return { context: { mapState: { mapStyles }, mapProvider: { draw }, services: { eventBus } }, eventBus }
15
11
  }
16
12
 
17
13
  beforeEach(() => jest.clearAllMocks())
@@ -29,7 +25,7 @@ describe('addFeature', () => {
29
25
  const feature = {
30
26
  id: 'a',
31
27
  geometry: { type: 'Point', coordinates: [0, 0] },
32
- stroke: 'red',
28
+ stroke: { outdoor: 'red', dark: 'white' },
33
29
  fill: 'blue',
34
30
  strokeWidth: 2,
35
31
  properties: { name: 'x' }
@@ -37,12 +33,11 @@ describe('addFeature', () => {
37
33
 
38
34
  addFeature(context, feature)
39
35
 
40
- expect(flattenStyleProperties).toHaveBeenCalledWith({ stroke: 'red', fill: 'blue', strokeWidth: 2 })
41
36
  const expected = {
42
37
  type: 'Feature',
43
38
  id: 'a',
44
39
  geometry: { type: 'Point', coordinates: [0, 0] },
45
- properties: { name: 'x', _flat: true }
40
+ properties: { name: 'x', stroke: 'red', strokeOutdoor: 'red', strokeDark: 'white', fill: 'blue', strokeWidth: 2 }
46
41
  }
47
42
  expect(draw.add).toHaveBeenCalledWith(expected)
48
43
  expect(eventBus.emit).toHaveBeenCalledWith('draw:add', expected)
@@ -56,8 +51,40 @@ describe('addFeature', () => {
56
51
  type: 'Feature',
57
52
  id: 'b',
58
53
  geometry: { type: 'LineString', coordinates: [[0, 0], [1, 1]] },
59
- properties: { _flat: true }
54
+ properties: {}
55
+ })
56
+ })
57
+
58
+ // A feature saved from draw:created carries its style in properties, already flattened
59
+ test('keeps a saved feature\'s style properties when no top-level style is given', () => {
60
+ const draw = { add: jest.fn() }
61
+ const { context } = setup(draw)
62
+ const properties = { stroke: '#8b5a2b', strokeOutdoor: '#8b5a2b', strokeDark: '#d2a679', strokeWidth: 4, fill: 'green', landUse: 'hedge' }
63
+ addFeature(context, { id: 'h', geometry: { type: 'LineString', coordinates: [[0, 0], [1, 1]] }, properties })
64
+ expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({ properties }))
65
+ })
66
+
67
+ test('flattens a per-style object given inside properties', () => {
68
+ const draw = { add: jest.fn() }
69
+ const { context } = setup(draw)
70
+ addFeature(context, { id: 'h', geometry: { type: 'LineString', coordinates: [[0, 0], [1, 1]] }, properties: { stroke: { outdoor: 'red', dark: 'white' } } })
71
+ expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({
72
+ properties: { stroke: 'red', strokeOutdoor: 'red', strokeDark: 'white' }
73
+ }))
74
+ })
75
+
76
+ test('a top-level style replaces that prop\'s saved values for each map style, leaving data and other props alone', () => {
77
+ const draw = { add: jest.fn() }
78
+ const { context } = setup(draw)
79
+ addFeature(context, {
80
+ id: 'h',
81
+ geometry: { type: 'LineString', coordinates: [[0, 0], [1, 1]] },
82
+ stroke: '#d4351c',
83
+ properties: { stroke: '#8b5a2b', strokeOutdoor: '#8b5a2b', strokeDark: '#d2a679', strokeWidth: 4, strokeWidthDark: 6, strokeNote: 'cut in March' }
60
84
  })
85
+ expect(draw.add).toHaveBeenCalledWith(expect.objectContaining({
86
+ properties: { stroke: '#d4351c', strokeWidth: 4, strokeWidthDark: 6, strokeNote: 'cut in March' }
87
+ }))
61
88
  })
62
89
 
63
90
  test('does not override an explicitly supplied type', () => {
@@ -48,7 +48,7 @@ export const editFeature = ({ appState, appConfig, mapState, pluginConfig, plugi
48
48
  // Seed the Done-button gate and the stroke from the feature's starting check, so an
49
49
  // already invalid feature opens dashed and cannot be "finished" until fixed. events.js
50
50
  // applies the result once it settles (straight away unless onGeometryChange is async).
51
- getCommitChecks(draw).run({ feature, context: { phase: 'edit-start', mode }, onGeometryChange: draw._commitValidator })
51
+ getCommitChecks(draw).run({ feature, context: { phase: 'edit-start', mode }, consumerCheck: draw._commitValidator })
52
52
 
53
53
  return true
54
54
  }
@@ -27,6 +27,6 @@ export const recheckGeometry = ({ mapProvider }, detail) => {
27
27
  }
28
28
 
29
29
  const context = { phase: 'recheck', mode, ...(detail !== undefined && { detail }) }
30
- checks.run({ feature, context, onGeometryChange: draw._commitValidator })
30
+ checks.run({ feature, context, consumerCheck: draw._commitValidator })
31
31
  return true
32
32
  }
@@ -12,7 +12,7 @@ describe('recheckGeometry', () => {
12
12
  .mockReturnValueOnce({ valid: false, reason: 'near a parcel' })
13
13
  .mockReturnValueOnce(true)
14
14
  const checks = getCommitChecks(draw)
15
- checks.run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' }, onGeometryChange: draw._commitValidator })
15
+ checks.run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' }, consumerCheck: draw._commitValidator })
16
16
  expect(checks.state.status).toBe('invalid')
17
17
 
18
18
  expect(recheckGeometry({ mapProvider: { draw } })).toBe(true)
@@ -26,7 +26,7 @@ describe('recheckGeometry', () => {
26
26
  test('passes a detail through to onGeometryChange', () => {
27
27
  const draw = makeDraw()
28
28
  draw._commitValidator = jest.fn(() => true)
29
- getCommitChecks(draw).run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' }, onGeometryChange: draw._commitValidator })
29
+ getCommitChecks(draw).run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' }, consumerCheck: draw._commitValidator })
30
30
  recheckGeometry({ mapProvider: { draw } }, { refresh: false })
31
31
  expect(draw._commitValidator).toHaveBeenLastCalledWith(
32
32
  { feature: square, phase: 'recheck', mode: 'edit_vertex', detail: { refresh: false } },
@@ -0,0 +1,39 @@
1
+ import { mergeFeatureProperties } from '../utils/mergeFeatureProperties.js'
2
+ import { mapStyleIds } from '../utils/flattenStyleProperties.js'
3
+ import { isEditMode } from '../utils/drawModes.js'
4
+ import { logger } from '../../../../src/services/logger.js'
5
+
6
+ /**
7
+ * Merge data properties into an existing feature. See mergeFeatureProperties for the rules:
8
+ * a shallow merge, undefined left out, null kept, internal and style properties refused.
9
+ *
10
+ * @param {object} context - plugin context
11
+ * @param {string} featureId
12
+ * @param {object} properties
13
+ * @returns {boolean} false if the feature doesn't exist
14
+ */
15
+ export const setProperties = ({ pluginState, mapState, mapProvider, services }, featureId, properties = {}) => {
16
+ const { draw } = mapProvider
17
+ const { eventBus } = services
18
+
19
+ if (!draw) {
20
+ return false
21
+ }
22
+
23
+ if (!draw.get(featureId)) {
24
+ logger.warn('setProperties: no feature found for id', featureId)
25
+ return false
26
+ }
27
+
28
+ const applied = mergeFeatureProperties(draw, featureId, properties, { caller: 'setProperties', styleIds: mapStyleIds(mapState) })
29
+
30
+ // Cancelling an edit puts back the feature as it was when the edit started, so that copy
31
+ // gets the properties too — they aren't part of the edit.
32
+ const { feature: editStart, dispatch } = pluginState
33
+ if (isEditMode(draw.getMode()) && editStart?.id === featureId) {
34
+ dispatch({ type: 'SET_FEATURE', payload: { feature: { ...editStart, properties: { ...editStart.properties, ...applied } } } })
35
+ }
36
+
37
+ eventBus.emit('draw:propertieschange', { featureId, properties: applied })
38
+ return true
39
+ }