@defra/interactive-map 0.0.57-alpha → 0.0.59-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/im-core.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/docs/assets/css/docusaurus.scss +7 -1
- package/docs/plugins/draw.md +317 -186
- package/package.json +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/adapterEvents.js +15 -9
- package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
- package/plugins/draw/src/api/addFeature.js +9 -6
- package/plugins/draw/src/api/addFeature.test.js +37 -10
- package/plugins/draw/src/api/createNewShape.js +2 -2
- package/plugins/draw/src/api/editFeature.js +1 -1
- package/plugins/draw/src/api/newPoint.js +2 -2
- package/plugins/draw/src/api/newPoint.test.js +8 -0
- package/plugins/draw/src/api/newPolygon.test.js +8 -0
- package/plugins/draw/src/api/recheckGeometry.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
- package/plugins/draw/src/api/setProperties.js +39 -0
- package/plugins/draw/src/api/setProperties.test.js +74 -0
- package/plugins/draw/src/api/setStyle.js +16 -19
- package/plugins/draw/src/api/setStyle.test.js +17 -2
- package/plugins/draw/src/api/split.js +10 -4
- package/plugins/draw/src/api/split.test.js +30 -2
- package/plugins/draw/src/events.js +110 -64
- package/plugins/draw/src/events.test.js +494 -4
- package/plugins/draw/src/manifest.js +6 -4
- package/plugins/draw/src/manifest.test.js +20 -26
- package/plugins/draw/src/reducer.js +7 -0
- package/plugins/draw/src/reducer.test.js +11 -0
- package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
- package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
- package/plugins/draw/src/utils/isPlainObject.js +14 -0
- package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
- package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
- package/plugins/draw/src/validation/commitChecks.js +32 -12
- package/plugins/draw/src/validation/commitChecks.test.js +73 -13
- package/plugins/draw/src/validation/validateGeometry.js +12 -5
- package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
- package/src/App/store/MapProvider.jsx +1 -0
- package/src/App/store/MapProvider.test.jsx +25 -0
- package/src/App/store/mapActionsMap.js +6 -0
- package/src/App/store/mapActionsMap.test.js +7 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +2 -0
|
@@ -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,
|
|
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}()});
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* `context.phase` through validateGeometry (validation/validateGeometry.js) to the
|
|
4
4
|
* default rules (validation/rules.js) and to the user's callbacks:
|
|
5
5
|
* - 'preview' and 'place' go to `onGeometryPreview`, which must answer synchronously
|
|
6
|
+
* - 'create' and 'edit-finish' go to `onGeometryFinish` when it's set
|
|
6
7
|
* - every other phase goes to `onGeometryChange`, which may return a Promise
|
|
7
8
|
*
|
|
8
9
|
* @typedef {'preview' | 'place' | 'change' | 'create' | 'edit-start' | 'edit-finish' | 'recheck'} GeometryChangePhase
|
|
@@ -17,13 +18,15 @@
|
|
|
17
18
|
* synchronously; a PLACE_RULES failure vetoes it outright
|
|
18
19
|
* and it never appears. Never fires continuously — that's
|
|
19
20
|
* 'preview''s job (see above).
|
|
20
|
-
* 'create' - a whole new feature finished
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* 'create' - a whole new feature finished. Always checked with
|
|
22
|
+
* onGeometryFinish; otherwise only without a passing or pending
|
|
23
|
+
* result for its final geometry (e.g. a new point), or when its
|
|
24
|
+
* last result asked for recheckOnFinish.
|
|
23
25
|
* 'edit-start' - an existing feature was just loaded into an edit session;
|
|
24
26
|
* nothing has changed yet, this is the baseline check.
|
|
25
|
-
* 'edit-finish' - Done was pressed on an edit
|
|
26
|
-
*
|
|
27
|
+
* 'edit-finish' - Done was pressed on an edit. Always checked with
|
|
28
|
+
* onGeometryFinish; otherwise only when its last result asked
|
|
29
|
+
* for recheckOnFinish.
|
|
27
30
|
* 'recheck' - the unchanged shape is checked again (recheckGeometry), with
|
|
28
31
|
* any detail it was given as `event.detail`.
|
|
29
32
|
* 'change' - the shape changed: a vertex was added, moved, inserted or
|
|
@@ -73,7 +76,7 @@ export const CHANGE_PHASE = 'change'
|
|
|
73
76
|
*/
|
|
74
77
|
|
|
75
78
|
/**
|
|
76
|
-
* What a user's `onGeometryPreview` or `
|
|
79
|
+
* What a user's `onGeometryPreview`, `onGeometryChange` or `onGeometryFinish` callback returns, after
|
|
77
80
|
* normaliseResult (validation/validateGeometry.js). `true`/`undefined` and `false`
|
|
78
81
|
* are shorthands for valid and invalid.
|
|
79
82
|
*
|
|
@@ -82,12 +85,15 @@ export const CHANGE_PHASE = 'change'
|
|
|
82
85
|
* @property {string} [reason] - shown as a hint toast and sent with draw:geometryinvalid
|
|
83
86
|
* @property {string} [announcement] - announced to screen readers in place of draw's own
|
|
84
87
|
* message; the reason then isn't shown as a hint, as the consumer presents it
|
|
85
|
-
* @property {boolean} [recheckOnFinish] -
|
|
86
|
-
* result when the shape is finished, check
|
|
88
|
+
* @property {boolean} [recheckOnFinish] - deprecated, use onGeometryFinish.
|
|
89
|
+
* `onGeometryChange` only: don't reuse this result when the shape is finished, check
|
|
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)
|
|
87
93
|
*/
|
|
88
94
|
|
|
89
95
|
/**
|
|
90
|
-
* The second argument passed to a user's `onGeometryChange` callback —
|
|
96
|
+
* The second argument passed to a user's `onGeometryChange` or `onGeometryFinish` callback —
|
|
91
97
|
* `onGeometryChange(event, { signal, revision })` (validation/commitChecks.js).
|
|
92
98
|
*
|
|
93
99
|
* @typedef {object} GeometryCheckContext
|
|
@@ -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
|
-
|
|
92
|
-
|
|
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,
|
|
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
|
-
|
|
132
|
-
|
|
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
|
-
|
|
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
|
-
...
|
|
26
|
-
...
|
|
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',
|
|
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: {
|
|
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', () => {
|
|
@@ -13,8 +13,8 @@ export const createNewShape = (mode) => ({ appState, appConfig, pluginConfig, pl
|
|
|
13
13
|
return
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const { stroke, fill, strokeWidth, properties: customProperties, onGeometryChange, onGeometryPreview, ...modeOptions } = options
|
|
17
|
-
startCheckSession(draw, { onGeometryChange, onGeometryPreview }, pluginConfig, eventBus)
|
|
16
|
+
const { stroke, fill, strokeWidth, properties: customProperties, onGeometryChange, onGeometryPreview, onGeometryFinish, ...modeOptions } = options
|
|
17
|
+
startCheckSession(draw, { onGeometryChange, onGeometryPreview, onGeometryFinish }, pluginConfig, eventBus)
|
|
18
18
|
eventBus.emit('draw:started', { mode, featureId })
|
|
19
19
|
|
|
20
20
|
const snapLayers = options.snapLayers === undefined ? (pluginConfig.snapLayers ?? null) : options.snapLayers
|
|
@@ -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 },
|
|
51
|
+
getCommitChecks(draw).run({ feature, context: { phase: 'edit-start', mode }, consumerCheck: draw._commitValidator })
|
|
52
52
|
|
|
53
53
|
return true
|
|
54
54
|
}
|
|
@@ -10,8 +10,8 @@ export const newPoint = ({ appState, appConfig, pluginConfig, pluginState, mapSt
|
|
|
10
10
|
return
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const { properties: customProperties, onGeometryChange, onGeometryPreview, ...modeOptions } = options
|
|
14
|
-
startCheckSession(draw, { onGeometryChange, onGeometryPreview }, pluginConfig, eventBus)
|
|
13
|
+
const { properties: customProperties, onGeometryChange, onGeometryPreview, onGeometryFinish, ...modeOptions } = options
|
|
14
|
+
startCheckSession(draw, { onGeometryChange, onGeometryPreview, onGeometryFinish }, pluginConfig, eventBus)
|
|
15
15
|
eventBus.emit('draw:started', { mode: 'draw_point', featureId })
|
|
16
16
|
|
|
17
17
|
const snapLayers = options.snapLayers === undefined ? (pluginConfig.snapLayers ?? null) : options.snapLayers
|
|
@@ -114,4 +114,12 @@ describe('newPoint', () => {
|
|
|
114
114
|
newPoint(context, 'f1')
|
|
115
115
|
expect(draw._commitValidator).toBe(pluginOnGeometryChange)
|
|
116
116
|
})
|
|
117
|
+
|
|
118
|
+
test('stores a per-call onGeometryFinish without leaking it into mode options', () => {
|
|
119
|
+
const { context, draw } = makeContext()
|
|
120
|
+
const onGeometryFinish = jest.fn()
|
|
121
|
+
newPoint(context, 'f1', { onGeometryFinish })
|
|
122
|
+
expect(draw._finishValidator).toBe(onGeometryFinish)
|
|
123
|
+
expect(draw.changeMode.mock.calls[0][1]).not.toHaveProperty('onGeometryFinish')
|
|
124
|
+
})
|
|
117
125
|
})
|