diff --git a/package-lock.json b/package-lock.json index ddca4875f..c0b75fa58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@fortawesome/react-fontawesome": "^0.2.2", "@terrestris/base-util": "^2.0.0", "@terrestris/ol-util": ">=18", - "@terrestris/react-util": "^8.0.4", + "@terrestris/react-util": "^8.0.5", "@types/lodash": "^4.17.4", "ag-grid-community": "^31.3.2", "ag-grid-react": "^31.3.2", @@ -5689,9 +5689,9 @@ } }, "node_modules/@terrestris/react-util": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/@terrestris/react-util/-/react-util-8.0.4.tgz", - "integrity": "sha512-UH7lw+tCem5d7k2wBnsT7153Mwx1piIGSF0miDEsMSQmhQEuUfDGAg7MncSxIDYPrANp8tv0uUBPUnXwp2CPHg==", + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/@terrestris/react-util/-/react-util-8.0.5.tgz", + "integrity": "sha512-wYLdnbP3u5eU/SNwIPzsYZ/jmJZCUAeBS2qUSrtpO3O/kRVpVkznEcG7guFx9ljUQlFdo/A/SnarjWPW+s1EtA==", "dependencies": { "@camptocamp/inkmap": "^1.4.0", "@terrestris/base-util": "^2.0.0", diff --git a/package.json b/package.json index 4afb7590e..8ecde793c 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@fortawesome/react-fontawesome": "^0.2.2", "@terrestris/base-util": "^2.0.0", "@terrestris/ol-util": ">=18", - "@terrestris/react-util": "^8.0.4", + "@terrestris/react-util": "^8.0.5", "@types/lodash": "^4.17.4", "ag-grid-community": "^31.3.2", "ag-grid-react": "^31.3.2", diff --git a/src/CoordinateInfo/CoordinateInfo.example.md b/src/CoordinateInfo/CoordinateInfo.example.md index 7439e1660..492bea10c 100644 --- a/src/CoordinateInfo/CoordinateInfo.example.md +++ b/src/CoordinateInfo/CoordinateInfo.example.md @@ -1,27 +1,31 @@ +The `CoordinateInfo` component is only a very shallow wrapper around the `useCoordinateInfo` hook of react-util. +Often it might be easier to use the hook directly, see the second example on how it's done. + ```jsx -import { faCopy } from '@fortawesome/free-solid-svg-icons'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import {faCopy} from '@fortawesome/free-solid-svg-icons'; +import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import CoordinateInfo from '@terrestris/react-geo/dist/CoordinateInfo/CoordinateInfo'; import MapComponent from '@terrestris/react-geo/dist/Map/MapComponent/MapComponent'; import MapContext from '@terrestris/react-util/dist/Context/MapContext/MapContext'; +import useCoordinateInfo from '@terrestris/react-util/dist/Hooks/useCoordinateInfo/useCoordinateInfo'; import { - Button, + Button, Divider, Spin, Statistic, 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 {Vector as VectorLayer} from 'ol/layer.js'; import OlLayerTile from 'ol/layer/Tile'; -import { bbox as bboxStrategy } from 'ol/loadingstrategy.js'; +import {bbox as bboxStrategy} from 'ol/loadingstrategy.js'; import OlMap from 'ol/Map'; -import { fromLonLat } from 'ol/proj'; +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 wmsLayer = new OlLayerTile({ name: 'States (USA)', @@ -60,6 +64,93 @@ const vectorLayer = new VectorLayer({ }, }); +const queryLayers = [wmsLayer, vectorLayer]; + +const getValue = (feature, key) => { + if (feature.getProperties().hasOwnProperty(key)) { + return feature.get(key); + } + return null; +}; + +const FeatureInfo = ({ + features, + loading, + clickCoordinate +}) => { + return !loading && features.length > 0 ? +