@defra/interactive-map 0.0.60-alpha → 0.0.62-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 (84) hide show
  1. package/dist/css/index.css +1 -1
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/api/button-definition.md +11 -0
  7. package/docs/api/context.md +2 -0
  8. package/docs/api.md +20 -0
  9. package/docs/plugins/draw.md +26 -0
  10. package/package.json +1 -1
  11. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  12. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  13. package/plugins/datasets/src/reducers/datasetsToMenu.js +12 -9
  14. package/plugins/datasets/src/reducers/datasetsToMenu.test.js +42 -0
  15. package/plugins/datasets/src/reducers/pluginState.test.js +12 -0
  16. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  17. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  18. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  19. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  20. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  21. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  22. package/plugins/draw/dist/umd/index.js +1 -1
  23. package/plugins/draw/src/DrawInit.jsx +3 -0
  24. package/plugins/draw/src/DrawInit.test.jsx +16 -0
  25. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
  26. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  27. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
  28. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
  29. package/plugins/draw/src/defaults.js +4 -0
  30. package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
  31. package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
  32. package/plugins/draw/src/manifest.js +4 -1
  33. package/plugins/draw/src/manifest.test.js +15 -2
  34. package/plugins/draw/src/utils/snapMinZoom.js +8 -0
  35. package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
  36. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  37. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  38. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  39. package/plugins/map-key/src/manifest.js +1 -1
  40. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  41. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  42. package/providers/openlayers/src/openlayersProvider.js +2 -1
  43. package/providers/openlayers/src/openlayersProvider.test.js +1 -1
  44. package/src/App/components/MapButton/MapButton.jsx +20 -2
  45. package/src/App/components/MapButton/MapButton.module.scss +15 -1
  46. package/src/App/components/MapButton/MapButton.test.jsx +21 -3
  47. package/src/App/components/MapControls/MapControls.jsx +2 -1
  48. package/src/App/components/MapControls/MapControls.test.jsx +1 -1
  49. package/src/App/components/PopupMenu/PopupMenu.test.jsx +22 -0
  50. package/src/App/components/PopupMenu/usePopupMenu.js +9 -6
  51. package/src/App/components/Tooltip/Tooltip.jsx +29 -11
  52. package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
  53. package/src/App/components/Viewport/MapController.jsx +4 -0
  54. package/src/App/components/Viewport/MapController.test.jsx +6 -0
  55. package/src/App/hooks/useMapProviderOverrides.js +10 -5
  56. package/src/App/hooks/useMapProviderOverrides.test.js +11 -0
  57. package/src/App/hooks/useResetViewTarget.js +135 -0
  58. package/src/App/hooks/useResetViewTarget.test.js +211 -0
  59. package/src/App/hooks/useUserMoveTracking.js +72 -0
  60. package/src/App/hooks/useUserMoveTracking.test.js +117 -0
  61. package/src/App/renderer/mapButtons.js +3 -1
  62. package/src/App/renderer/mapButtons.test.js +20 -0
  63. package/src/App/store/ServiceProvider.jsx +8 -2
  64. package/src/App/store/ServiceProvider.test.jsx +13 -0
  65. package/src/App/store/mapActionsMap.js +16 -1
  66. package/src/App/store/mapActionsMap.test.js +17 -0
  67. package/src/App/store/mapReducer.js +6 -0
  68. package/src/App/store/mapReducer.test.js +3 -0
  69. package/src/InteractiveMap/InteractiveMap.js +8 -0
  70. package/src/InteractiveMap/InteractiveMap.test.js +5 -0
  71. package/src/config/appConfig.js +17 -0
  72. package/src/config/appConfig.test.js +28 -0
  73. package/src/config/defaults.js +1 -0
  74. package/src/config/events.js +2 -0
  75. package/src/scss/settings/_colors.scss +4 -0
  76. package/src/services/mapFocus.js +3 -2
  77. package/src/services/mapFocus.test.js +10 -0
  78. package/src/types.js +9 -0
  79. package/src/utils/focusAfterPanelClose.js +3 -1
  80. package/src/utils/getFocusOptions.js +3 -0
  81. package/src/utils/getFocusOptions.test.js +11 -0
  82. package/src/utils/mapStateSync.js +1 -0
  83. package/src/utils/resetView.js +61 -0
  84. package/src/utils/resetView.test.js +62 -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,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}()});
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,579));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 @@ import { EVENTS } from '../../../src/config/events.js'
3
3
  import { loadDrawAdapter } from './adapters/loadDrawAdapter.js'
4
4
  import { attachEvents } from './events.js'
5
5
  import { useSpatialList } from './hooks/useSpatialList.js'
6
+ import { useSnapMinZoom } from './hooks/useSnapMinZoom.js'
6
7
  import { APPLICATION_MODE_ID } from './defaults.js'
7
8
  import { needsDrawTarget } from './utils/needsDrawTarget.js'
8
9
  import { isDrawingMode, isSessionMode } from './utils/drawModes.js'
@@ -78,6 +79,8 @@ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginSt
78
79
 
79
80
  useLoadDrawAdapter({ mapState, pluginConfig, pluginState, mapProvider, eventBus, symbolRegistry })
80
81
 
82
+ useSnapMinZoom({ mapState, pluginConfig, pluginState, mapProvider, hints })
83
+
81
84
  // Enters the 'draw' application mode (declared in the manifest) in any draw/edit mode, and leaves it
82
85
  // when the draw/edit mode ends. useLayoutEffect so the class lands in the same paint as the change.
83
86
  useLayoutEffect(() => {
@@ -5,11 +5,13 @@ import { DrawInit } from './DrawInit.jsx'
5
5
  import { loadDrawAdapter } from './adapters/loadDrawAdapter.js'
6
6
  import { attachEvents } from './events.js'
7
7
  import { useSpatialList } from './hooks/useSpatialList.js'
8
+ import { useSnapMinZoom } from './hooks/useSnapMinZoom.js'
8
9
 
9
10
  jest.mock('./adapters/loadDrawAdapter.js', () => ({ loadDrawAdapter: jest.fn() }))
10
11
  jest.mock('../../../src/services/logger.js', () => ({ logger: { error: jest.fn() } }))
11
12
  jest.mock('./events.js', () => ({ attachEvents: jest.fn(() => jest.fn()) }))
12
13
  jest.mock('./hooks/useSpatialList.js', () => ({ useSpatialList: jest.fn() }))
14
+ jest.mock('./hooks/useSnapMinZoom.js', () => ({ useSnapMinZoom: jest.fn() }))
13
15
 
14
16
  const makeProps = (overrides = {}) => {
15
17
  const adapter = { remove: jest.fn(), setInterfaceType: jest.fn() }
@@ -253,6 +255,20 @@ describe('useSpatialList wiring', () => {
253
255
  })
254
256
  })
255
257
 
258
+ describe('useSnapMinZoom wiring', () => {
259
+ test('is called with the map and plugin state, the map provider and the hints service', async () => {
260
+ const { props } = makeProps({ pluginState: { dispatch: jest.fn(), mode: 'draw_line' } })
261
+ await renderInit(props)
262
+ expect(useSnapMinZoom).toHaveBeenCalledWith({
263
+ mapState: props.mapState,
264
+ pluginConfig: props.pluginConfig,
265
+ pluginState: props.pluginState,
266
+ mapProvider: props.mapProvider,
267
+ hints: props.services.hints
268
+ })
269
+ })
270
+ })
271
+
256
272
  describe('crosshair', () => {
257
273
  test('fixes the crosshair at centre while drawing on a touch interface', async () => {
258
274
  const { props } = makeProps({
@@ -68,6 +68,7 @@ export const displayedShape = (mode, coordinates) => {
68
68
  * setGeometry(geometry)
69
69
  * get(id) / add(feature) / setStyle(id, properties) / setProperties(id, properties) / delete(id) / deleteAll()
70
70
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
71
+ * setSnapAvailable(bool)
71
72
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
72
73
  * on(event, handler) / off(event, handler)
73
74
  * remove()
@@ -82,6 +83,7 @@ export class MaplibreDrawAdapter {
82
83
  // Assigned once per feature, on creation only (see styles.js's SORT_KEY_PROP) — drives
83
84
  // paint order so a later-drawn feature reliably layers above an earlier one.
84
85
  this._sortKeyCounter = 0
86
+ this._snapAvailable = true
85
87
 
86
88
  const { draw, remove } = createMapboxDraw({
87
89
  mapStyle: options.mapStyle,
@@ -370,9 +372,23 @@ export class MaplibreDrawAdapter {
370
372
 
371
373
  setSnapEnabled (bool) {
372
374
  this._mapProvider.snapEnabled = bool
375
+ this._applySnapStatus()
376
+ }
377
+
378
+ // Snaps only while the user has snap on and it's available
379
+ setSnapAvailable (bool) {
380
+ if (bool === this._snapAvailable) {
381
+ return
382
+ }
383
+ this._snapAvailable = bool
384
+ this._applySnapStatus()
385
+ }
386
+
387
+ _applySnapStatus () {
388
+ const isActive = this.isSnapEnabled()
373
389
  const snap = getSnapInstance(this._map)
374
- if (snap?.setSnapStatus) { snap.setSnapStatus(bool) }
375
- if (!bool && snap) {
390
+ if (snap?.setSnapStatus) { snap.setSnapStatus(isActive) }
391
+ if (!isActive && snap) {
376
392
  clearSnapState(snap)
377
393
  if (this._map.getLayer('snap-helper-circle')) {
378
394
  this._map.setLayoutProperty('snap-helper-circle', 'visibility', 'none')
@@ -392,7 +408,7 @@ export class MaplibreDrawAdapter {
392
408
  }
393
409
 
394
410
  isSnapEnabled () {
395
- return this._mapProvider.snapEnabled === true
411
+ return this._mapProvider.snapEnabled === true && this._snapAvailable
396
412
  }
397
413
 
398
414
  setFeatureProperty (id, property, value) {
@@ -1164,3 +1164,30 @@ describe('remove', () => {
1164
1164
  expect(removeDraw).toHaveBeenCalled()
1165
1165
  })
1166
1166
  })
1167
+
1168
+ describe('snap availability', () => {
1169
+ test('snaps only while snap is on and available, keeping the user\'s choice', () => {
1170
+ const { adapter, mapProvider } = setup()
1171
+ const snap = { setSnapStatus: jest.fn() }
1172
+ getSnapInstance.mockReturnValue(snap)
1173
+ adapter.setSnapEnabled(true)
1174
+
1175
+ adapter.setSnapAvailable(false)
1176
+ expect(snap.setSnapStatus).toHaveBeenLastCalledWith(false)
1177
+ expect(clearSnapState).toHaveBeenCalledWith(snap)
1178
+ expect(adapter.isSnapEnabled()).toBe(false)
1179
+ expect(mapProvider.snapEnabled).toBe(true)
1180
+
1181
+ adapter.setSnapAvailable(true)
1182
+ expect(snap.setSnapStatus).toHaveBeenLastCalledWith(true)
1183
+ expect(adapter.isSnapEnabled()).toBe(true)
1184
+ })
1185
+
1186
+ test('does nothing when availability hasn\'t changed', () => {
1187
+ const { adapter } = setup()
1188
+ const snap = { setSnapStatus: jest.fn() }
1189
+ getSnapInstance.mockReturnValue(snap)
1190
+ adapter.setSnapAvailable(true)
1191
+ expect(snap.setSnapStatus).not.toHaveBeenCalled()
1192
+ })
1193
+ })
@@ -31,12 +31,14 @@ const DRAW_OUTLINE_STYLE_LAYER = 'stroke-inactive.cold'
31
31
  * setGeometry(geometry)
32
32
  * get(id) / add(feature) / setStyle(id, properties) / setProperties(id, properties) / delete(id) / deleteAll()
33
33
  * setSnapEnabled(bool) / setSnapLayers(layers) / isSnapEnabled()
34
+ * setSnapAvailable(bool)
34
35
  * setFeatureProperty(id, property, value) / setDrawingPreviewProperty(property, value)
35
36
  * on(event, handler) / off(event, handler)
36
37
  * remove()
37
38
  */
38
39
  export class OLDrawAdapter {
39
40
  _snapEnabled = false
41
+ _snapAvailable = true
40
42
 
41
43
  constructor (mapProvider, options) {
42
44
  const { manager, remove } = createOLDraw({
@@ -135,7 +137,13 @@ export class OLDrawAdapter {
135
137
 
136
138
  setSnapEnabled (bool) {
137
139
  this._snapEnabled = bool
138
- this._manager.snap?.setActive(bool)
140
+ this._manager.snap?.setActive(this.isSnapEnabled())
141
+ }
142
+
143
+ // Snaps only while the user has snap on and it's available
144
+ setSnapAvailable (bool) {
145
+ this._snapAvailable = bool
146
+ this._manager.snap?.setActive(this.isSnapEnabled())
139
147
  }
140
148
 
141
149
  setSnapLayers (layers) {
@@ -143,7 +151,7 @@ export class OLDrawAdapter {
143
151
  this._manager.snap?.setSnapLayers(translated)
144
152
  }
145
153
 
146
- isSnapEnabled () { return this._snapEnabled }
154
+ isSnapEnabled () { return this._snapEnabled && this._snapAvailable }
147
155
 
148
156
  setFeatureProperty () { /* not implemented for OL */ }
149
157
  setDrawingPreviewProperty (property, value) { this._manager.setDrawingPreviewProperty(property, value) }
@@ -289,3 +289,17 @@ test('remove runs the olDraw cleanup', () => {
289
289
  adapter.remove()
290
290
  expect(createOLDraw.mock.results.at(-1).value.remove).toHaveBeenCalled()
291
291
  })
292
+
293
+ test('snaps only while snap is on and available', () => {
294
+ const { manager, adapter } = setup()
295
+ adapter.setSnapEnabled(true)
296
+ adapter.setSnapAvailable(false)
297
+ expect(manager.snap.setActive).toHaveBeenLastCalledWith(false)
298
+ expect(adapter.isSnapEnabled()).toBe(false)
299
+ adapter.setSnapAvailable(true)
300
+ expect(manager.snap.setActive).toHaveBeenLastCalledWith(true)
301
+ expect(adapter.isSnapEnabled()).toBe(true)
302
+
303
+ manager.snap = null
304
+ expect(() => adapter.setSnapAvailable(false)).not.toThrow()
305
+ })
@@ -39,6 +39,10 @@ export const TOLERANCES = {
39
39
  snapRadius: 12
40
40
  }
41
41
 
42
+ // Shown when the user zooms below snapMinZoom, and read with the Snap button while it's
43
+ // disabled there. Overridden by snapZoomInHintText.
44
+ export const SNAP_ZOOM_IN_HINT_TEXT = 'Zoom in to use snap'
45
+
42
46
  export const KEYBOARD = {
43
47
  nudgeAmount: 1,
44
48
  stepAmount: 5
@@ -0,0 +1,29 @@
1
+ import { useEffect, useRef } from 'react'
2
+ import { isBelowSnapMinZoom, getSnapHintText } from '../utils/snapMinZoom.js'
3
+
4
+ /**
5
+ * Stops the adapter snapping below snapMinZoom, keeping the user's on/off choice. When the user
6
+ * has snap on and their own zoom takes the map below it during a draw or edit, a hint tells them
7
+ * to zoom in. Zooms made by code never show the hint.
8
+ */
9
+ export function useSnapMinZoom ({ mapState, pluginConfig, pluginState, mapProvider, hints }) {
10
+ const { zoom, isUserMove } = mapState
11
+ const { mode, hasSnapLayers, snap } = pluginState
12
+ const draw = mapProvider.draw
13
+ const isBelow = isBelowSnapMinZoom(pluginConfig, zoom)
14
+ const previousRef = useRef({ mode: null, isBelow: false })
15
+
16
+ useEffect(() => {
17
+ if (!draw) {
18
+ return
19
+ }
20
+ const previous = previousRef.current
21
+ previousRef.current = { mode, isBelow }
22
+ draw.setSnapAvailable(!isBelow)
23
+
24
+ const isZoomInSession = !!mode && previous.mode === mode && hasSnapLayers
25
+ if (isBelow && !previous.isBelow && isZoomInSession && snap && isUserMove) {
26
+ hints.show(getSnapHintText(pluginConfig))
27
+ }
28
+ }, [draw, mode, isBelow])
29
+ }
@@ -0,0 +1,82 @@
1
+ import { renderHook } from '@testing-library/react'
2
+ import { useSnapMinZoom } from './useSnapMinZoom.js'
3
+
4
+ const setup = ({ mode = 'draw_polygon', zoom = 16, isUserMove = true, hasSnapLayers = true, snap = true, snapMinZoom = 16, draw = { setSnapAvailable: jest.fn() } } = {}) => {
5
+ const hints = { show: jest.fn() }
6
+ const props = (overrides = {}) => ({
7
+ mapState: { zoom, isUserMove, ...overrides.mapState },
8
+ pluginConfig: { snapMinZoom, ...overrides.pluginConfig },
9
+ pluginState: { mode, hasSnapLayers, snap, ...overrides.pluginState },
10
+ mapProvider: { draw },
11
+ hints
12
+ })
13
+ const hook = renderHook((hookProps) => useSnapMinZoom(hookProps), { initialProps: props() })
14
+ const rerender = (overrides) => hook.rerender(props(overrides))
15
+ return { draw, hints, rerender }
16
+ }
17
+
18
+ describe('useSnapMinZoom', () => {
19
+ test('makes snapping unavailable below snapMinZoom, and available again at it', () => {
20
+ const { draw, rerender } = setup()
21
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(true)
22
+ rerender({ mapState: { zoom: 15 } })
23
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(false)
24
+ rerender({ mapState: { zoom: 16 } })
25
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(true)
26
+ })
27
+
28
+ test('shows the hint when the user zooms below snapMinZoom with snap on', () => {
29
+ const { hints, rerender } = setup()
30
+ rerender({ mapState: { zoom: 15 } })
31
+ expect(hints.show).toHaveBeenCalledWith('Zoom in to use snap')
32
+ })
33
+
34
+ test('shows the configured hint text', () => {
35
+ const { hints, rerender } = setup()
36
+ rerender({ mapState: { zoom: 15 }, pluginConfig: { snapZoomInHintText: 'Zoom in further' } })
37
+ expect(hints.show).toHaveBeenCalledWith('Zoom in further')
38
+ })
39
+
40
+ test('doesn\'t show the hint again while the map stays below snapMinZoom', () => {
41
+ const { hints, rerender } = setup()
42
+ rerender({ mapState: { zoom: 15 } })
43
+ rerender({ mapState: { zoom: 14 } })
44
+ expect(hints.show).toHaveBeenCalledTimes(1)
45
+ })
46
+
47
+ test('doesn\'t show the hint with snap off', () => {
48
+ const { draw, hints, rerender } = setup({ snap: false })
49
+ rerender({ mapState: { zoom: 15 } })
50
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(false)
51
+ expect(hints.show).not.toHaveBeenCalled()
52
+ })
53
+
54
+ test('doesn\'t show the hint when code zoomed the map', () => {
55
+ const { draw, hints, rerender } = setup()
56
+ rerender({ mapState: { zoom: 15, isUserMove: false } })
57
+ expect(draw.setSnapAvailable).toHaveBeenLastCalledWith(false)
58
+ expect(hints.show).not.toHaveBeenCalled()
59
+ })
60
+
61
+ test('doesn\'t show the hint when a draw or edit starts below snapMinZoom', () => {
62
+ const { hints, rerender } = setup({ mode: null, zoom: 12 })
63
+ rerender({ pluginState: { mode: 'draw_polygon' } })
64
+ expect(hints.show).not.toHaveBeenCalled()
65
+ })
66
+
67
+ test('doesn\'t show the hint outside a draw or edit, or without snap layers', () => {
68
+ const outside = setup({ mode: null })
69
+ outside.rerender({ mapState: { zoom: 15 } })
70
+ expect(outside.hints.show).not.toHaveBeenCalled()
71
+
72
+ const noLayers = setup({ hasSnapLayers: false })
73
+ noLayers.rerender({ mapState: { zoom: 15 } })
74
+ expect(noLayers.hints.show).not.toHaveBeenCalled()
75
+ })
76
+
77
+ test('waits for the adapter', () => {
78
+ const { hints, rerender } = setup({ draw: null })
79
+ rerender({ mapState: { zoom: 15 } })
80
+ expect(hints.show).not.toHaveBeenCalled()
81
+ })
82
+ })
@@ -16,6 +16,7 @@ import { isMac } from '../../../src/utils/isMac.js'
16
16
  import { APPLICATION_MODE_ID } from './defaults.js'
17
17
  import { needsDrawTarget } from './utils/needsDrawTarget.js'
18
18
  import { isShapeDrawMode, isCheckedMode } from './utils/drawModes.js'
19
+ import { isBelowSnapMinZoom, getSnapHintText } from './utils/snapMinZoom.js'
19
20
 
20
21
  // edit_point behaves like edit_vertex for Done/Undo, but stays out of drawDeletePoint and mergeShapes (neither applies to a single coordinate).
21
22
 
@@ -115,8 +116,10 @@ export const manifest = {
115
116
  label: 'Snap',
116
117
  iconId: 'magnet',
117
118
  hiddenWhen: ({ pluginState }) => !pluginState.mode || !pluginState.hasSnapLayers,
118
- enableWhen: ({ pluginState }) => !pluginState.holding,
119
+ // Also disabled below snapMinZoom, keeping the user's on/off choice
120
+ enableWhen: ({ pluginConfig, pluginState, mapState }) => !pluginState.holding && !isBelowSnapMinZoom(pluginConfig, mapState.zoom),
119
121
  pressedWhen: ({ pluginState }) => !!pluginState.snap,
122
+ description: ({ pluginConfig, mapState }) => isBelowSnapMinZoom(pluginConfig, mapState.zoom) ? getSnapHintText(pluginConfig) : undefined,
120
123
  ...createButtonSlots(true, TOOLBAR_SLOT)
121
124
  },
122
125
  {
@@ -195,8 +195,21 @@ describe('top row buttons', () => {
195
195
 
196
196
  test('is disabled while Done waits on a check', () => {
197
197
  expect(item().hiddenWhen({ pluginState: { mode: 'draw_line', hasSnapLayers: true, holding: true } })).toBe(false)
198
- expect(item().enableWhen({ pluginState: { holding: true } })).toBe(false)
199
- expect(item().enableWhen({ pluginState: { holding: false } })).toBe(true)
198
+ expect(item().enableWhen({ pluginState: { holding: true }, mapState: {} })).toBe(false)
199
+ expect(item().enableWhen({ pluginState: { holding: false }, mapState: {} })).toBe(true)
200
+ })
201
+
202
+ test('is disabled below snapMinZoom', () => {
203
+ const enabled = (zoom) => item().enableWhen({ pluginConfig: { snapMinZoom: 16 }, pluginState: { holding: false }, mapState: { zoom } })
204
+ expect(enabled(15)).toBe(false)
205
+ expect(enabled(16)).toBe(true)
206
+ })
207
+
208
+ test('is described with the hint below snapMinZoom', () => {
209
+ const description = (pluginConfig, zoom) => item().description({ pluginConfig: { snapMinZoom: 16, ...pluginConfig }, mapState: { zoom } })
210
+ expect(description({}, 15)).toBe('Zoom in to use snap')
211
+ expect(description({ snapZoomInHintText: 'Zoom in further' }, 15)).toBe('Zoom in further')
212
+ expect(description({}, 16)).toBeUndefined()
200
213
  })
201
214
 
202
215
  test('is visible during draw_point, which supports snapping but has no undo/delete', () => {
@@ -0,0 +1,8 @@
1
+ import { SNAP_ZOOM_IN_HINT_TEXT } from '../defaults.js'
2
+
3
+ /** Whether the map is zoomed out below snapMinZoom, so snapping isn't available */
4
+ export const isBelowSnapMinZoom = (pluginConfig, zoom) =>
5
+ typeof pluginConfig?.snapMinZoom === 'number' && typeof zoom === 'number' && zoom < pluginConfig.snapMinZoom
6
+
7
+ /** The hint telling the user to zoom in to use snap */
8
+ export const getSnapHintText = (pluginConfig) => pluginConfig?.snapZoomInHintText ?? SNAP_ZOOM_IN_HINT_TEXT
@@ -0,0 +1,22 @@
1
+ import { isBelowSnapMinZoom, getSnapHintText } from './snapMinZoom.js'
2
+
3
+ describe('isBelowSnapMinZoom', () => {
4
+ test('is true only below snapMinZoom', () => {
5
+ expect(isBelowSnapMinZoom({ snapMinZoom: 16 }, 15.9)).toBe(true)
6
+ expect(isBelowSnapMinZoom({ snapMinZoom: 16 }, 16)).toBe(false)
7
+ })
8
+
9
+ test('is false without a snapMinZoom or a zoom', () => {
10
+ expect(isBelowSnapMinZoom({}, 1)).toBe(false)
11
+ expect(isBelowSnapMinZoom(undefined, 1)).toBe(false)
12
+ expect(isBelowSnapMinZoom({ snapMinZoom: 16 }, undefined)).toBe(false)
13
+ })
14
+ })
15
+
16
+ describe('getSnapHintText', () => {
17
+ test('uses the configured text, or the default', () => {
18
+ expect(getSnapHintText({ snapZoomInHintText: 'Zoom in further' })).toBe('Zoom in further')
19
+ expect(getSnapHintText({})).toBe('Zoom in to use snap')
20
+ expect(getSnapHintText(undefined)).toBe('Zoom in to use snap')
21
+ })
22
+ })