@performant-software/geospatial 1.1.0-beta.0 → 1.1.0-beta.2

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/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{"use strict";var e={n:r=>{var t=r&&r.__esModule?()=>r.default:()=>r;return e.d(t,{a:t}),t},d:(r,t)=>{for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{DrawControl:()=>l,MapDraw:()=>v});const t=require("@mapbox/mapbox-gl-draw");var n=e.n(t);const o=require("react");var a=e.n(o);const u=require("react-map-gl");var i=e.n(u);const l=(0,o.forwardRef)((function(e,r){var t=(0,u.useControl)((function(){return new(n())(e)}),(function(r){var t=r.map;t.on("draw.create",e.onCreate),t.on("draw.update",e.onUpdate),t.on("draw.delete",e.onDelete)}),(function(r){var t=r.map;t.off("draw.create",e.onCreate),t.off("draw.update",e.onUpdate),t.off("draw.delete",e.onDelete)}),{position:e.position});return(0,o.useImperativeHandle)(r,(function(){return t}),[t]),null})),c=require("@turf/turf"),f=require("maplibre-gl");var d=e.n(f);const p=require("underscore");var s=e.n(p);function y(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function b(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function m(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}const v=function(e){var r=(0,o.useRef)(),t=(0,o.useRef)(),n=(0,o.useCallback)((function(){e.onChange(r.current.getAll())}),[e.onChange]),u=(0,o.useMemo)((function(){return function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?b(Object(t),!0).forEach((function(r){m(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):b(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}({height:500,width:"100%"},e.style||{})}),[e.style]);return(0,o.useEffect)((function(){if(e.data){var n=(0,c.bbox)(e.data);if(s().every(n,s().isFinite)){var o=(i=4,function(e){if(Array.isArray(e))return e}(u=n)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a=[],u=!0,i=!1;try{for(t=t.call(e);!(u=(n=t.next()).done)&&(a.push(n.value),!r||a.length!==r);u=!0);}catch(e){i=!0,o=e}finally{try{u||null==t.return||t.return()}finally{if(i)throw o}}return a}}(u,i)||function(e,r){if(e){if("string"==typeof e)return y(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?y(e,r):void 0}}(u,i)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=[[o[0],o[1]],[o[2],o[3]]];t.current.fitBounds(a,{padding:40,duration:1e3})}"GeometryCollection"===e.data.type?s().each(e.data.geometries,(function(e){r.current.add((0,c.feature)(e))})):r.current.add(e.data)}var u,i}),[e.data]),a().createElement(i(),{attributionControl:!1,mapLib:d(),ref:t,style:u,mapStyle:e.mapStyle},a().createElement(l,{ref:r,controls:{line_string:!0,point:!0,polygon:!0,trash:!0},displayControlsDefault:!1,onCreate:n,onUpdate:n,onDelete:n}))};module.exports=r})();
1
+ (()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{DrawControl:()=>l,MapDraw:()=>g});const r=require("@mapbox/mapbox-gl-draw");var n=e.n(r);const o=require("react");var a=e.n(o);const u=require("react-map-gl");var i=e.n(u);const l=(0,o.forwardRef)((function(e,t){var r=(0,u.useControl)((function(){return new(n())(e)}),(function(t){var r=t.map;r.on("draw.create",e.onCreate),r.on("draw.update",e.onUpdate),r.on("draw.delete",e.onDelete)}),(function(t){var r=t.map;r.off("draw.create",e.onCreate),r.off("draw.update",e.onUpdate),r.off("draw.delete",e.onDelete)}),{position:e.position});return(0,o.useImperativeHandle)(t,(function(){return r}),[r]),null})),c=require("@turf/turf"),f=require("maplibre-gl");var d=e.n(f);const s=require("underscore");var p=e.n(s);function y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a=[],u=!0,i=!1;try{for(r=r.call(e);!(u=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);u=!0);}catch(e){i=!0,o=e}finally{try{u||null==r.return||r.return()}finally{if(i)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}const g=function(e){var t=m((0,o.useState)(!1),2),r=t[0],n=t[1],u=(0,o.useRef)(),f=(0,o.useRef)(),s=(0,o.useCallback)((function(){e.onChange(u.current.getAll())}),[e.onChange]),v=(0,o.useMemo)((function(){return function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?y(Object(r),!0).forEach((function(t){b(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({height:500,width:"100%"},e.style||{})}),[e.style]);return(0,o.useEffect)((function(){if(r&&e.data){var t=(0,c.bbox)(e.data);if(p().every(t,p().isFinite)){var n=m(t,4),o=[[n[0],n[1]],[n[2],n[3]]];f.current.fitBounds(o,{padding:40,duration:1e3})}"GeometryCollection"===e.data.type?p().each(e.data.geometries,(function(e){u.current.add((0,c.feature)(e))})):u.current.add(e.data)}}),[r,e.data]),a().createElement(i(),{attributionControl:!1,onLoad:function(){return n(!0)},mapLib:d(),ref:f,style:v,mapStyle:e.mapStyle},a().createElement(l,{ref:u,controls:{line_string:!0,point:!0,polygon:!0,trash:!0},displayControlsDefault:!1,onCreate:s,onUpdate:s,onDelete:s}))};module.exports=t})();
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":"mB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AQ,cCAvC,EAA+BA,QAAQ,e,aCA7C,MAAM,EAA+BA,QAAQ,c,6cCmG7C,QAvEgB,SAACE,GACf,IAAME,GAAUW,EAAAA,EAAAA,UACVC,GAASD,EAAAA,EAAAA,UAOTE,GAAWC,EAAAA,EAAAA,cAAY,WAC3BhB,EAAMe,SAASb,EAAQe,QAAQC,SACjC,GAAG,CAAClB,EAAMe,WAOJI,GAAQC,EAAAA,EAAAA,UAAQ,kB,+VAAA,EAASC,OAAQ,IAAKC,MAAO,QAAYtB,EAAMmB,OAAS,CAAC,EAAC,GAAM,CAACnB,EAAMmB,QA4B7F,OAvBAI,EAAAA,EAAAA,YAAU,WACR,GAAIvB,EAAMwB,KAAM,CAEd,IAAMC,GAAcC,EAAAA,EAAAA,MAAK1B,EAAMwB,MAE/B,GAAIG,IAAAA,MAAQF,EAAaE,IAAAA,UAAa,CACpC,O,EAAoD,E,4CAAXF,I,gxBACnCG,EAAS,CAAC,CADH,KAAQ,MACa,CADL,KAAQ,OAGrCd,EAAOG,QAAQY,UAAUD,EAAQ,CAAEE,QAAS,GAAIC,SAAU,KAC5D,CAGwB,uBAApB/B,EAAMwB,KAAKQ,KACbL,IAAAA,KAAO3B,EAAMwB,KAAKS,YAAY,SAACC,GAC7BhC,EAAQe,QAAQkB,KAAIC,EAAAA,EAAAA,SAAQF,GAC9B,IAEAhC,EAAQe,QAAQkB,IAAInC,EAAMwB,KAE9B,C,OACF,GAAG,CAACxB,EAAMwB,OAGR,kBAAC,IAAG,CACFa,oBAAoB,EACpBC,OAAQC,IACRtC,IAAKa,EACLK,MAAOA,EACPqB,SAAUxC,EAAMwC,UAEhB,kBAAC,EAAW,CACVvC,IAAKC,EACLuC,SAAU,CACRC,aAAa,EACbC,OAAO,EACPC,SAAS,EACTC,OAAO,GAETC,wBAAwB,EACxBvC,SAAUQ,EACVP,SAAUO,EACVN,SAAUM,IAIlB,E","sources":["webpack://@performant-software/geospatial/webpack/bootstrap","webpack://@performant-software/geospatial/webpack/runtime/compat get default export","webpack://@performant-software/geospatial/webpack/runtime/define property getters","webpack://@performant-software/geospatial/webpack/runtime/hasOwnProperty shorthand","webpack://@performant-software/geospatial/webpack/runtime/make namespace object","webpack://@performant-software/geospatial/external commonjs \"@mapbox/mapbox-gl-draw\"","webpack://@performant-software/geospatial/external commonjs2 \"react\"","webpack://@performant-software/geospatial/external commonjs \"react-map-gl\"","webpack://@performant-software/geospatial/./src/components/DrawControl.js","webpack://@performant-software/geospatial/external commonjs \"@turf/turf\"","webpack://@performant-software/geospatial/external commonjs \"maplibre-gl\"","webpack://@performant-software/geospatial/external commonjs \"underscore\"","webpack://@performant-software/geospatial/./src/components/MapDraw.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mapbox/mapbox-gl-draw\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react-map-gl\");","// @flow\n\nimport MapboxDraw from '@mapbox/mapbox-gl-draw';\nimport { forwardRef, useImperativeHandle } from 'react';\nimport { useControl, type ControlPosition, type MapRef } from 'react-map-gl';\n\ntype Props = {\n position?: ControlPosition;\n onCreate?: (evt: { features: Array<any> }) => void;\n onUpdate?: (evt: { features: Array<any>, action: string }) => void;\n onDelete?: (evt: { features: Array<any> }) => void;\n};\n\nconst DrawControl = forwardRef((props: Props, ref) => {\n /**\n * Creates the drawer ref using MapboxDraw.\n */\n const drawRef = useControl(\n () => new MapboxDraw(props),\n ({ map }: { map: MapRef }) => {\n map.on('draw.create', props.onCreate);\n map.on('draw.update', props.onUpdate);\n map.on('draw.delete', props.onDelete);\n },\n ({ map }: { map: MapRef }) => {\n map.off('draw.create', props.onCreate);\n map.off('draw.update', props.onUpdate);\n map.off('draw.delete', props.onDelete);\n },\n {\n position: props.position\n }\n );\n\n /**\n * Exposes the ref for the MapboxDraw object.\n */\n useImperativeHandle(ref, () => drawRef, [drawRef]);\n\n return null;\n});\n\nexport default DrawControl;\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@turf/turf\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"maplibre-gl\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"underscore\");","// @flow\n\nimport MapboxDraw from '@mapbox/mapbox-gl-draw';\nimport {\n bbox,\n feature,\n type FeatureCollection,\n type GeometryCollection\n} from '@turf/turf';\nimport maplibregl from 'maplibre-gl';\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport Map, { MapRef } from 'react-map-gl';\nimport _ from 'underscore';\nimport DrawControl from './DrawControl';\nimport './MapDraw.css';\n\ntype Props = {\n data: GeometryCollection | FeatureCollection,\n mapStyle: string,\n onChange: (features: Array<any>) => void,\n style?: any\n};\n\nconst MapDraw = (props: Props) => {\n const drawRef = useRef<MapboxDraw>();\n const mapRef = useRef<MapRef>();\n\n /**\n * Calls the onChange prop with all of the geometries in the current drawer.\n *\n * @type {(function(): void)|*}\n */\n const onChange = useCallback(() => {\n props.onChange(drawRef.current.getAll());\n }, [props.onChange]);\n\n /**\n * Sets the map style.\n *\n * @type {{width: string, height: number}}\n */\n const style = useMemo(() => ({ height: 500, width: '100%', ...(props.style || {}) }), [props.style]);\n\n /**\n * Updates the map bounding box and drawer when the geometry is changed.\n */\n useEffect(() => {\n if (props.data) {\n // Sets the bounding box for the current geometry.\n const boundingBox = bbox(props.data);\n\n if (_.every(boundingBox, _.isFinite)) {\n const [minLng, minLat, maxLng, maxLat] = boundingBox;\n const bounds = [[minLng, minLat], [maxLng, maxLat]];\n\n mapRef.current.fitBounds(bounds, { padding: 40, duration: 1000 });\n }\n\n // Handle special case for geometry collection (not supported by mabox-gl-draw)\n if (props.data.type === 'GeometryCollection') {\n _.each(props.data.geometries, (geometry) => {\n drawRef.current.add(feature(geometry));\n });\n } else {\n drawRef.current.add(props.data);\n }\n }\n }, [props.data]);\n\n return (\n <Map\n attributionControl={false}\n mapLib={maplibregl}\n ref={mapRef}\n style={style}\n mapStyle={props.mapStyle}\n >\n <DrawControl\n ref={drawRef}\n controls={{\n line_string: true,\n point: true,\n polygon: true,\n trash: true\n }}\n displayControlsDefault={false}\n onCreate={onChange}\n onUpdate={onChange}\n onDelete={onChange}\n />\n </Map>\n );\n};\n\nexport default MapDraw;\n"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","forwardRef","props","ref","drawRef","useControl","MapboxDraw","map","on","onCreate","onUpdate","onDelete","off","position","useImperativeHandle","useRef","mapRef","onChange","useCallback","current","getAll","style","useMemo","height","width","useEffect","data","boundingBox","bbox","_","bounds","fitBounds","padding","duration","type","geometries","geometry","add","feature","attributionControl","mapLib","maplibregl","mapStyle","controls","line_string","point","polygon","trash","displayControlsDefault"],"sourceRoot":""}
1
+ {"version":3,"file":"index.js","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAyBC,IACxB,IAAIC,EAASD,GAAUA,EAAOE,WAC7B,IAAOF,EAAiB,QACxB,IAAM,EAEP,OADAD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/webpack/runtime/compat get default export","webpack://@performant-software/geospatial/webpack/runtime/define property getters","webpack://@performant-software/geospatial/webpack/runtime/hasOwnProperty shorthand","webpack://@performant-software/geospatial/webpack/runtime/make namespace object","webpack://@performant-software/geospatial/external commonjs \"@mapbox/mapbox-gl-draw\"","webpack://@performant-software/geospatial/external commonjs2 \"react\"","webpack://@performant-software/geospatial/external commonjs \"react-map-gl\"","webpack://@performant-software/geospatial/./src/components/DrawControl.js","webpack://@performant-software/geospatial/external commonjs \"@turf/turf\"","webpack://@performant-software/geospatial/external commonjs \"maplibre-gl\"","webpack://@performant-software/geospatial/external commonjs \"underscore\"","webpack://@performant-software/geospatial/./src/components/MapDraw.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mapbox/mapbox-gl-draw\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react-map-gl\");","// @flow\n\nimport MapboxDraw from '@mapbox/mapbox-gl-draw';\nimport { forwardRef, useImperativeHandle } from 'react';\nimport { useControl, type ControlPosition, type MapRef } from 'react-map-gl';\n\ntype Props = {\n position?: ControlPosition;\n onCreate?: (evt: { features: Array<any> }) => void;\n onUpdate?: (evt: { features: Array<any>, action: string }) => void;\n onDelete?: (evt: { features: Array<any> }) => void;\n};\n\nconst DrawControl = forwardRef((props: Props, ref) => {\n /**\n * Creates the drawer ref using MapboxDraw.\n */\n const drawRef = useControl(\n () => new MapboxDraw(props),\n ({ map }: { map: MapRef }) => {\n map.on('draw.create', props.onCreate);\n map.on('draw.update', props.onUpdate);\n map.on('draw.delete', props.onDelete);\n },\n ({ map }: { map: MapRef }) => {\n map.off('draw.create', props.onCreate);\n map.off('draw.update', props.onUpdate);\n map.off('draw.delete', props.onDelete);\n },\n {\n position: props.position\n }\n );\n\n /**\n * Exposes the ref for the MapboxDraw object.\n */\n useImperativeHandle(ref, () => drawRef, [drawRef]);\n\n return null;\n});\n\nexport default DrawControl;\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@turf/turf\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"maplibre-gl\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"underscore\");","// @flow\n\nimport MapboxDraw from '@mapbox/mapbox-gl-draw';\nimport {\n bbox,\n feature,\n type FeatureCollection,\n type GeometryCollection\n} from '@turf/turf';\nimport maplibregl from 'maplibre-gl';\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState\n} from 'react';\nimport Map, { MapRef } from 'react-map-gl';\nimport _ from 'underscore';\nimport DrawControl from './DrawControl';\nimport './MapDraw.css';\n\ntype Props = {\n /**\n * GeoJSON structured data to be displayed on the map.\n */\n data: GeometryCollection | FeatureCollection,\n\n /**\n * URL of the map style to render. This URL should contain any necessary API keys.\n */\n mapStyle: string,\n\n /**\n * Callback fired when the map geometries are changed.\n *\n * @param features\n */\n onChange: (features: Array<any>) => void,\n\n /**\n * Map style object.\n */\n style?: any\n};\n\nconst GeometryTypes = {\n geometryCollection: 'GeometryCollection',\n point: 'Point'\n};\n\n/**\n * This component renders a map with controls for drawing one or more geometries. Geometries can be a point (lat/long),\n * a line, or a polygon.\n */\nconst MapDraw = (props: Props) => {\n const [loaded, setLoaded] = useState(false);\n\n const drawRef = useRef<MapboxDraw>();\n const mapRef = useRef<MapRef>();\n\n /**\n * Calls the onChange prop with all of the geometries in the current drawer.\n *\n * @type {(function(): void)|*}\n */\n const onChange = useCallback(() => {\n props.onChange(drawRef.current.getAll());\n }, [props.onChange]);\n\n /**\n * Sets the map style.\n *\n * @type {{width: string, height: number}}\n */\n const style = useMemo(() => ({ height: 500, width: '100%', ...(props.style || {}) }), [props.style]);\n\n /**\n * Updates the map bounding box and drawer when the geometry is changed.\n */\n useEffect(() => {\n if (loaded && props.data) {\n // Sets the bounding box for the current geometry.\n const boundingBox = bbox(props.data);\n\n if (_.every(boundingBox, _.isFinite)) {\n const [minLng, minLat, maxLng, maxLat] = boundingBox;\n const bounds = [[minLng, minLat], [maxLng, maxLat]];\n\n mapRef.current.fitBounds(bounds, { padding: 40, duration: 1000 });\n }\n\n // Handle special cases for geometry collection (not supported by mabox-gl-draw) and point\n if (props.data.type === GeometryTypes.geometryCollection) {\n _.each(props.data.geometries, (geometry) => {\n drawRef.current.add(feature(geometry));\n });\n } else {\n drawRef.current.add(props.data);\n }\n }\n }, [loaded, props.data]);\n\n return (\n <Map\n attributionControl={false}\n onLoad={() => setLoaded(true)}\n mapLib={maplibregl}\n ref={mapRef}\n style={style}\n mapStyle={props.mapStyle}\n >\n <DrawControl\n ref={drawRef}\n controls={{\n line_string: true,\n point: true,\n polygon: true,\n trash: true\n }}\n displayControlsDefault={false}\n onCreate={onChange}\n onUpdate={onChange}\n onDelete={onChange}\n />\n </Map>\n );\n};\n\nexport default MapDraw;\n"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","forwardRef","props","ref","drawRef","useControl","MapboxDraw","map","on","onCreate","onUpdate","onDelete","off","position","useImperativeHandle","useState","loaded","setLoaded","useRef","mapRef","onChange","useCallback","current","getAll","style","useMemo","height","width","useEffect","data","boundingBox","bbox","_","bounds","fitBounds","padding","duration","type","geometries","geometry","add","feature","attributionControl","onLoad","mapLib","maplibregl","mapStyle","controls","line_string","point","polygon","trash","displayControlsDefault"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@performant-software/geospatial",
3
- "version": "1.1.0-beta.0",
3
+ "version": "1.1.0-beta.2",
4
4
  "description": "TODO: ADD",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",
@@ -13,6 +13,7 @@ import React, {
13
13
  useEffect,
14
14
  useMemo,
15
15
  useRef,
16
+ useState
16
17
  } from 'react';
17
18
  import Map, { MapRef } from 'react-map-gl';
18
19
  import _ from 'underscore';
@@ -20,13 +21,41 @@ import DrawControl from './DrawControl';
20
21
  import './MapDraw.css';
21
22
 
22
23
  type Props = {
24
+ /**
25
+ * GeoJSON structured data to be displayed on the map.
26
+ */
23
27
  data: GeometryCollection | FeatureCollection,
28
+
29
+ /**
30
+ * URL of the map style to render. This URL should contain any necessary API keys.
31
+ */
24
32
  mapStyle: string,
33
+
34
+ /**
35
+ * Callback fired when the map geometries are changed.
36
+ *
37
+ * @param features
38
+ */
25
39
  onChange: (features: Array<any>) => void,
40
+
41
+ /**
42
+ * Map style object.
43
+ */
26
44
  style?: any
27
45
  };
28
46
 
47
+ const GeometryTypes = {
48
+ geometryCollection: 'GeometryCollection',
49
+ point: 'Point'
50
+ };
51
+
52
+ /**
53
+ * This component renders a map with controls for drawing one or more geometries. Geometries can be a point (lat/long),
54
+ * a line, or a polygon.
55
+ */
29
56
  const MapDraw = (props: Props) => {
57
+ const [loaded, setLoaded] = useState(false);
58
+
30
59
  const drawRef = useRef<MapboxDraw>();
31
60
  const mapRef = useRef<MapRef>();
32
61
 
@@ -50,7 +79,7 @@ const MapDraw = (props: Props) => {
50
79
  * Updates the map bounding box and drawer when the geometry is changed.
51
80
  */
52
81
  useEffect(() => {
53
- if (props.data) {
82
+ if (loaded && props.data) {
54
83
  // Sets the bounding box for the current geometry.
55
84
  const boundingBox = bbox(props.data);
56
85
 
@@ -61,8 +90,8 @@ const MapDraw = (props: Props) => {
61
90
  mapRef.current.fitBounds(bounds, { padding: 40, duration: 1000 });
62
91
  }
63
92
 
64
- // Handle special case for geometry collection (not supported by mabox-gl-draw)
65
- if (props.data.type === 'GeometryCollection') {
93
+ // Handle special cases for geometry collection (not supported by mabox-gl-draw) and point
94
+ if (props.data.type === GeometryTypes.geometryCollection) {
66
95
  _.each(props.data.geometries, (geometry) => {
67
96
  drawRef.current.add(feature(geometry));
68
97
  });
@@ -70,11 +99,12 @@ const MapDraw = (props: Props) => {
70
99
  drawRef.current.add(props.data);
71
100
  }
72
101
  }
73
- }, [props.data]);
102
+ }, [loaded, props.data]);
74
103
 
75
104
  return (
76
105
  <Map
77
106
  attributionControl={false}
107
+ onLoad={() => setLoaded(true)}
78
108
  mapLib={maplibregl}
79
109
  ref={mapRef}
80
110
  style={style}
@@ -13,6 +13,7 @@ import React, {
13
13
  useEffect,
14
14
  useMemo,
15
15
  useRef,
16
+ useState
16
17
  } from 'react';
17
18
  import Map, { MapRef } from 'react-map-gl';
18
19
  import _ from 'underscore';
@@ -20,13 +21,41 @@ import DrawControl from './DrawControl';
20
21
  import './MapDraw.css';
21
22
 
22
23
  type Props = {
24
+ /**
25
+ * GeoJSON structured data to be displayed on the map.
26
+ */
23
27
  data: GeometryCollection | FeatureCollection,
28
+
29
+ /**
30
+ * URL of the map style to render. This URL should contain any necessary API keys.
31
+ */
24
32
  mapStyle: string,
33
+
34
+ /**
35
+ * Callback fired when the map geometries are changed.
36
+ *
37
+ * @param features
38
+ */
25
39
  onChange: (features: Array<any>) => void,
40
+
41
+ /**
42
+ * Map style object.
43
+ */
26
44
  style?: any
27
45
  };
28
46
 
47
+ const GeometryTypes = {
48
+ geometryCollection: 'GeometryCollection',
49
+ point: 'Point'
50
+ };
51
+
52
+ /**
53
+ * This component renders a map with controls for drawing one or more geometries. Geometries can be a point (lat/long),
54
+ * a line, or a polygon.
55
+ */
29
56
  const MapDraw = (props: Props) => {
57
+ const [loaded, setLoaded] = useState(false);
58
+
30
59
  const drawRef = useRef<MapboxDraw>();
31
60
  const mapRef = useRef<MapRef>();
32
61
 
@@ -50,7 +79,7 @@ const MapDraw = (props: Props) => {
50
79
  * Updates the map bounding box and drawer when the geometry is changed.
51
80
  */
52
81
  useEffect(() => {
53
- if (props.data) {
82
+ if (loaded && props.data) {
54
83
  // Sets the bounding box for the current geometry.
55
84
  const boundingBox = bbox(props.data);
56
85
 
@@ -61,8 +90,8 @@ const MapDraw = (props: Props) => {
61
90
  mapRef.current.fitBounds(bounds, { padding: 40, duration: 1000 });
62
91
  }
63
92
 
64
- // Handle special case for geometry collection (not supported by mabox-gl-draw)
65
- if (props.data.type === 'GeometryCollection') {
93
+ // Handle special cases for geometry collection (not supported by mabox-gl-draw) and point
94
+ if (props.data.type === GeometryTypes.geometryCollection) {
66
95
  _.each(props.data.geometries, (geometry) => {
67
96
  drawRef.current.add(feature(geometry));
68
97
  });
@@ -70,11 +99,12 @@ const MapDraw = (props: Props) => {
70
99
  drawRef.current.add(props.data);
71
100
  }
72
101
  }
73
- }, [props.data]);
102
+ }, [loaded, props.data]);
74
103
 
75
104
  return (
76
105
  <Map
77
106
  attributionControl={false}
107
+ onLoad={() => setLoaded(true)}
78
108
  mapLib={maplibregl}
79
109
  ref={mapRef}
80
110
  style={style}