Skip to content

Commit

Permalink
feat: adds a wfs layer and feature-info (#3826)
Browse files Browse the repository at this point in the history
* feat: adds a wfs layer and feature-info
  • Loading branch information
FritzHoing authored and simonseyock committed May 6, 2024
1 parent 1c0bec3 commit 38dabed
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
51 changes: 44 additions & 7 deletions src/CoordinateInfo/CoordinateInfo.example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
Expand All @@ -43,7 +71,8 @@ const CoordinateInfoExample = () => {
name: 'OSM',
source: new OlSourceOSM()
}),
queryLayer
vectorLayer,
wmsLayer
],
view: new OlView({
center: fromLonLat([-99.4031637, 38.3025695]),
Expand All @@ -66,12 +95,19 @@ const CoordinateInfoExample = () => {
/>
<CoordinateInfo
map={this.map}
queryLayers={[queryLayer]}
queryLayers={[wmsLayer, vectorLayer]}
resultRenderer={(opts) => {
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 ?
<div>
Expand Down Expand Up @@ -119,7 +155,8 @@ const CoordinateInfoExample = () => {
>
<Statistic
title="State"
value={features[Object.keys(features)[0]][0].get('STATE_NAME')}
value={getValue(features[Object.keys(features)[0]][0], 'STATE_NAME')
|| getValue(features[Object.keys(features)[0]][0], 'name')}
/>
</Spin>
<Tooltip
Expand All @@ -146,7 +183,7 @@ const CoordinateInfoExample = () => {
/>
</MapContext.Provider>
);
}
};

<CoordinateInfoExample />
<CoordinateInfoExample />;
```

0 comments on commit 38dabed

Please sign in to comment.