@performant-software/geospatial 1.1.0-beta.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Performant Software Solutions LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
package/build/index.js ADDED
@@ -0,0 +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})();
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAyBC,IACxB,IAAIC,EAASD,GAAUA,EAAOE,WAC7B,IAAOF,EAAiB,QACxB,IAAM,EAEP,OADAD,EAAoBI,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdF,EAAwB,CAACM,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXP,EAAoBS,EAAEF,EAAYC,KAASR,EAAoBS,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDR,EAAwB,CAACc,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFf,EAAyBM,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,GAAO,G,qDCL9D,MAAM,EAA+BC,QAAQ,0B,aCA7C,MAAM,EAA+BA,QAAQ,S,aCA7C,MAAM,EAA+BA,QAAQ,gB,aC0C7C,SA7BoBC,EAAAA,EAAAA,aAAW,SAACC,EAAcC,GAI5C,IAAMC,GAAUC,EAAAA,EAAAA,aACd,kBAAM,IAAIC,IAAJ,CAAeJ,EAAM,IAC3B,YAA8B,IAA3BK,EAAG,EAAHA,IACDA,EAAIC,GAAG,cAAeN,EAAMO,UAC5BF,EAAIC,GAAG,cAAeN,EAAMQ,UAC5BH,EAAIC,GAAG,cAAeN,EAAMS,SAC9B,IACA,YAA8B,IAA3BJ,EAAG,EAAHA,IACDA,EAAIK,IAAI,cAAeV,EAAMO,UAC7BF,EAAIK,IAAI,cAAeV,EAAMQ,UAC7BH,EAAIK,IAAI,cAAeV,EAAMS,SAC/B,GACA,CACEE,SAAUX,EAAMW,WASpB,OAFAC,EAAAA,EAAAA,qBAAoBX,GAAK,kBAAMC,CAAO,GAAE,CAACA,IAElC,IACT,ICxCM,EAA+BJ,QAAQ,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":""}
package/build/main.css ADDED
@@ -0,0 +1,91 @@
1
+
2
+ /* Override default control style */
3
+ .mapbox-gl-draw_ctrl-bottom-left,
4
+ .mapbox-gl-draw_ctrl-top-left {
5
+ margin-left:0;
6
+ border-radius:0 4px 4px 0;
7
+ }
8
+ .mapbox-gl-draw_ctrl-top-right,
9
+ .mapbox-gl-draw_ctrl-bottom-right {
10
+ margin-right:0;
11
+ border-radius:4px 0 0 4px;
12
+ }
13
+
14
+ .mapbox-gl-draw_ctrl-draw-btn {
15
+ border-color:rgba(0,0,0,0.9);
16
+ color:rgba(255,255,255,0.5);
17
+ width:30px;
18
+ height:30px;
19
+ }
20
+
21
+ .mapbox-gl-draw_ctrl-draw-btn.active,
22
+ .mapbox-gl-draw_ctrl-draw-btn.active:hover {
23
+ background-color:rgb(0 0 0/5%);
24
+ }
25
+ .mapbox-gl-draw_ctrl-draw-btn {
26
+ background-repeat: no-repeat;
27
+ background-position: center;
28
+ }
29
+
30
+ .mapbox-gl-draw_point {
31
+ background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20">%3Cpath d="m10 2c-3.3 0-6 2.7-6 6s6 9 6 9 6-5.7 6-9-2.7-6-6-6zm0 2c2.1 0 3.8 1.7 3.8 3.8 0 1.5-1.8 3.9-2.9 5.2h-1.7c-1.1-1.4-2.9-3.8-2.9-5.2-.1-2.1 1.6-3.8 3.7-3.8z"/>%3C/svg>');
32
+ }
33
+ .mapbox-gl-draw_polygon {
34
+ background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20">%3Cpath d="m15 12.3v-4.6c.6-.3 1-1 1-1.7 0-1.1-.9-2-2-2-.7 0-1.4.4-1.7 1h-4.6c-.3-.6-1-1-1.7-1-1.1 0-2 .9-2 2 0 .7.4 1.4 1 1.7v4.6c-.6.3-1 1-1 1.7 0 1.1.9 2 2 2 .7 0 1.4-.4 1.7-1h4.6c.3.6 1 1 1.7 1 1.1 0 2-.9 2-2 0-.7-.4-1.4-1-1.7zm-8-.3v-4l1-1h4l1 1v4l-1 1h-4z"/>%3C/svg>');
35
+ }
36
+ .mapbox-gl-draw_line {
37
+ background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20">%3Cpath d="m13.5 3.5c-1.4 0-2.5 1.1-2.5 2.5 0 .3 0 .6.2.9l-3.8 3.8c-.3-.1-.6-.2-.9-.2-1.4 0-2.5 1.1-2.5 2.5s1.1 2.5 2.5 2.5 2.5-1.1 2.5-2.5c0-.3 0-.6-.2-.9l3.8-3.8c.3.1.6.2.9.2 1.4 0 2.5-1.1 2.5-2.5s-1.1-2.5-2.5-2.5z"/>%3C/svg>');
38
+ }
39
+ .mapbox-gl-draw_trash {
40
+ background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20">%3Cpath d="M10,3.4 c-0.8,0-1.5,0.5-1.8,1.2H5l-1,1v1h12v-1l-1-1h-3.2C11.5,3.9,10.8,3.4,10,3.4z M5,8v7c0,1,1,2,2,2h6c1,0,2-1,2-2V8h-2v5.5h-1.5V8h-3 v5.5H7V8H5z"/>%3C/svg>');
41
+ }
42
+ .mapbox-gl-draw_uncombine {
43
+ background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20">%3Cpath d="m12 2c-.3 0-.5.1-.7.3l-1 1c-.4.4-.4 1 0 1.4l1 1c.4.4 1 .4 1.4 0l1-1c.4-.4.4-1 0-1.4l-1-1c-.2-.2-.4-.3-.7-.3zm4 4c-.3 0-.5.1-.7.3l-1 1c-.4.4-.4 1 0 1.4l1 1c.4.4 1 .4 1.4 0l1-1c.4-.4.4-1 0-1.4l-1-1c-.2-.2-.4-.3-.7-.3zm-7 1c-1 0-1 1-.5 1.5.3.3 1 1 1 1l-1 1s-.5.5 0 1 1 0 1 0l1-1 1 1c.5.5 1.5.5 1.5-.5v-4zm-5 3c-.3 0-.5.1-.7.3l-1 1c-.4.4-.4 1 0 1.4l4.9 4.9c.4.4 1 .4 1.4 0l1-1c.4-.4.4-1 0-1.4l-4.9-4.9c-.1-.2-.4-.3-.7-.3z"/>%3C/svg>');
44
+ }
45
+ .mapbox-gl-draw_combine {
46
+ background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20">%3Cpath d="M12.1,2c-0.3,0-0.5,0.1-0.7,0.3l-1,1c-0.4,0.4-0.4,1,0,1.4l4.9,4.9c0.4,0.4,1,0.4,1.4,0l1-1 c0.4-0.4,0.4-1,0-1.4l-4.9-4.9C12.6,2.1,12.3,2,12.1,2z M8,8C7,8,7,9,7.5,9.5c0.3,0.3,1,1,1,1l-1,1c0,0-0.5,0.5,0,1s1,0,1,0l1-1l1,1 C11,13,12,13,12,12V8H8z M4,10c-0.3,0-0.5,0.1-0.7,0.3l-1,1c-0.4,0.4-0.4,1,0,1.4l1,1c0.4,0.4,1,0.4,1.4,0l1-1c0.4-0.4,0.4-1,0-1.4 l-1-1C4.5,10.1,4.3,10,4,10z M8,14c-0.3,0-0.5,0.1-0.7,0.3l-1,1c-0.4,0.4-0.4,1,0,1.4l1,1c0.4,0.4,1,0.4,1.4,0l1-1 c0.4-0.4,0.4-1,0-1.4l-1-1C8.5,14.1,8.3,14,8,14z"/>%3C/svg>');
47
+ }
48
+
49
+ .mapboxgl-map.mouse-pointer .mapboxgl-canvas-container.mapboxgl-interactive {
50
+ cursor: pointer;
51
+ }
52
+ .mapboxgl-map.mouse-move .mapboxgl-canvas-container.mapboxgl-interactive {
53
+ cursor: move;
54
+ }
55
+ .mapboxgl-map.mouse-add .mapboxgl-canvas-container.mapboxgl-interactive {
56
+ cursor: crosshair;
57
+ }
58
+ .mapboxgl-map.mouse-move.mode-direct_select .mapboxgl-canvas-container.mapboxgl-interactive {
59
+ cursor: grab;
60
+ cursor: -moz-grab;
61
+ cursor: -webkit-grab;
62
+ }
63
+ .mapboxgl-map.mode-direct_select.feature-vertex.mouse-move .mapboxgl-canvas-container.mapboxgl-interactive {
64
+ cursor: move;
65
+ }
66
+ .mapboxgl-map.mode-direct_select.feature-midpoint.mouse-pointer .mapboxgl-canvas-container.mapboxgl-interactive {
67
+ cursor: cell;
68
+ }
69
+ .mapboxgl-map.mode-direct_select.feature-feature.mouse-move .mapboxgl-canvas-container.mapboxgl-interactive {
70
+ cursor: move;
71
+ }
72
+ .mapboxgl-map.mode-static.mouse-pointer .mapboxgl-canvas-container.mapboxgl-interactive {
73
+ cursor: grab;
74
+ cursor: -moz-grab;
75
+ cursor: -webkit-grab;
76
+ }
77
+
78
+ .mapbox-gl-draw_boxselect {
79
+ pointer-events: none;
80
+ position: absolute;
81
+ top: 0;
82
+ left: 0;
83
+ width: 0;
84
+ height: 0;
85
+ background: rgba(0,0,0,.1);
86
+ border: 2px dotted #fff;
87
+ opacity: 0.5;
88
+ }
89
+
90
+
91
+
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./build/index');
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@performant-software/geospatial",
3
+ "version": "1.1.0-beta.0",
4
+ "description": "TODO: ADD",
5
+ "license": "MIT",
6
+ "main": "./build/index.js",
7
+ "style": "./build/main.css",
8
+ "scripts": {
9
+ "build": "webpack --mode production && flow-copy-source -v src types"
10
+ },
11
+ "dependencies": {
12
+ "@mapbox/mapbox-gl-draw": "^1.4.3",
13
+ "@turf/turf": "^6.5.0",
14
+ "mapbox-gl": "npm:empty-npm-package@1.0.0",
15
+ "maplibre-gl": "^3.5.2",
16
+ "react-map-gl": "^7.1.6",
17
+ "underscore": "^1.13.6"
18
+ },
19
+ "peerDependencies": {
20
+ "react": ">= 16.13.1 < 19.0.0",
21
+ "react-dom": ">= 16.13.1 < 19.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@performant-software/webpack-config": "^1.0.0",
25
+ "react": "^18.2.0",
26
+ "react-dom": "^18.2.0"
27
+ }
28
+ }
@@ -0,0 +1,43 @@
1
+ // @flow
2
+
3
+ import MapboxDraw from '@mapbox/mapbox-gl-draw';
4
+ import { forwardRef, useImperativeHandle } from 'react';
5
+ import { useControl, type ControlPosition, type MapRef } from 'react-map-gl';
6
+
7
+ type Props = {
8
+ position?: ControlPosition;
9
+ onCreate?: (evt: { features: Array<any> }) => void;
10
+ onUpdate?: (evt: { features: Array<any>, action: string }) => void;
11
+ onDelete?: (evt: { features: Array<any> }) => void;
12
+ };
13
+
14
+ const DrawControl = forwardRef((props: Props, ref) => {
15
+ /**
16
+ * Creates the drawer ref using MapboxDraw.
17
+ */
18
+ const drawRef = useControl(
19
+ () => new MapboxDraw(props),
20
+ ({ map }: { map: MapRef }) => {
21
+ map.on('draw.create', props.onCreate);
22
+ map.on('draw.update', props.onUpdate);
23
+ map.on('draw.delete', props.onDelete);
24
+ },
25
+ ({ map }: { map: MapRef }) => {
26
+ map.off('draw.create', props.onCreate);
27
+ map.off('draw.update', props.onUpdate);
28
+ map.off('draw.delete', props.onDelete);
29
+ },
30
+ {
31
+ position: props.position
32
+ }
33
+ );
34
+
35
+ /**
36
+ * Exposes the ref for the MapboxDraw object.
37
+ */
38
+ useImperativeHandle(ref, () => drawRef, [drawRef]);
39
+
40
+ return null;
41
+ });
42
+
43
+ export default DrawControl;
@@ -0,0 +1 @@
1
+ @import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
@@ -0,0 +1,100 @@
1
+ // @flow
2
+
3
+ import MapboxDraw from '@mapbox/mapbox-gl-draw';
4
+ import {
5
+ bbox,
6
+ feature,
7
+ type FeatureCollection,
8
+ type GeometryCollection
9
+ } from '@turf/turf';
10
+ import maplibregl from 'maplibre-gl';
11
+ import React, {
12
+ useCallback,
13
+ useEffect,
14
+ useMemo,
15
+ useRef,
16
+ } from 'react';
17
+ import Map, { MapRef } from 'react-map-gl';
18
+ import _ from 'underscore';
19
+ import DrawControl from './DrawControl';
20
+ import './MapDraw.css';
21
+
22
+ type Props = {
23
+ data: GeometryCollection | FeatureCollection,
24
+ mapStyle: string,
25
+ onChange: (features: Array<any>) => void,
26
+ style?: any
27
+ };
28
+
29
+ const MapDraw = (props: Props) => {
30
+ const drawRef = useRef<MapboxDraw>();
31
+ const mapRef = useRef<MapRef>();
32
+
33
+ /**
34
+ * Calls the onChange prop with all of the geometries in the current drawer.
35
+ *
36
+ * @type {(function(): void)|*}
37
+ */
38
+ const onChange = useCallback(() => {
39
+ props.onChange(drawRef.current.getAll());
40
+ }, [props.onChange]);
41
+
42
+ /**
43
+ * Sets the map style.
44
+ *
45
+ * @type {{width: string, height: number}}
46
+ */
47
+ const style = useMemo(() => ({ height: 500, width: '100%', ...(props.style || {}) }), [props.style]);
48
+
49
+ /**
50
+ * Updates the map bounding box and drawer when the geometry is changed.
51
+ */
52
+ useEffect(() => {
53
+ if (props.data) {
54
+ // Sets the bounding box for the current geometry.
55
+ const boundingBox = bbox(props.data);
56
+
57
+ if (_.every(boundingBox, _.isFinite)) {
58
+ const [minLng, minLat, maxLng, maxLat] = boundingBox;
59
+ const bounds = [[minLng, minLat], [maxLng, maxLat]];
60
+
61
+ mapRef.current.fitBounds(bounds, { padding: 40, duration: 1000 });
62
+ }
63
+
64
+ // Handle special case for geometry collection (not supported by mabox-gl-draw)
65
+ if (props.data.type === 'GeometryCollection') {
66
+ _.each(props.data.geometries, (geometry) => {
67
+ drawRef.current.add(feature(geometry));
68
+ });
69
+ } else {
70
+ drawRef.current.add(props.data);
71
+ }
72
+ }
73
+ }, [props.data]);
74
+
75
+ return (
76
+ <Map
77
+ attributionControl={false}
78
+ mapLib={maplibregl}
79
+ ref={mapRef}
80
+ style={style}
81
+ mapStyle={props.mapStyle}
82
+ >
83
+ <DrawControl
84
+ ref={drawRef}
85
+ controls={{
86
+ line_string: true,
87
+ point: true,
88
+ polygon: true,
89
+ trash: true
90
+ }}
91
+ displayControlsDefault={false}
92
+ onCreate={onChange}
93
+ onUpdate={onChange}
94
+ onDelete={onChange}
95
+ />
96
+ </Map>
97
+ );
98
+ };
99
+
100
+ export default MapDraw;
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // @flow
2
+
3
+ // Components
4
+ export { default as DrawControl } from './components/DrawControl';
5
+ export { default as MapDraw } from './components/MapDraw';
@@ -0,0 +1,43 @@
1
+ // @flow
2
+
3
+ import MapboxDraw from '@mapbox/mapbox-gl-draw';
4
+ import { forwardRef, useImperativeHandle } from 'react';
5
+ import { useControl, type ControlPosition, type MapRef } from 'react-map-gl';
6
+
7
+ type Props = {
8
+ position?: ControlPosition;
9
+ onCreate?: (evt: { features: Array<any> }) => void;
10
+ onUpdate?: (evt: { features: Array<any>, action: string }) => void;
11
+ onDelete?: (evt: { features: Array<any> }) => void;
12
+ };
13
+
14
+ const DrawControl = forwardRef((props: Props, ref) => {
15
+ /**
16
+ * Creates the drawer ref using MapboxDraw.
17
+ */
18
+ const drawRef = useControl(
19
+ () => new MapboxDraw(props),
20
+ ({ map }: { map: MapRef }) => {
21
+ map.on('draw.create', props.onCreate);
22
+ map.on('draw.update', props.onUpdate);
23
+ map.on('draw.delete', props.onDelete);
24
+ },
25
+ ({ map }: { map: MapRef }) => {
26
+ map.off('draw.create', props.onCreate);
27
+ map.off('draw.update', props.onUpdate);
28
+ map.off('draw.delete', props.onDelete);
29
+ },
30
+ {
31
+ position: props.position
32
+ }
33
+ );
34
+
35
+ /**
36
+ * Exposes the ref for the MapboxDraw object.
37
+ */
38
+ useImperativeHandle(ref, () => drawRef, [drawRef]);
39
+
40
+ return null;
41
+ });
42
+
43
+ export default DrawControl;
@@ -0,0 +1,100 @@
1
+ // @flow
2
+
3
+ import MapboxDraw from '@mapbox/mapbox-gl-draw';
4
+ import {
5
+ bbox,
6
+ feature,
7
+ type FeatureCollection,
8
+ type GeometryCollection
9
+ } from '@turf/turf';
10
+ import maplibregl from 'maplibre-gl';
11
+ import React, {
12
+ useCallback,
13
+ useEffect,
14
+ useMemo,
15
+ useRef,
16
+ } from 'react';
17
+ import Map, { MapRef } from 'react-map-gl';
18
+ import _ from 'underscore';
19
+ import DrawControl from './DrawControl';
20
+ import './MapDraw.css';
21
+
22
+ type Props = {
23
+ data: GeometryCollection | FeatureCollection,
24
+ mapStyle: string,
25
+ onChange: (features: Array<any>) => void,
26
+ style?: any
27
+ };
28
+
29
+ const MapDraw = (props: Props) => {
30
+ const drawRef = useRef<MapboxDraw>();
31
+ const mapRef = useRef<MapRef>();
32
+
33
+ /**
34
+ * Calls the onChange prop with all of the geometries in the current drawer.
35
+ *
36
+ * @type {(function(): void)|*}
37
+ */
38
+ const onChange = useCallback(() => {
39
+ props.onChange(drawRef.current.getAll());
40
+ }, [props.onChange]);
41
+
42
+ /**
43
+ * Sets the map style.
44
+ *
45
+ * @type {{width: string, height: number}}
46
+ */
47
+ const style = useMemo(() => ({ height: 500, width: '100%', ...(props.style || {}) }), [props.style]);
48
+
49
+ /**
50
+ * Updates the map bounding box and drawer when the geometry is changed.
51
+ */
52
+ useEffect(() => {
53
+ if (props.data) {
54
+ // Sets the bounding box for the current geometry.
55
+ const boundingBox = bbox(props.data);
56
+
57
+ if (_.every(boundingBox, _.isFinite)) {
58
+ const [minLng, minLat, maxLng, maxLat] = boundingBox;
59
+ const bounds = [[minLng, minLat], [maxLng, maxLat]];
60
+
61
+ mapRef.current.fitBounds(bounds, { padding: 40, duration: 1000 });
62
+ }
63
+
64
+ // Handle special case for geometry collection (not supported by mabox-gl-draw)
65
+ if (props.data.type === 'GeometryCollection') {
66
+ _.each(props.data.geometries, (geometry) => {
67
+ drawRef.current.add(feature(geometry));
68
+ });
69
+ } else {
70
+ drawRef.current.add(props.data);
71
+ }
72
+ }
73
+ }, [props.data]);
74
+
75
+ return (
76
+ <Map
77
+ attributionControl={false}
78
+ mapLib={maplibregl}
79
+ ref={mapRef}
80
+ style={style}
81
+ mapStyle={props.mapStyle}
82
+ >
83
+ <DrawControl
84
+ ref={drawRef}
85
+ controls={{
86
+ line_string: true,
87
+ point: true,
88
+ polygon: true,
89
+ trash: true
90
+ }}
91
+ displayControlsDefault={false}
92
+ onCreate={onChange}
93
+ onUpdate={onChange}
94
+ onDelete={onChange}
95
+ />
96
+ </Map>
97
+ );
98
+ };
99
+
100
+ export default MapDraw;
@@ -0,0 +1,5 @@
1
+ // @flow
2
+
3
+ // Components
4
+ export { default as DrawControl } from './components/DrawControl';
5
+ export { default as MapDraw } from './components/MapDraw';
@@ -0,0 +1,13 @@
1
+ const { configure } = require('@performant-software/webpack-config');
2
+ const path = require('path');
3
+
4
+ module.exports = configure(__dirname, {
5
+ resolve: {
6
+ alias: {
7
+ './@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css$': path.resolve(
8
+ __dirname,
9
+ '../../node_modules/@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'
10
+ )
11
+ }
12
+ }
13
+ });