-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from wearepal/kew-data
Added KewLayer to map view
- Loading branch information
Showing
6 changed files
with
231 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import BaseLayer from "ol/layer/Base" | ||
import { KewLayer } from "../state" | ||
import VectorLayer from "ol/layer/Vector" | ||
import { memoize } from "lodash" | ||
import VectorSource from "ol/source/Vector" | ||
import GeoJSON from "ol/format/GeoJSON" | ||
import { bbox } from "ol/loadingstrategy" | ||
import { Fill, Stroke, Style, Text } from "ol/style" | ||
import { Map, Overlay } from "ol" | ||
|
||
|
||
|
||
const getSource = memoize((location: string) => { | ||
const source = new VectorSource({ | ||
url: extent => `https://landscapes.wearepal.ai/geoserver/kew/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=${location}&outputFormat=application/json&bbox=${extent.join(',')},EPSG:3857&crs=EPSG:3857`, | ||
format: new GeoJSON({ | ||
extractGeometryName: true | ||
}), | ||
strategy: bbox, | ||
attributions: '© <a href="https://www.kew.org/">Kew</a> Partners', | ||
}) | ||
|
||
return source | ||
|
||
}) | ||
|
||
const getStyle = (layer: KewLayer, zoom: number | undefined) => ( | ||
(feature) => { | ||
const properties = feature.getProperties() | ||
let metric | ||
let dmax = layer.typeOptions.filter(opt => opt.value == layer.metric)[0].max || 100 | ||
layer.periodOptions.filter(opt => opt.selected).forEach(option => { | ||
metric = properties[[option.value, layer.loc, layer.metric].filter(a => a).join("_")] || metric | ||
}) | ||
const [min, max] = [0, dmax] | ||
const color = metric ? `rgba(${255 * (1 - ((metric - min) / (max - min)))}, ${(metric - min) / (max - min) * 255}, 0, 1)` : "rgba(0,0,0,.1)" | ||
|
||
return new Style({ | ||
fill : new Fill({ | ||
color | ||
}), | ||
stroke: new Stroke({ | ||
color: `rgba(0,0,0,.5)`, | ||
width: 1 | ||
}), | ||
text: new Text({ | ||
text: `${metric ? metric : ""} ${zoom ? (zoom > 21 ? `(${properties.GRID_ID})` : "") : ""}`, | ||
font: `${zoom ? (zoom > 21 ? 16 : 12) : 12}px Calibri,sans-serif`, | ||
fill: new Fill({ | ||
color: metric ? '#fff' : "rgba(0,0,0,.1)" | ||
}), | ||
stroke: new Stroke({ | ||
color: metric ? '#fff' : "rgba(0,0,0,.1)", | ||
width: zoom ? (zoom > 10 ? .2 : 0) : 0 | ||
}) | ||
|
||
}) | ||
}) | ||
} | ||
) | ||
|
||
|
||
export function reifyKewLayer (layer: KewLayer, existingLayer: BaseLayer | null , map: Map) { | ||
|
||
const vectLayer = new VectorLayer({ | ||
source: getSource(layer.location), | ||
style: getStyle(layer, map.getView().getZoom()) | ||
}) | ||
|
||
return vectLayer | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters