-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathgeojson.mjs
54 lines (40 loc) · 1.32 KB
/
geojson.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
export default layer => {
layer.format = new ol.format.GeoJSON();
layer.reload = loader;
function loader () {
mapp.utils.xhr(
`${layer.mapview.host}/api/layer/geojson?${mapp.utils.paramString({
locale: layer.mapview.locale.key,
layer: layer.key,
table: layer.table,
filter: layer.filter && layer.filter.current,
})}`)
.then(response => {
if (response === null) return;
const features = response.map((f) =>
new ol.Feature({
id: f.id,
geometry: layer.format.readGeometry(f.geometry, {
dataProjection: "EPSG:" + layer.srid,
featureProjection: "EPSG:" + layer.mapview.srid,
}),
properties: f.properties
}))
let source = new ol.source.Vector({
features: features
})
if (layer.clusterSource) {
source = new ol.source.Cluster({
distance: layer.clusterSource.distance || 50,
source
})
}
layer.L.setSource(source)
})
}
layer.L = new ol.layer[layer.vectorImage && 'VectorImage' || 'Vector']({
key: layer.key,
zIndex: layer.zIndex || 1,
style: layer.styleFunction || mapp.layer.Style(layer)
})
}