geostyler 9.0.0 → 9.0.1
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.
|
@@ -4,11 +4,12 @@ import { ProjectionLike } from 'ol/proj';
|
|
|
4
4
|
import { Style } from 'geostyler-style';
|
|
5
5
|
import { Data } from 'geostyler-data';
|
|
6
6
|
import './PreviewMap.css';
|
|
7
|
+
import { StandardLonghandProperties } from 'csstype';
|
|
7
8
|
export interface PreviewMapDefaultProps {
|
|
8
9
|
/** The projection of the data to visualize */
|
|
9
10
|
dataProjection: ProjectionLike;
|
|
10
11
|
/** The height of the map */
|
|
11
|
-
mapHeight:
|
|
12
|
+
mapHeight: StandardLonghandProperties['height'];
|
|
12
13
|
}
|
|
13
14
|
export interface PreviewMapProps extends Partial<PreviewMapDefaultProps> {
|
|
14
15
|
/** The data to visualize */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewMap.js","sourceRoot":"","sources":["../../../src/Component/PreviewMap/PreviewMap.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAAiD;AAEjD,+CAA2B;AAC3B,2DAA4C;AAC5C,4DAA8C;AAC9C,8DAAgD;AAEhD,uDAAmC;AACnC,uDAAwC;AACxC,sDAAwC;AAIxC,4FAAwD;AAExD,yEAAmD;AAEnD,6BAA2B;AAsB3B;;GAEG;AACI,IAAM,UAAU,GAA8B,UAAC,EAOrD;QANC,sBAA4B,EAA5B,cAAc,mBAAG,WAAW,KAAA,EAC5B,iBAAe,EAAf,SAAS,mBAAG,GAAG,KAAA,EACf,IAAI,UAAA,EACJ,KAAK,WAAA,EACA,OAAO,SAAA,EACZ,aAAa,mBAAA;IAGb,IAAM,YAAY,GAAG,IAAA,cAAM,GAAE,CAAC;IAE9B,+CAA+C;IAC/C,IAAM,YAAY,GAAG,IAAA,cAAM,EAAqB,IAAI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AAC;YAC5C,CAAC,CAAC,CAAC;YACH,UAAU,EAAE,CAAC;SACd;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAElB,qCAAqC;IACrC,IAAA,iBAAS,EAAC;QACR,IAAI,OAAO,EAAE;YACX,uDAAuD;YACvD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;SAC1B;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd;;OAEG;IACH,IAAA,iBAAS,EAAC;QACR,IAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC;QAC3B,IAAI,YAAY,EAAE;YAChB,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YACpC,GAAG,CAAC,UAAU,EAAE,CAAC;YACjB,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;SACd;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP;;OAEG;IACH,IAAA,iBAAS,EAAC;QACR,IAAI,YAAY,EAAE;YAChB,IAAI,aAAa,EAAE;gBACjB,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC/B;SACF;IACH,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,OAAO,CACL,uCACE,GAAG,EAAE,YAAY,EACjB,SAAS,EAAC,8BAA8B,EACxC,EAAE,EAAE,cAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAE,EACtD,KAAK,EAAE;YACL,MAAM,EAAE,SAAS;SAClB,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AA9IW,QAAA,UAAU,cA8IrB;AAEF,kBAAe,kBAAU,CAAC","sourcesContent":["/* Released under the BSD 2-Clause License\n *\n * Copyright © 2018-present, terrestris GmbH & Co. KG and GeoStyler contributors\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n *\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport React, { useEffect, useRef } from 'react';\n\nimport OlMap from 'ol/Map';\nimport OlLayerVector from 'ol/layer/Vector';\nimport OlSourceVector from 'ol/source/Vector';\nimport OlFormatGeoJSON from 'ol/format/GeoJSON';\nimport { ProjectionLike } from 'ol/proj';\nimport OlFeature from 'ol/Feature';\nimport OlLayerTile from 'ol/layer/Tile';\nimport OlSourceOSM from 'ol/source/OSM';\n\nimport { Style } from 'geostyler-style';\nimport { Data, VectorData } from 'geostyler-data';\nimport OlStyleParser from 'geostyler-openlayers-parser';\n\nimport GeometryUtil from '../../Util/GeometryUtil';\n\nimport './PreviewMap.less';\n\n// default props\nexport interface PreviewMapDefaultProps {\n /** The projection of the data to visualize */\n dataProjection: ProjectionLike;\n /** The height of the map */\n mapHeight: number;\n}\n\n// non default props\nexport interface PreviewMapProps extends Partial<PreviewMapDefaultProps> {\n /** The data to visualize */\n data?: Data;\n /** The GeoStyler Style to preview */\n style: Style;\n /** A custom map used for rendering */\n map?: OlMap;\n /** A list of layers to add to the map */\n onMapDidMount?: (map: OlMap) => void;\n}\n\n/**\n * Style preview UI.\n */\nexport const PreviewMap: React.FC<PreviewMapProps> = ({\n dataProjection = 'EPSG:4326',\n mapHeight = 267,\n data,\n style,\n map: mapProp,\n onMapDidMount\n}) => {\n\n const containerRef = useRef();\n\n /** the vector layer for the passed features */\n const dataLayerRef = useRef<OlLayerVector<any>>(new OlLayerVector({\n source: new OlSourceVector()\n }));\n\n /** the underlying OpenLayers map */\n const mapRef = useRef<OlMap>(\n mapProp ||\n new OlMap({\n controls: [],\n layers: [\n new OlLayerTile({\n source: new OlSourceOSM()\n }),\n dataLayerRef.current\n ]\n })\n );\n\n /**\n * Fits the preview extend to the data when the dataLayer changes.\n */\n const zoomToData = () => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n map.getView().fit(\n dataLayer.getSource().getExtent(),\n {\n maxZoom: 10\n }\n );\n };\n\n /**\n * Add the dataLayer to the map.\n */\n const addDataLayer = () => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n if (!map.getAllLayers().some(layer => layer === dataLayer)) {\n map.addLayer(dataLayer);\n }\n };\n\n /**\n * Add the containing exampleFeatures if the passed data changes.\n */\n useEffect(() => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n if (dataLayer && (data as VectorData)?.exampleFeatures && map) {\n dataLayer.getSource().clear();\n const format = new OlFormatGeoJSON({\n dataProjection: dataProjection,\n featureProjection: map.getView().getProjection()\n });\n const olFeatures = format.readFeatures((data as VectorData).exampleFeatures);\n dataLayer.getSource().addFeatures(olFeatures);\n }\n }, [data, dataProjection]);\n\n /**\n * Update the layerStyle if the passed style changes.\n */\n useEffect(() => {\n const dataLayer = dataLayerRef.current;\n const styleParser = new OlStyleParser();\n styleParser.writeStyle(style)\n .then(({ output: olStyles}) => {\n dataLayer.setStyle(olStyles);\n });\n }, [style]);\n\n /**\n * If no data is provided create sample geometries based on the passed style.\n */\n useEffect(() => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n if (!data && dataLayer && map && style) {\n const geoms = GeometryUtil.getSampleGeomFromStyle(style, map.getView().getProjection());\n geoms.forEach((geometry: any) => {\n const feature = new OlFeature({geometry});\n dataLayer.getSource().addFeature(feature);\n });\n zoomToData();\n }\n }, [style, data]);\n\n // Set the map if a mapProp is passed\n useEffect(() => {\n if (mapProp) {\n // use passed in OL map and bind it to this preview DIV\n mapRef.current = mapProp;\n }\n }, [mapProp]);\n\n /**\n * Set the target of the map if the ref is defined.\n */\n useEffect(() => {\n const map = mapRef.current;\n if (containerRef) {\n map.setTarget(containerRef.current);\n map.updateSize();\n addDataLayer();\n zoomToData();\n }\n }, []);\n\n /**\n * Call the `onMapDidMount` callback if defined.\n */\n useEffect(() => {\n if (containerRef) {\n if (onMapDidMount) {\n onMapDidMount(mapRef.current);\n }\n }\n }, [onMapDidMount]);\n\n return (\n <div\n ref={containerRef}\n className=\"gs-symbolizer-previewmap map\"\n id={`map_${Math.floor((1 + Math.random()) * 0x10000)}`}\n style={{\n height: mapHeight\n }}\n />\n );\n};\n\nexport default PreviewMap;\n"]}
|
|
1
|
+
{"version":3,"file":"PreviewMap.js","sourceRoot":"","sources":["../../../src/Component/PreviewMap/PreviewMap.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAAiD;AAEjD,+CAA2B;AAC3B,2DAA4C;AAC5C,4DAA8C;AAC9C,8DAAgD;AAEhD,uDAAmC;AACnC,uDAAwC;AACxC,sDAAwC;AAIxC,4FAAwD;AAExD,yEAAmD;AAEnD,6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CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAE,EACtD,KAAK,EAAE;YACL,MAAM,EAAE,SAAS;SAClB,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AA9IW,QAAA,UAAU,cA8IrB;AAEF,kBAAe,kBAAU,CAAC","sourcesContent":["/* Released under the BSD 2-Clause License\n *\n * Copyright © 2018-present, terrestris GmbH & Co. KG and GeoStyler contributors\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n *\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport React, { useEffect, useRef } from 'react';\n\nimport OlMap from 'ol/Map';\nimport OlLayerVector from 'ol/layer/Vector';\nimport OlSourceVector from 'ol/source/Vector';\nimport OlFormatGeoJSON from 'ol/format/GeoJSON';\nimport { ProjectionLike } from 'ol/proj';\nimport OlFeature from 'ol/Feature';\nimport OlLayerTile from 'ol/layer/Tile';\nimport OlSourceOSM from 'ol/source/OSM';\n\nimport { Style } from 'geostyler-style';\nimport { Data, VectorData } from 'geostyler-data';\nimport OlStyleParser from 'geostyler-openlayers-parser';\n\nimport GeometryUtil from '../../Util/GeometryUtil';\n\nimport './PreviewMap.less';\nimport { StandardLonghandProperties } from 'csstype';\n\n// default props\nexport interface PreviewMapDefaultProps {\n /** The projection of the data to visualize */\n dataProjection: ProjectionLike;\n /** The height of the map */\n mapHeight: StandardLonghandProperties['height'];\n}\n\n// non default props\nexport interface PreviewMapProps extends Partial<PreviewMapDefaultProps> {\n /** The data to visualize */\n data?: Data;\n /** The GeoStyler Style to preview */\n style: Style;\n /** A custom map used for rendering */\n map?: OlMap;\n /** A list of layers to add to the map */\n onMapDidMount?: (map: OlMap) => void;\n}\n\n/**\n * Style preview UI.\n */\nexport const PreviewMap: React.FC<PreviewMapProps> = ({\n dataProjection = 'EPSG:4326',\n mapHeight = 267,\n data,\n style,\n map: mapProp,\n onMapDidMount\n}) => {\n\n const containerRef = useRef();\n\n /** the vector layer for the passed features */\n const dataLayerRef = useRef<OlLayerVector<any>>(new OlLayerVector({\n source: new OlSourceVector()\n }));\n\n /** the underlying OpenLayers map */\n const mapRef = useRef<OlMap>(\n mapProp ||\n new OlMap({\n controls: [],\n layers: [\n new OlLayerTile({\n source: new OlSourceOSM()\n }),\n dataLayerRef.current\n ]\n })\n );\n\n /**\n * Fits the preview extend to the data when the dataLayer changes.\n */\n const zoomToData = () => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n map.getView().fit(\n dataLayer.getSource().getExtent(),\n {\n maxZoom: 10\n }\n );\n };\n\n /**\n * Add the dataLayer to the map.\n */\n const addDataLayer = () => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n if (!map.getAllLayers().some(layer => layer === dataLayer)) {\n map.addLayer(dataLayer);\n }\n };\n\n /**\n * Add the containing exampleFeatures if the passed data changes.\n */\n useEffect(() => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n if (dataLayer && (data as VectorData)?.exampleFeatures && map) {\n dataLayer.getSource().clear();\n const format = new OlFormatGeoJSON({\n dataProjection: dataProjection,\n featureProjection: map.getView().getProjection()\n });\n const olFeatures = format.readFeatures((data as VectorData).exampleFeatures);\n dataLayer.getSource().addFeatures(olFeatures);\n }\n }, [data, dataProjection]);\n\n /**\n * Update the layerStyle if the passed style changes.\n */\n useEffect(() => {\n const dataLayer = dataLayerRef.current;\n const styleParser = new OlStyleParser();\n styleParser.writeStyle(style)\n .then(({ output: olStyles}) => {\n dataLayer.setStyle(olStyles);\n });\n }, [style]);\n\n /**\n * If no data is provided create sample geometries based on the passed style.\n */\n useEffect(() => {\n const map = mapRef.current;\n const dataLayer = dataLayerRef.current;\n if (!data && dataLayer && map && style) {\n const geoms = GeometryUtil.getSampleGeomFromStyle(style, map.getView().getProjection());\n geoms.forEach((geometry: any) => {\n const feature = new OlFeature({geometry});\n dataLayer.getSource().addFeature(feature);\n });\n zoomToData();\n }\n }, [style, data]);\n\n // Set the map if a mapProp is passed\n useEffect(() => {\n if (mapProp) {\n // use passed in OL map and bind it to this preview DIV\n mapRef.current = mapProp;\n }\n }, [mapProp]);\n\n /**\n * Set the target of the map if the ref is defined.\n */\n useEffect(() => {\n const map = mapRef.current;\n if (containerRef) {\n map.setTarget(containerRef.current);\n map.updateSize();\n addDataLayer();\n zoomToData();\n }\n }, []);\n\n /**\n * Call the `onMapDidMount` callback if defined.\n */\n useEffect(() => {\n if (containerRef) {\n if (onMapDidMount) {\n onMapDidMount(mapRef.current);\n }\n }\n }, [onMapDidMount]);\n\n return (\n <div\n ref={containerRef}\n className=\"gs-symbolizer-previewmap map\"\n id={`map_${Math.floor((1 + Math.random()) * 0x10000)}`}\n style={{\n height: mapHeight\n }}\n />\n );\n};\n\nexport default PreviewMap;\n"]}
|