Mercurial > gemma
comparison client/src/store/map.js @ 2140:55bedb39295a
feat: clicking on stretches activates according layer
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 07 Feb 2019 10:30:44 +0100 |
parents | 602c2096c078 |
children | 8be0fbac2297 82867a69e10e |
comparison
equal
deleted
inserted
replaced
2139:22bbd0d0500e | 2140:55bedb39295a |
---|---|
31 import { getCenter } from "ol/extent"; | 31 import { getCenter } from "ol/extent"; |
32 import { transformExtent } from "ol/proj.js"; | 32 import { transformExtent } from "ol/proj.js"; |
33 import bbox from "@turf/bbox"; | 33 import bbox from "@turf/bbox"; |
34 import app from "../main"; | 34 import app from "../main"; |
35 | 35 |
36 const LAYERS = { | |
37 OPENSTREETMAP: "Open Streetmap", | |
38 INLANDECDIS: "Inland ECDIS chart Danube", | |
39 WATERWAYAREA: "Waterway Area", | |
40 STRETCHES: "Stretches", | |
41 FAIRWAYDIMENSIONSLOS1: "Fairway Dimensions LOS 1", | |
42 FAIRWAYDIMENSIONSLOS2: "Fairway Dimensions LOS 2", | |
43 FAIRWAYDIMENSIONSLOS3: "Fairway Dimensions LOS 3", | |
44 WATERWAYAXIS: "Waterway Axis", | |
45 BOTTLENECKS: "Bottlenecks", | |
46 BOTTLENECKISOLINE: "Bottleneck isolines", | |
47 DISTANCEMARKS: "Distance marks", | |
48 DISTANCEMARKSAXIS: "Distance marks, Axis", | |
49 DRAWTOOL: "Draw Tool", | |
50 CUTTOOL: "Cut Tool" | |
51 }; | |
52 | |
36 // initial state | 53 // initial state |
37 const init = () => { | 54 const init = () => { |
38 return { | 55 return { |
39 openLayersMap: null, | 56 openLayersMap: null, |
40 extent: { | 57 extent: { |
49 polygonTool: null, // open layers interaction object (Draw) | 66 polygonTool: null, // open layers interaction object (Draw) |
50 cutTool: null, // open layers interaction object (Draw) | 67 cutTool: null, // open layers interaction object (Draw) |
51 isolinesLegendImgDataURL: "", | 68 isolinesLegendImgDataURL: "", |
52 layers: [ | 69 layers: [ |
53 { | 70 { |
54 name: "Open Streetmap", | 71 name: LAYERS.OPENSTREETMAP, |
55 data: new TileLayer({ | 72 data: new TileLayer({ |
56 source: new OSM() | 73 source: new OSM() |
57 }), | 74 }), |
58 isVisible: true, | 75 isVisible: true, |
59 showInLegend: true | 76 showInLegend: true |
60 }, | 77 }, |
61 { | 78 { |
62 name: "Inland ECDIS chart Danube", | 79 name: LAYERS.INLANDECDIS, |
63 data: new TileLayer({ | 80 data: new TileLayer({ |
64 source: new TileWMS({ | 81 source: new TileWMS({ |
65 preload: 1, | 82 preload: 1, |
66 url: "https://service.d4d-portal.info/wms/", | 83 url: "https://service.d4d-portal.info/wms/", |
67 crossOrigin: "anonymous", | 84 crossOrigin: "anonymous", |
70 }), | 87 }), |
71 isVisible: true, | 88 isVisible: true, |
72 showInLegend: true | 89 showInLegend: true |
73 }, | 90 }, |
74 { | 91 { |
75 name: "Waterway Area", | 92 name: LAYERS.WATERWAYAREA, |
76 data: new VectorLayer({ | 93 data: new VectorLayer({ |
77 source: new VectorSource({ | 94 source: new VectorSource({ |
78 strategy: bboxStrategy | 95 strategy: bboxStrategy |
79 }), | 96 }), |
80 style: new Style({ | 97 style: new Style({ |
86 }), | 103 }), |
87 isVisible: true, | 104 isVisible: true, |
88 showInLegend: true | 105 showInLegend: true |
89 }, | 106 }, |
90 { | 107 { |
91 name: "Stretches", | 108 name: LAYERS.STRETCHES, |
92 data: new VectorLayer({ | 109 data: new VectorLayer({ |
93 source: new VectorSource({ | 110 source: new VectorSource({ |
94 strategy: bboxStrategy | 111 strategy: bboxStrategy |
95 }), | 112 }), |
96 style: new Style({ | 113 style: new Style({ |
105 }), | 122 }), |
106 isVisible: false, | 123 isVisible: false, |
107 showInLegend: true | 124 showInLegend: true |
108 }, | 125 }, |
109 { | 126 { |
110 name: "Fairway Dimensions LOS 1", | 127 name: LAYERS.FAIRWAYDIMENSIONSLOS1, |
111 data: new VectorLayer({ | 128 data: new VectorLayer({ |
112 source: new VectorSource(), | 129 source: new VectorSource(), |
113 style: function() { | 130 style: function() { |
114 return [ | 131 return [ |
115 new Style({ | 132 new Style({ |
134 }), | 151 }), |
135 isVisible: true, | 152 isVisible: true, |
136 showInLegend: true | 153 showInLegend: true |
137 }, | 154 }, |
138 { | 155 { |
139 name: "Fairway Dimensions LOS 2", | 156 name: LAYERS.FAIRWAYDIMENSIONSLOS2, |
140 data: new VectorLayer({ | 157 data: new VectorLayer({ |
141 source: new VectorSource(), | 158 source: new VectorSource(), |
142 style: function() { | 159 style: function() { |
143 return [ | 160 return [ |
144 new Style({ | 161 new Style({ |
163 }), | 180 }), |
164 isVisible: true, | 181 isVisible: true, |
165 showInLegend: true | 182 showInLegend: true |
166 }, | 183 }, |
167 { | 184 { |
168 name: "Fairway Dimensions LOS 3", | 185 name: LAYERS.FAIRWAYDIMENSIONSLOS3, |
169 data: new VectorLayer({ | 186 data: new VectorLayer({ |
170 source: new VectorSource(), | 187 source: new VectorSource(), |
171 style: function() { | 188 style: function() { |
172 return [ | 189 return [ |
173 new Style({ | 190 new Style({ |
192 }), | 209 }), |
193 isVisible: true, | 210 isVisible: true, |
194 showInLegend: true | 211 showInLegend: true |
195 }, | 212 }, |
196 { | 213 { |
197 name: "Waterway Axis", | 214 name: LAYERS.WATERWAYAXIS, |
198 data: new VectorLayer({ | 215 data: new VectorLayer({ |
199 source: new VectorSource({ | 216 source: new VectorSource({ |
200 strategy: bboxStrategy | 217 strategy: bboxStrategy |
201 }), | 218 }), |
202 style: new Style({ | 219 style: new Style({ |
209 }), | 226 }), |
210 isVisible: true, | 227 isVisible: true, |
211 showInLegend: true | 228 showInLegend: true |
212 }, | 229 }, |
213 { | 230 { |
214 name: "Bottlenecks", | 231 name: LAYERS.BOTTLENECKS, |
215 data: new VectorLayer({ | 232 data: new VectorLayer({ |
216 source: new VectorSource({ | 233 source: new VectorSource({ |
217 strategy: bboxStrategy | 234 strategy: bboxStrategy |
218 }), | 235 }), |
219 style: new Style({ | 236 style: new Style({ |
228 }), | 245 }), |
229 isVisible: true, | 246 isVisible: true, |
230 showInLegend: true | 247 showInLegend: true |
231 }, | 248 }, |
232 { | 249 { |
233 name: "Bottleneck isolines", | 250 name: LAYERS.BOTTLENECKISOLINE, |
234 data: new TileLayer({ | 251 data: new TileLayer({ |
235 source: new TileWMS({ | 252 source: new TileWMS({ |
236 preload: 0, | 253 preload: 0, |
237 projection: "EPSG:3857", | 254 projection: "EPSG:3857", |
238 url: window.location.origin + "/api/internal/wms", | 255 url: window.location.origin + "/api/internal/wms", |
256 }), | 273 }), |
257 isVisible: false, | 274 isVisible: false, |
258 showInLegend: true | 275 showInLegend: true |
259 }, | 276 }, |
260 { | 277 { |
261 name: "Distance marks", | 278 name: LAYERS.DISTANCEMARKS, |
262 forLegendStyle: { point: true, resolution: 8 }, | 279 forLegendStyle: { point: true, resolution: 8 }, |
263 data: new VectorLayer({ | 280 data: new VectorLayer({ |
264 source: new VectorSource({ | 281 source: new VectorSource({ |
265 strategy: bboxStrategy | 282 strategy: bboxStrategy |
266 }) | 283 }) |
267 }), | 284 }), |
268 isVisible: false, | 285 isVisible: false, |
269 showInLegend: true | 286 showInLegend: true |
270 }, | 287 }, |
271 { | 288 { |
272 name: "Distance marks, Axis", | 289 name: LAYERS.DISTANCEMARKSAXIS, |
273 forLegendStyle: { point: true, resolution: 8 }, | 290 forLegendStyle: { point: true, resolution: 8 }, |
274 data: new VectorLayer({ | 291 data: new VectorLayer({ |
275 source: new VectorSource({ | 292 source: new VectorSource({ |
276 strategy: bboxStrategy | 293 strategy: bboxStrategy |
277 }), | 294 }), |
304 }), | 321 }), |
305 isVisible: true, | 322 isVisible: true, |
306 showInLegend: true | 323 showInLegend: true |
307 }, | 324 }, |
308 { | 325 { |
309 name: "Draw Tool", | 326 name: LAYERS.DRAWTOOL, |
310 data: new VectorLayer({ | 327 data: new VectorLayer({ |
311 source: new VectorSource({ wrapX: false }), | 328 source: new VectorSource({ wrapX: false }), |
312 style: function(feature) { | 329 style: function(feature) { |
313 // adapted from OpenLayer's LineString Arrow Example | 330 // adapted from OpenLayer's LineString Arrow Example |
314 var geometry = feature.getGeometry(); | 331 var geometry = feature.getGeometry(); |
352 }), | 369 }), |
353 isVisible: true, | 370 isVisible: true, |
354 showInLegend: false | 371 showInLegend: false |
355 }, | 372 }, |
356 { | 373 { |
357 name: "Cut Tool", | 374 name: LAYERS.CUTTOOL, |
358 data: new VectorLayer({ | 375 data: new VectorLayer({ |
359 source: new VectorSource({ wrapX: false }), | 376 source: new VectorSource({ wrapX: false }), |
360 style: function(feature) { | 377 style: function(feature) { |
361 // adapted from OpenLayer's LineString Arrow Example | 378 // adapted from OpenLayer's LineString Arrow Example |
362 var geometry = feature.getGeometry(); | 379 var geometry = feature.getGeometry(); |
422 } | 439 } |
423 }, | 440 }, |
424 mutations: { | 441 mutations: { |
425 extent: (state, extent) => { | 442 extent: (state, extent) => { |
426 state.extent = extent; | 443 state.extent = extent; |
444 }, | |
445 setLayerVisible: (state, name) => { | |
446 const layer = state.layers.findIndex(l => l.name === name); | |
447 state.layers[layer].isVisible = true; | |
448 state.layers[layer].data.setVisible(true); | |
449 }, | |
450 setLayerInvisible: (state, name) => { | |
451 const layer = state.layers.findIndex(l => l.name === name); | |
452 state.layers[layer].isVisible = false; | |
453 state.layers[layer].data.setVisible(false); | |
454 }, | |
455 toggleVisibilityByName: (state, name) => { | |
456 const layer = state.layers.findIndex(l => l.name === name); | |
457 state.layers[layer].isVisible = !state.layers[layer].isVisible; | |
458 state.layers[layer].data.setVisible(state.layers[layer].isVisible); | |
427 }, | 459 }, |
428 toggleVisibility: (state, layer) => { | 460 toggleVisibility: (state, layer) => { |
429 state.layers[layer].isVisible = !state.layers[layer].isVisible; | 461 state.layers[layer].isVisible = !state.layers[layer].isVisible; |
430 state.layers[layer].data.setVisible(state.layers[layer].isVisible); | 462 state.layers[layer].data.setVisible(state.layers[layer].isVisible); |
431 }, | 463 }, |
643 ); | 675 ); |
644 } | 676 } |
645 } | 677 } |
646 } | 678 } |
647 }; | 679 }; |
680 | |
681 export { LAYERS }; |