diff --git a/package-lock.json b/package-lock.json index cd9fa3f2c..efdc297da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@fortawesome/react-fontawesome": "^0.2.0", "@terrestris/base-util": "^1.1.0", "@terrestris/ol-util": "^17.0.0", - "@terrestris/react-util": "^5.0.0-beta.0", + "@terrestris/react-util": "^5.0.0-beta.1", "@types/geojson": "^7946.0.14", "@types/lodash": "^4.17.0", "ag-grid-community": "^31.1.1", @@ -5711,9 +5711,9 @@ } }, "node_modules/@terrestris/react-util": { - "version": "5.0.0-beta.0", - "resolved": "https://registry.npmjs.org/@terrestris/react-util/-/react-util-5.0.0-beta.0.tgz", - "integrity": "sha512-BvIEmE2Mlvp/RTF8VheQOGjDX4ljf9WylhFWRaxT6o4yITlxttwaqtzGLI0KyaT2AXPbY+hpszaFD8Ry+LvGbw==", + "version": "5.0.0-beta.1", + "resolved": "https://registry.npmjs.org/@terrestris/react-util/-/react-util-5.0.0-beta.1.tgz", + "integrity": "sha512-GIkeawNQPlJgPQ7JcKKLABOk10bhIDfbPWfCVIQ6zUl2IHcijx75LMRCDRTjhR53dBpQHO7T0d7eUV/YgzeGDg==", "dependencies": { "@camptocamp/inkmap": "^1.4.0", "@terrestris/base-util": "^1.1.0", diff --git a/package.json b/package.json index e752e00ef..85556181f 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@fortawesome/react-fontawesome": "^0.2.0", "@terrestris/base-util": "^1.1.0", "@terrestris/ol-util": "^17.0.0", - "@terrestris/react-util": "^5.0.0-beta.0", + "@terrestris/react-util": "^5.0.0-beta.1", "@types/geojson": "^7946.0.14", "@types/lodash": "^4.17.0", "ag-grid-community": "^31.1.1", diff --git a/src/CoordinateInfo/CoordinateInfo.example.md b/src/CoordinateInfo/CoordinateInfo.example.md index dcf32dcc0..6e4a859d0 100644 --- a/src/CoordinateInfo/CoordinateInfo.example.md +++ b/src/CoordinateInfo/CoordinateInfo.example.md @@ -11,15 +11,19 @@ import { Tooltip } from 'antd'; import * as copy from 'copy-to-clipboard'; +import GeoJSON from 'ol/format/GeoJSON.js'; +import { Vector as VectorLayer } from 'ol/layer.js'; import OlLayerTile from 'ol/layer/Tile'; +import { bbox as bboxStrategy } from 'ol/loadingstrategy.js'; import OlMap from 'ol/Map'; import { fromLonLat } from 'ol/proj'; import OlSourceOSM from 'ol/source/OSM'; import OlSourceTileWMS from 'ol/source/TileWMS'; +import VectorSource from 'ol/source/Vector.js'; import OlView from 'ol/View'; -import React, { useEffect,useState } from 'react'; +import React, { useEffect, useState } from 'react'; -const queryLayer = new OlLayerTile({ +const wmsLayer = new OlLayerTile({ name: 'States (USA)', source: new OlSourceTileWMS({ url: 'https://ahocevar.com/geoserver/wms', @@ -32,6 +36,30 @@ const queryLayer = new OlLayerTile({ }) }); +const vectorSource = new VectorSource({ + format: new GeoJSON(), + url: function (extent) { + return ( + 'https://ows-demo.terrestris.de/geoserver/osm/wfs?service=WFS&' + + 'version=1.1.0&request=GetFeature&typename=osm:osm-country-borders&' + + 'outputFormat=application/json&srsname=EPSG:3857&' + + 'bbox=' + + extent.join(',') + + ',EPSG:3857' + ); + }, + strategy: bboxStrategy, +}); + +const vectorLayer = new VectorLayer({ + source: vectorSource, + style: { + 'stroke-width': 0.75, + 'stroke-color': 'white', + 'fill-color': 'rgba(100,100,100,0.25)', + }, +}); + const CoordinateInfoExample = () => { const [map, setMap] = useState(); @@ -43,7 +71,8 @@ const CoordinateInfoExample = () => { name: 'OSM', source: new OlSourceOSM() }), - queryLayer + vectorLayer, + wmsLayer ], view: new OlView({ center: fromLonLat([-99.4031637, 38.3025695]), @@ -66,12 +95,19 @@ const CoordinateInfoExample = () => { /> { const features = opts.features; const clickCoord = opts.clickCoordinate; const loading = opts.loading; + const getValue = (feature, key) => { + if (feature.getProperties().hasOwnProperty(key)) { + return feature.get(key); + } + return null; + }; + return ( Object.keys(features).length === 1 && features[Object.keys(features)[0]].length === 1 ?
@@ -119,7 +155,8 @@ const CoordinateInfoExample = () => { > { /> ); -} +}; - +; ```