@vidro/map-handler 1.0.11 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  // Config:
2
2
 
3
3
  var sessionToken = document.querySelector("#sessionToken").textContent;
4
- var communicator = new VidroMaps.Communicator({sessionToken});
4
+ var communicator = new VidroMaps.Communicator({ sessionToken });
5
5
  var clickedCoordinates = null;
6
6
  // UI buttons:
7
7
 
@@ -23,8 +23,12 @@ var btStopGeolocalize = document.querySelector("#btStopGeolocalize");
23
23
  var btHighlight = document.querySelector("#btHighlight");
24
24
  var zoomToHighlightCheck = document.querySelector("#zoomToHighlightCheck");
25
25
  var btToggleGiswaterTiled = document.querySelector("#btToggleGiswaterTiled");
26
- var toggleGiswaterTiledCheck = document.querySelector("#toggleGiswaterTiledCheck");
27
- var btReloadDisplayedLayers = document.querySelector("#btReloadDisplayedLayers");
26
+ var toggleGiswaterTiledCheck = document.querySelector(
27
+ "#toggleGiswaterTiledCheck"
28
+ );
29
+ var btReloadDisplayedLayers = document.querySelector(
30
+ "#btReloadDisplayedLayers"
31
+ );
28
32
  var btAddGeoJSON = document.querySelector("#btAddGeoJSON");
29
33
  var btClearGeoJSON = document.querySelector("#btClearGeoJSON");
30
34
  var geoJSONFileContent = document.getElementById("geojsonfile");
@@ -36,9 +40,13 @@ var btsetGiswaterFilters = document.querySelector("#btsetGiswaterFilters");
36
40
  var btgetGiswaterFilters = document.querySelector("#btgetGiswaterFilters");
37
41
  var btLoadWMSLayers = document.querySelector("#btLoadWMSLayers");
38
42
  var btDebug = document.querySelector("#btDebug");
39
- var btAddGeoJSONFromGiswater = document.querySelector("#btAddGeoJSONFromGiswater");
43
+ var btAddGeoJSONFromGiswater = document.querySelector(
44
+ "#btAddGeoJSONFromGiswater"
45
+ );
40
46
  //override layer properties
41
- var overrideLayerProperties = document.querySelector("#overrideLayerProperties");
47
+ var overrideLayerProperties = document.querySelector(
48
+ "#overrideLayerProperties"
49
+ );
42
50
  var gutter = document.querySelector("#gutter");
43
51
  var toggleTransparentLayer = document.querySelector("#toggleTransparentLayer");
44
52
  var toggleSingleTile = document.querySelector("#toggleSingleTile");
@@ -49,284 +57,317 @@ var geom_stroke_width = document.querySelector("#geom_stroke_width");
49
57
  var geom_fill_color = document.querySelector("#geom_fill_color");
50
58
  var geom_shape = document.querySelector("#geom_shape");
51
59
  var geom_radius = document.querySelector("#geom_radius");
52
-
60
+
53
61
  var btSetColors = document.querySelector("#btSetColors");
54
62
  var btGetElementsFromLayer = document.querySelector("#btGetElementsFromLayer");
63
+ var btGetToc = document.querySelector("#btGetToc");
64
+ var btChangeBackground = document.querySelector("#btChangeBackground");
65
+ var newBackground = document.querySelector("#newBackground");
55
66
 
56
67
  var geoJSONName = null; //geoJSON file name
57
68
  var geoJSONContent = null; // geojson file content
58
69
  //local var for store active layer
59
70
  var currentActiveLayer = null;
60
- function cleanContainers(){
61
- Error_container.innerHTML = '';
62
- Result_container.innerHTML = '';
71
+ function cleanContainers() {
72
+ Error_container.innerHTML = "";
73
+ Result_container.innerHTML = "";
63
74
  }
64
75
 
65
76
  // Map events
66
77
 
67
- communicator.on("onZoomChange", function(data){
68
- console.log("onZoomChange",data);
69
- if(document.getElementById('zoomLevel')){
70
- //Add current zoom Level to highlight input zoomlevel
71
- document.getElementById('zoomLevel').value = data;
72
- }
73
- cleanContainers();
74
- Result_container.innerHTML = `Zoom level changed: ${data}`;
78
+ communicator.on("onZoomChange", function (data) {
79
+ console.log("onZoomChange", data);
80
+ if (document.getElementById("zoomLevel")) {
81
+ //Add current zoom Level to highlight input zoomlevel
82
+ document.getElementById("zoomLevel").value = data;
83
+ }
84
+ cleanContainers();
85
+ Result_container.innerHTML = `Zoom level changed: ${data}`;
75
86
  });
76
87
 
88
+ communicator.on("geomAdded", function (data) {
89
+ console.log("geomAdded", data);
90
+ cleanContainers();
91
+ //show geometry on DOM
92
+ Result_container.innerHTML = data;
93
+ //Add current geom to highlight input geom
94
+ document.getElementById("geom").value = data;
95
+ });
77
96
 
78
- communicator.on("geomAdded", function(data){
79
- console.log("geomAdded",data);
80
- cleanContainers();
81
- //show geometry on DOM
82
- Result_container.innerHTML = data;
83
- //Add current geom to highlight input geom
84
- document.getElementById('geom').value = data;
97
+ communicator.on("loaded", function (data) {
98
+ console.log("loaded", data);
99
+ communicator.setCustomColors({
100
+ geom_stroke_color: "rgb(19, 39, 99,0.5)",
101
+ geom_fill_color: "rgb(19, 39, 99,0.5)",
102
+ geom_stroke_width: 1,
103
+ geom_shape: "circle",
104
+ geom_radius: 200,
105
+ });
85
106
  });
86
107
 
87
- communicator.on("loaded", function(data){
88
- console.log("loaded",data);
108
+ communicator.on("layers", function (data) {
109
+ console.log("layers received", data);
110
+ fillDisplayedLayersSelect(data);
89
111
  });
90
112
 
91
- communicator.on("layers", function(data){
92
- console.log("layers received",data);
93
- fillDisplayedLayersSelect(data);
113
+ communicator.on("getToc", function (data) {
114
+ console.log("getToc received", data);
94
115
  });
95
116
 
96
- communicator.on("geoJSONlayers", function(data){
97
- console.log("geoJSONlayers received",data);
98
- fillGeoJSONLayersSelect(data);
117
+ communicator.on("geoJSONlayers", function (data) {
118
+ console.log("geoJSONlayers received", data);
119
+ fillGeoJSONLayersSelect(data);
99
120
  });
100
121
 
101
122
  //error event
102
- communicator.on("error", function(data){
103
- console.error("error",data);
104
- cleanContainers();
105
- Error_container.innerHTML = data.error;
123
+ communicator.on("error", function (data) {
124
+ console.error("error", data);
125
+ cleanContainers();
126
+ Error_container.innerHTML = data.error;
106
127
  });
107
128
 
108
129
  //clicked coordinates
109
- communicator.on("coordinates", function(data){
110
- console.info("coordinates",data);
111
- cleanContainers();
112
- clickedCoordinates = [data.coordinates[0],data.coordinates[1]]
113
- Result_container.innerHTML = `Clicked coordinates -> x: ${data.coordinates[0]}, y: ${data.coordinates[1]}`;
130
+ communicator.on("coordinates", function (data) {
131
+ console.info("coordinates", data);
132
+ cleanContainers();
133
+ clickedCoordinates = [data.coordinates[0], data.coordinates[1]];
134
+ Result_container.innerHTML = `Clicked coordinates -> x: ${data.coordinates[0]}, y: ${data.coordinates[1]}`;
114
135
  });
115
136
 
116
- communicator.on("activeLayer", function(data){
117
- console.info("activeLayer",data);
118
- cleanContainers();
119
- Result_container.innerHTML = data.activeLayer;
137
+ communicator.on("activeLayer", function (data) {
138
+ console.info("activeLayer", data);
139
+ cleanContainers();
140
+ Result_container.innerHTML = data.activeLayer;
120
141
  });
121
142
 
122
- communicator.on("geolocation", function(data){
123
- console.info("geolocation",data);
124
- cleanContainers();
143
+ communicator.on("geolocation", function (data) {
144
+ console.info("geolocation", data);
145
+ cleanContainers();
125
146
  });
126
147
 
127
- communicator.on("GiswaterLayerAvailableFilters", function(data){
128
- console.info("GiswaterLayerAvailableFilters",data);
129
- cleanContainers();
130
- Result_container.innerHTML = data.filters;
148
+ communicator.on("GiswaterLayerAvailableFilters", function (data) {
149
+ console.info("GiswaterLayerAvailableFilters", data);
150
+ cleanContainers();
151
+ Result_container.innerHTML = data.filters;
131
152
  });
132
153
 
133
-
134
154
  //info event
135
- communicator.on("info", function(data){
136
- console.log("info received",data);
137
- var dataToRender = data.data;
138
- //depending on infoType, data.data can be an string or a JSON
139
- if(data.infoType==="giswater"){
140
- dataToRender = JSON.stringify(data.data)
141
- }
142
- cleanContainers();
143
- Result_container.innerText = dataToRender;
155
+ communicator.on("info", function (data) {
156
+ console.log("info received", data);
157
+ var dataToRender = data.data;
158
+ //depending on infoType, data.data can be an string or a JSON
159
+ if (data.infoType === "giswater") {
160
+ dataToRender = JSON.stringify(data.data);
161
+ }
162
+ cleanContainers();
163
+ Result_container.innerText = dataToRender;
144
164
  });
145
165
 
146
166
  //Layer elements list
147
- communicator.on("layerElements", function(data){
148
- console.log("layerElements received",data);
149
- var dataToRender = data.data;
150
- //depending on requested format, data.data can be an string (xml) or a JSON
151
- cleanContainers();
152
- Result_container.innerText = (typeof dataToRender==="object")? JSON.stringify(dataToRender): dataToRender;
167
+ communicator.on("layerElements", function (data) {
168
+ console.log("layerElements received", data);
169
+ var dataToRender = data.data;
170
+ //depending on requested format, data.data can be an string (xml) or a JSON
171
+ cleanContainers();
172
+ Result_container.innerText =
173
+ typeof dataToRender === "object"
174
+ ? JSON.stringify(dataToRender)
175
+ : dataToRender;
153
176
  });
154
177
 
155
178
  //giswater tiled background
156
- communicator.on("giswaterTiledBackgroundDisplayed", function(data){
157
- console.log("giswaterTiledBackgroundDisplayed",data);
158
- if(toggleGiswaterTiledCheck){
159
- toggleGiswaterTiledCheck.checked = data.visible;
160
- }
161
-
179
+ communicator.on("giswaterTiledBackgroundDisplayed", function (data) {
180
+ console.log("giswaterTiledBackgroundDisplayed", data);
181
+ if (toggleGiswaterTiledCheck) {
182
+ toggleGiswaterTiledCheck.checked = data.visible;
183
+ }
162
184
  });
163
- communicator.on("giswaterTiledBackgroundAvailable", function(data){
164
- console.log("giswaterTiledBackgroundAvailable",data);
165
- if(btToggleGiswaterTiled && data.available){
166
- btToggleGiswaterTiled.disabled = false;
167
- var use_giswater_tiled = document.querySelector("#use_giswater_tiled");
168
- if (use_giswater_tiled) {
169
- toggleGiswaterTiledCheck.checked = use_giswater_tiled.checked;
170
- }
171
- }
185
+ communicator.on("giswaterTiledBackgroundAvailable", function (data) {
186
+ console.log("giswaterTiledBackgroundAvailable", data);
187
+ if (btToggleGiswaterTiled && data.available) {
188
+ btToggleGiswaterTiled.disabled = false;
189
+ var use_giswater_tiled = document.querySelector("#use_giswater_tiled");
190
+ if (use_giswater_tiled) {
191
+ toggleGiswaterTiledCheck.checked = use_giswater_tiled.checked;
192
+ }
193
+ }
172
194
  });
173
- communicator.on("WMSInfoAvailable", function(){
174
- console.log("WMSInfoAvailable");
175
- if(btWMSInfo) btWMSInfo.disabled = false;
195
+ communicator.on("WMSInfoAvailable", function () {
196
+ console.log("WMSInfoAvailable");
197
+ if (btWMSInfo) btWMSInfo.disabled = false;
176
198
  });
177
- communicator.on("availableWMSLayers", function(data){
178
- console.log("availableWMSLayers",data);
179
- fillLayersSelect(data);
199
+ communicator.on("availableWMSLayers", function (data) {
200
+ console.log("availableWMSLayers", data);
201
+ fillLayersSelect(data);
180
202
  });
181
203
 
182
204
  function fillLayersSelect(options) {
183
- console.log('fillLayersSelect',options)
184
- var projectlayers = document.getElementById("projectlayers");
185
- if(projectlayers){
186
-
187
-
205
+ console.log("fillLayersSelect", options);
206
+ var projectlayers = document.getElementById("projectlayers");
207
+ if (projectlayers) {
188
208
  var length = projectlayers.options.length;
189
209
 
190
- for (i = length-1; i >= 0; i--) {
210
+ for (i = length - 1; i >= 0; i--) {
191
211
  projectlayers.options[i] = null;
192
212
  }
193
- for(var i = 0; i < options.length; i++) {
194
- var opt = options[i];
195
- var el = document.createElement("option");
196
- el.textContent = opt;
197
- el.value = opt;
198
- projectlayers.appendChild(el);
213
+ for (var i = 0; i < options.length; i++) {
214
+ var opt = options[i];
215
+ var el = document.createElement("option");
216
+ el.textContent = opt;
217
+ el.value = opt;
218
+ projectlayers.appendChild(el);
219
+ }
220
+ }
221
+ }
222
+
223
+ function fillDisplayedLayersSelect(options) {
224
+ var layers_select = document.getElementById("layers");
225
+ if (layers_select) {
226
+ //empty previous options
227
+ var length = layers_select.options.length;
228
+ for (i = length - 1; i >= 0; i--) {
229
+ layers_select.options[i] = null;
230
+ }
231
+ for (var i = 0; i < options.length; i++) {
232
+ var opt = options[i];
233
+ var el = document.createElement("option");
234
+ el.textContent = opt;
235
+ el.value = opt;
236
+ layers_select.appendChild(el);
199
237
  }
200
238
  }
201
239
  }
202
240
 
203
- function fillDisplayedLayersSelect(options){
204
- var layers_select = document.getElementById("layers");
205
- if(layers_select){
206
- //empty previous options
207
- var length = layers_select.options.length;
208
- for (i = length-1; i >= 0; i--) {
209
- layers_select.options[i] = null;
210
- }
211
- for(var i = 0; i < options.length; i++) {
212
- var opt = options[i];
213
- var el = document.createElement("option");
214
- el.textContent = opt;
215
- el.value = opt;
216
- layers_select.appendChild(el);
217
- }
218
- }
219
- }
220
-
221
- if(btDebug){
222
- btDebug.addEventListener("click", function(){
223
- var debug = parseInt(document.getElementById("debug").value);
224
- communicator.setDebug(debug);
225
- });
241
+ if (btDebug) {
242
+ btDebug.addEventListener("click", function () {
243
+ var debug = parseInt(document.getElementById("debug").value);
244
+ communicator.setDebug(debug);
245
+ });
226
246
  }
227
247
  // Actions
228
- btZoomIn.addEventListener("click", function(){
248
+ btZoomIn.addEventListener("click", function () {
229
249
  return communicator.ZoomIn();
230
250
  });
231
251
 
232
- btZoomOut.addEventListener("click", function(){
252
+ btZoomOut.addEventListener("click", function () {
233
253
  communicator.ZoomOut();
234
254
  });
235
- if(btZoomToCoordinates){
236
- btZoomToCoordinates.addEventListener("click", function(){
237
- let level = 4;
238
- if(document.getElementById('zoomLevelToCoordinates')){
239
- //zoom Level
240
- level = document.getElementById('zoomLevelToCoordinates').value
241
- }
242
- if(clickedCoordinates){
243
- communicator.zoomToCoordinates(clickedCoordinates[0],clickedCoordinates[1],level);
244
- }else{
245
- Error_container.innerHTML ="No coordinates provided";
246
- }
247
- });
248
- }
249
-
250
- if(btAddPoint){
251
- btAddPoint.addEventListener("click", function(){
252
- communicator.AddGeom('Point');
253
- });
254
- }
255
- if(btAddPolygon){
256
- btAddPolygon.addEventListener("click", function(){
257
- communicator.AddGeom('Polygon');
258
- });
259
- }
260
- if(btAddLine){
261
- btAddLine.addEventListener("click", function(){
262
- communicator.AddGeom('Line');
263
- });
264
- }
265
- if(btGeolocalize){
266
- btGeolocalize.addEventListener("click", function(){
267
- communicator.Geolocalize(true);
268
- });
269
- }
270
- if(btStopGeolocalize){
271
- btStopGeolocalize.addEventListener("click", function(){
272
- communicator.Geolocalize(false);
273
- });
255
+ if (btZoomToCoordinates) {
256
+ btZoomToCoordinates.addEventListener("click", function () {
257
+ let level = 4;
258
+ if (document.getElementById("zoomLevelToCoordinates")) {
259
+ //zoom Level
260
+ level = document.getElementById("zoomLevelToCoordinates").value;
261
+ }
262
+ if (clickedCoordinates) {
263
+ communicator.zoomToCoordinates(
264
+ clickedCoordinates[0],
265
+ clickedCoordinates[1],
266
+ level
267
+ );
268
+ } else {
269
+ Error_container.innerHTML = "No coordinates provided";
270
+ }
271
+ });
272
+ }
273
+
274
+ if (btAddPoint) {
275
+ btAddPoint.addEventListener("click", function () {
276
+ communicator.AddGeom("Point");
277
+ });
278
+ }
279
+ if (btAddPolygon) {
280
+ btAddPolygon.addEventListener("click", function () {
281
+ communicator.AddGeom("Polygon");
282
+ });
283
+ }
284
+ if (btAddLine) {
285
+ btAddLine.addEventListener("click", function () {
286
+ communicator.AddGeom("Line");
287
+ });
288
+ }
289
+ if (btGeolocalize) {
290
+ btGeolocalize.addEventListener("click", function () {
291
+ communicator.Geolocalize(true);
292
+ });
293
+ }
294
+ if (btStopGeolocalize) {
295
+ btStopGeolocalize.addEventListener("click", function () {
296
+ communicator.Geolocalize(false);
297
+ });
274
298
  }
275
299
  //**********************************************************
276
300
  //************** LAYERS ****************
277
301
  //**********************************************************
278
- if(btToggleLayer){
279
- btToggleLayer.addEventListener("click", function(){
280
-
281
- if(overrideLayerProperties){
282
- if(overrideLayerProperties.checked){
283
- var properties = {};
284
- if(toggleTransparentLayer){
285
- properties.transparent = toggleTransparentLayer.checked;
286
-
287
- }
288
- if(toggleSingleTile){
289
- properties.singletile = toggleSingleTile.checked;
290
- }
291
- if(gutter) properties.gutter = gutter.value;
292
- communicator.toggleLayer(document.getElementById('projectlayers').value,properties);
293
- return;
294
- }
295
-
296
- }
297
-
298
- communicator.toggleLayer(document.getElementById('projectlayers').value);
299
- });
300
- }
301
-
302
-
303
- if(btGetActiveLayer){
304
- btGetActiveLayer.addEventListener("click", function(){
305
- cleanContainers();
306
- communicator.getActiveLayer();
307
- });
308
- }
309
- if(btReloadDisplayedLayers){
310
- btReloadDisplayedLayers.addEventListener("click", function(){
311
- communicator.reloadDisplayedLayers();
312
- });
313
- }
314
- if(btLoadWMSLayers){
315
- btLoadWMSLayers.addEventListener("click", function (evt) {
316
- console.log('btLoadWMSLayers')
317
- communicator.loadWMSAvailableLayers();
318
- });
302
+ if (btToggleLayer) {
303
+ btToggleLayer.addEventListener("click", function () {
304
+ if (overrideLayerProperties) {
305
+ if (overrideLayerProperties.checked) {
306
+ var properties = {};
307
+ if (toggleTransparentLayer) {
308
+ properties.transparent = toggleTransparentLayer.checked;
309
+ }
310
+ if (toggleSingleTile) {
311
+ properties.singletile = toggleSingleTile.checked;
312
+ }
313
+ if (gutter) properties.gutter = gutter.value;
314
+ communicator.toggleLayer(
315
+ document.getElementById("projectlayers").value,
316
+ properties
317
+ );
318
+ return;
319
+ }
320
+ }
321
+
322
+ communicator.toggleLayer(document.getElementById("projectlayers").value);
323
+ });
324
+ }
325
+
326
+ if (btGetActiveLayer) {
327
+ btGetActiveLayer.addEventListener("click", function () {
328
+ cleanContainers();
329
+ communicator.getActiveLayer();
330
+ });
331
+ }
332
+ if (btReloadDisplayedLayers) {
333
+ btReloadDisplayedLayers.addEventListener("click", function () {
334
+ communicator.reloadDisplayedLayers();
335
+ });
336
+ }
337
+ if (btLoadWMSLayers) {
338
+ btLoadWMSLayers.addEventListener("click", function (evt) {
339
+ console.log("btLoadWMSLayers");
340
+ communicator.loadWMSAvailableLayers();
341
+ });
319
342
  }
320
343
 
321
344
  //Override layer properties
322
- if(overrideLayerProperties){
323
- overrideLayerProperties.addEventListener("click", function(){
324
- if(overrideLayerProperties.checked){
325
- if(containerOverride) containerOverride.style.display = 'block';
326
- }else{
327
- if(containerOverride) containerOverride.style.display = 'none';
328
- }
329
- });
345
+ if (overrideLayerProperties) {
346
+ overrideLayerProperties.addEventListener("click", function () {
347
+ if (overrideLayerProperties.checked) {
348
+ if (containerOverride) containerOverride.style.display = "block";
349
+ } else {
350
+ if (containerOverride) containerOverride.style.display = "none";
351
+ }
352
+ });
353
+ }
354
+
355
+ if (btGetToc) {
356
+ btGetToc.addEventListener("click", function (evt) {
357
+ console.log("btGetToc");
358
+ communicator.getToc();
359
+ });
360
+ }
361
+ ;
362
+ if(btChangeBackground){
363
+ btChangeBackground.addEventListener("click", function (evt) {
364
+ if(newBackground.value){
365
+ console.log("btChangeBackground",newBackground.value);
366
+ communicator.changeBackground(newBackground.value);
367
+ }else{
368
+ console.warn("no active layer")
369
+ }
370
+ });
330
371
  }
331
372
  /*
332
373
  overrideLayerProperties
@@ -338,186 +379,203 @@ containerOverride*/
338
379
  //**********************************************************
339
380
  //************** END LAYERS ****************
340
381
  //**********************************************************
341
- if(btClear){
342
- btClear.addEventListener("click", function(){
343
- cleanContainers();
344
- communicator.clear();
345
- });
346
- }
347
- if(btZoomToExtent){
348
- btZoomToExtent.addEventListener("click", function(){
349
- cleanContainers();
350
- communicator.zoomToExtent();
351
- });
352
- }
353
- if(btWMSInfo){
354
- btWMSInfo.addEventListener("click", function(){
355
- cleanContainers();
356
- communicator.infoFromCoordinates('wms',document.getElementById('layers').value,5,document.getElementById('formatWMS').value);
357
- });
358
- }
359
- if(btGiswaterInfo){
360
- btGiswaterInfo.addEventListener("click", function(){
361
- cleanContainers();
362
- communicator.infoFromCoordinates('giswater',document.getElementById('layers').value);
363
- });
364
- }
365
- if(btActiveLayer){
366
- btActiveLayer.addEventListener("click", function(){
367
- cleanContainers();
368
- communicator.setActiveLayer(document.getElementById('layers').value);
369
- currentActiveLayer = document.getElementById('layers').value;
370
- document.getElementById('currentActiveLayer').innerHTML = `<b>Active layer</b>: ${currentActiveLayer}`;
371
- if(btAddGeoJSONFromGiswater){
372
- btAddGeoJSONFromGiswater.disabled = false;
373
- }
374
- document.getElementById('currentActiveLayerForGeoJSON').innerHTML = ` ${currentActiveLayer}`;
375
- });
376
- }
377
-
378
- if(btHighlight){
379
- btHighlight.addEventListener("click", function(){
380
- cleanContainers();
381
- var options = {
382
- geom: document.getElementById('geom').value
383
- }
384
- if(zoomToHighlightCheck.checked){
385
- options.zoom = {
386
- type: 'geom'
387
- };
388
- }else{
389
- options.zoom = {
390
- type: 'level',
391
- zoomLevel : document.getElementById('zoomLevel').value
392
- }
393
- }
394
- communicator.Highlight(options);
395
-
396
- });
397
- }
398
- if(zoomToHighlightCheck){
399
- //disable/enable zoom level to highlight
400
- zoomToHighlightCheck.addEventListener("click", function(){
401
- document.getElementById('zoomLevel').disabled = zoomToHighlightCheck.checked;
402
- });
382
+ if (btClear) {
383
+ btClear.addEventListener("click", function () {
384
+ cleanContainers();
385
+ communicator.clear();
386
+ });
387
+ }
388
+ if (btZoomToExtent) {
389
+ btZoomToExtent.addEventListener("click", function () {
390
+ cleanContainers();
391
+ communicator.zoomToExtent();
392
+ });
393
+ }
394
+ if (btWMSInfo) {
395
+ btWMSInfo.addEventListener("click", function () {
396
+ cleanContainers();
397
+ communicator.infoFromCoordinates(
398
+ "wms",
399
+ document.getElementById("layers").value,
400
+ 5,
401
+ document.getElementById("formatWMS").value
402
+ );
403
+ });
404
+ }
405
+ if (btGiswaterInfo) {
406
+ btGiswaterInfo.addEventListener("click", function () {
407
+ cleanContainers();
408
+ communicator.infoFromCoordinates(
409
+ "giswater",
410
+ document.getElementById("layers").value
411
+ );
412
+ });
413
+ }
414
+ if (btActiveLayer) {
415
+ btActiveLayer.addEventListener("click", function () {
416
+ cleanContainers();
417
+ communicator.setActiveLayer(document.getElementById("layers").value);
418
+ currentActiveLayer = document.getElementById("layers").value;
419
+ document.getElementById(
420
+ "currentActiveLayer"
421
+ ).innerHTML = `<b>Active layer</b>: ${currentActiveLayer}`;
422
+ if (btAddGeoJSONFromGiswater) {
423
+ btAddGeoJSONFromGiswater.disabled = false;
424
+ }
425
+ document.getElementById(
426
+ "currentActiveLayerForGeoJSON"
427
+ ).innerHTML = ` ${currentActiveLayer}`;
428
+ });
429
+ }
430
+
431
+ if (btHighlight) {
432
+ btHighlight.addEventListener("click", function () {
433
+ cleanContainers();
434
+ var options = {
435
+ geom: document.getElementById("geom").value,
436
+ };
437
+ if (zoomToHighlightCheck.checked) {
438
+ options.zoom = {
439
+ type: "geom",
440
+ };
441
+ } else {
442
+ options.zoom = {
443
+ type: "level",
444
+ zoomLevel: document.getElementById("zoomLevel").value,
445
+ };
446
+ }
447
+ communicator.Highlight(options);
448
+ });
449
+ }
450
+ if (zoomToHighlightCheck) {
451
+ //disable/enable zoom level to highlight
452
+ zoomToHighlightCheck.addEventListener("click", function () {
453
+ document.getElementById("zoomLevel").disabled =
454
+ zoomToHighlightCheck.checked;
455
+ });
403
456
  }
404
457
  //Giswater tiled background
405
- if(btToggleGiswaterTiled && toggleGiswaterTiledCheck){
406
- btToggleGiswaterTiled.addEventListener("click", function(){
407
- cleanContainers();
408
- communicator.toggleGiswaterTiled(toggleGiswaterTiledCheck.checked);
409
- });
458
+ if (btToggleGiswaterTiled && toggleGiswaterTiledCheck) {
459
+ btToggleGiswaterTiled.addEventListener("click", function () {
460
+ cleanContainers();
461
+ communicator.toggleGiswaterTiled(toggleGiswaterTiledCheck.checked);
462
+ });
410
463
  }
411
464
 
412
465
  //**********************************************************
413
466
  //************** GeoJSON ****************
414
467
  //**********************************************************
415
468
 
416
- if(geoJSONFileContent){
417
- geoJSONFileContent.addEventListener("change", handleFiles, false);
418
- function handleFiles() {
419
- const fileList = this.files;
420
- // use the 1st file from the list
421
- f = fileList[0];
422
- geoJSONName = f.name;
423
- var reader = new FileReader();
424
- // Closure to capture the file information.
425
- reader.onload = (function(theFile) {
426
- return function(e) {
427
- geoJSONContent = e.target.result;
428
- };
429
- })(f);
430
-
431
- // Read in the image file as a data URL.
432
- reader.readAsText(f);
433
-
434
- }
435
- }
436
- if(btAddGeoJSON){
437
- btAddGeoJSON.addEventListener("click", function(){
438
- var geoToSend = null;
439
- var geojsondata = document.querySelector("#geojsondata");
440
- if(geojsondata){
441
- console.log("using geoJSON input");
442
- var cleanjson = geojsondata.value.replace(/(\r\n|\n|\r)/gm, "");
443
- geoToSend = cleanjson;
444
- }
445
- if(geoJSONContent){
446
- console.log("using geoJSON file");
447
- geoToSend = geoJSONContent;
448
-
449
- }
450
- var fillcolor = document.querySelector("#fillcolor");
451
- var strokecolor = document.querySelector("#strokecolor");
452
-
453
- //Check JSON
454
- try{
455
- let options = {
456
- fillcolor: null,
457
- strokecolor: null
458
- }
459
- if(fillcolor){
460
- options.fillcolor = fillcolor.value;
461
- }
462
- if(strokecolor){
463
- options.strokecolor = strokecolor.value;
464
- }
465
- communicator.addGeoJSON(JSON.parse(geoToSend),options,geoJSONName);
466
- }catch(e){
467
- console.error("invalid geoJSON",e);
468
- }
469
- });
470
- }
471
-
472
- if(btClearGeoJSON){
473
- btClearGeoJSON.addEventListener("click", function(){
474
- communicator.clearGeoJSON();
475
- });
476
- }
477
-
478
- if(btGeoJSONInfo){
479
- btGeoJSONInfo.addEventListener("click", function(){
480
- cleanContainers();
481
- let tolerance = 10;
482
- if(hitTolerance){
483
- //(typeof hitTolerance!='undefined') ? hitTolerance : 5,
484
- tolerance = (hitTolerance.value=='' || hitTolerance.value==null) ? 5 : parseInt(hitTolerance.value);
485
-
486
- }
487
- communicator.infoFromCoordinates('geojson',document.getElementById('geojsonlayers').value,tolerance);
488
- });
489
- }
490
-
491
- if(btRemoveGeoJSONLayer){
492
- btRemoveGeoJSONLayer.addEventListener("click", function(){
493
- cleanContainers();
494
- communicator.removeGeoJSONLayer(document.getElementById('geojsonlayers').value);
495
- });
496
- }
497
-
498
-
499
- function fillGeoJSONLayersSelect(options){
500
- var layers_select = document.getElementById("geojsonlayers");
501
- if(layers_select){
502
- //empty previous options
503
- var length = layers_select.options.length;
504
- for (i = length-1; i >= 0; i--) {
505
- layers_select.options[i] = null;
506
- }
507
- for(var i = 0; i < options.length; i++) {
508
- var opt = options[i];
509
- var el = document.createElement("option");
510
- el.textContent = opt;
511
- el.value = opt;
512
- layers_select.appendChild(el);
513
- }
514
- }
515
- if(btGeoJSONInfo && options.length>0){
516
- btGeoJSONInfo.disabled = false;
517
- }
518
- if(btRemoveGeoJSONLayer && options.length>0){
519
- btRemoveGeoJSONLayer.disabled = false;
520
- }
469
+ if (geoJSONFileContent) {
470
+ geoJSONFileContent.addEventListener("change", handleFiles, false);
471
+ function handleFiles() {
472
+ const fileList = this.files;
473
+ // use the 1st file from the list
474
+ f = fileList[0];
475
+ geoJSONName = f.name;
476
+ var reader = new FileReader();
477
+ // Closure to capture the file information.
478
+ reader.onload = (function (theFile) {
479
+ return function (e) {
480
+ geoJSONContent = e.target.result;
481
+ };
482
+ })(f);
483
+
484
+ // Read in the image file as a data URL.
485
+ reader.readAsText(f);
486
+ }
487
+ }
488
+ if (btAddGeoJSON) {
489
+ btAddGeoJSON.addEventListener("click", function () {
490
+ var geoToSend = null;
491
+ var geojsondata = document.querySelector("#geojsondata");
492
+ if (geojsondata) {
493
+ console.log("using geoJSON input");
494
+ var cleanjson = geojsondata.value.replace(/(\r\n|\n|\r)/gm, "");
495
+ geoToSend = cleanjson;
496
+ }
497
+ if (geoJSONContent) {
498
+ console.log("using geoJSON file");
499
+ geoToSend = geoJSONContent;
500
+ }
501
+ var fillcolor = document.querySelector("#fillcolor");
502
+ var strokecolor = document.querySelector("#strokecolor");
503
+
504
+ //Check JSON
505
+ try {
506
+ let options = {
507
+ fillcolor: null,
508
+ strokecolor: null,
509
+ };
510
+ if (fillcolor) {
511
+ options.fillcolor = fillcolor.value;
512
+ }
513
+ if (strokecolor) {
514
+ options.strokecolor = strokecolor.value;
515
+ }
516
+ communicator.addGeoJSON(JSON.parse(geoToSend), options, geoJSONName);
517
+ } catch (e) {
518
+ console.error("invalid geoJSON", e);
519
+ }
520
+ });
521
+ }
522
+
523
+ if (btClearGeoJSON) {
524
+ btClearGeoJSON.addEventListener("click", function () {
525
+ communicator.clearGeoJSON();
526
+ });
527
+ }
528
+
529
+ if (btGeoJSONInfo) {
530
+ btGeoJSONInfo.addEventListener("click", function () {
531
+ cleanContainers();
532
+ let tolerance = 10;
533
+ if (hitTolerance) {
534
+ //(typeof hitTolerance!='undefined') ? hitTolerance : 5,
535
+ tolerance =
536
+ hitTolerance.value == "" || hitTolerance.value == null
537
+ ? 5
538
+ : parseInt(hitTolerance.value);
539
+ }
540
+ communicator.infoFromCoordinates(
541
+ "geojson",
542
+ document.getElementById("geojsonlayers").value,
543
+ tolerance
544
+ );
545
+ });
546
+ }
547
+
548
+ if (btRemoveGeoJSONLayer) {
549
+ btRemoveGeoJSONLayer.addEventListener("click", function () {
550
+ cleanContainers();
551
+ communicator.removeGeoJSONLayer(
552
+ document.getElementById("geojsonlayers").value
553
+ );
554
+ });
555
+ }
556
+
557
+ function fillGeoJSONLayersSelect(options) {
558
+ var layers_select = document.getElementById("geojsonlayers");
559
+ if (layers_select) {
560
+ //empty previous options
561
+ var length = layers_select.options.length;
562
+ for (i = length - 1; i >= 0; i--) {
563
+ layers_select.options[i] = null;
564
+ }
565
+ for (var i = 0; i < options.length; i++) {
566
+ var opt = options[i];
567
+ var el = document.createElement("option");
568
+ el.textContent = opt;
569
+ el.value = opt;
570
+ layers_select.appendChild(el);
571
+ }
572
+ }
573
+ if (btGeoJSONInfo && options.length > 0) {
574
+ btGeoJSONInfo.disabled = false;
575
+ }
576
+ if (btRemoveGeoJSONLayer && options.length > 0) {
577
+ btRemoveGeoJSONLayer.disabled = false;
578
+ }
521
579
  }
522
580
 
523
581
  //**********************************************************
@@ -528,24 +586,22 @@ function fillGeoJSONLayersSelect(options){
528
586
  //************** GISWATER FILTERS ****************
529
587
  //**********************************************************
530
588
 
589
+ if (btsetGiswaterFilters) {
590
+ btsetGiswaterFilters.addEventListener("click", function () {
591
+ var filters = document.getElementById("giswaterFilters").value;
531
592
 
532
- if(btsetGiswaterFilters){
533
- btsetGiswaterFilters.addEventListener("click", function(){
534
- var filters = document.getElementById('giswaterFilters').value;
535
-
536
- cleanContainers();
537
- communicator.setGiswaterFilters(filters);
538
- });
593
+ cleanContainers();
594
+ communicator.setGiswaterFilters(filters);
595
+ });
539
596
  }
540
- if(btgetGiswaterFilters){
541
- btgetGiswaterFilters.addEventListener("click", function(){
542
- var layerName = document.getElementById('layers').value;
543
- cleanContainers();
544
- communicator.getGiswaterLayerAvailableFilters(layerName);
545
- });
597
+ if (btgetGiswaterFilters) {
598
+ btgetGiswaterFilters.addEventListener("click", function () {
599
+ var layerName = document.getElementById("layers").value;
600
+ cleanContainers();
601
+ communicator.getGiswaterLayerAvailableFilters(layerName);
602
+ });
546
603
  }
547
604
 
548
-
549
605
  //**********************************************************
550
606
  //************** END GISWATER FILTERS ****************
551
607
  //**********************************************************
@@ -554,33 +610,32 @@ if(btgetGiswaterFilters){
554
610
  //************** CUSTOM COLORS ****************
555
611
  //**********************************************************
556
612
 
557
- if(btSetColors){
558
-
559
- btSetColors.addEventListener("click", function(){
560
- var properties = {
561
- geom_stroke_color: 'rgb(19, 39, 99,0.5)',
562
- geom_fill_color: 'rgb(19, 39, 99,0.5)',
563
- geom_stroke_width: 1,
564
- geom_shape: 'circle',
565
- geom_radius: 4,
566
- }
567
- if(geom_stroke_color){
568
- properties.geom_stroke_color = geom_stroke_color.value;
569
- }
570
- if(geom_stroke_width){
571
- properties.geom_stroke_width = geom_stroke_width.value;
572
- }
573
- if(geom_fill_color){
574
- properties.geom_fill_color = geom_fill_color.value;
575
- }
576
- if(geom_shape){
577
- properties.geom_shape = geom_shape.value;
578
- }
579
- if(geom_radius){
580
- properties.geom_radius = geom_radius.value;
581
- }
582
- communicator.setCustomColors(properties);
583
- });
613
+ if (btSetColors) {
614
+ btSetColors.addEventListener("click", function () {
615
+ var properties = {
616
+ geom_stroke_color: "rgb(19, 39, 99,0.5)",
617
+ geom_fill_color: "rgb(19, 39, 99,0.5)",
618
+ geom_stroke_width: 1,
619
+ geom_shape: "circle",
620
+ geom_radius: 4,
621
+ };
622
+ if (geom_stroke_color) {
623
+ properties.geom_stroke_color = geom_stroke_color.value;
624
+ }
625
+ if (geom_stroke_width) {
626
+ properties.geom_stroke_width = geom_stroke_width.value;
627
+ }
628
+ if (geom_fill_color) {
629
+ properties.geom_fill_color = geom_fill_color.value;
630
+ }
631
+ if (geom_shape) {
632
+ properties.geom_shape = geom_shape.value;
633
+ }
634
+ if (geom_radius) {
635
+ properties.geom_radius = geom_radius.value;
636
+ }
637
+ communicator.setCustomColors(properties);
638
+ });
584
639
  }
585
640
 
586
641
  //**********************************************************
@@ -590,17 +645,21 @@ if(btSetColors){
590
645
  //**********************************************************
591
646
  //************** WMS TABLE ****************
592
647
  //**********************************************************
593
- if(btGetElementsFromLayer){
594
-
595
- btGetElementsFromLayer.addEventListener("click", function(){
596
- let limit = document.getElementById('limit') ? document.getElementById('limit').value : 100;
597
- let format = document.getElementById('format') ? document.getElementById('format').value : 'xml';
598
- communicator.getElementsFromLayer(document.getElementById('layers').value,limit,format);
599
- });
648
+ if (btGetElementsFromLayer) {
649
+ btGetElementsFromLayer.addEventListener("click", function () {
650
+ let limit = document.getElementById("limit")
651
+ ? document.getElementById("limit").value
652
+ : 100;
653
+ let format = document.getElementById("format")
654
+ ? document.getElementById("format").value
655
+ : "xml";
656
+ communicator.getElementsFromLayer(
657
+ document.getElementById("layers").value,
658
+ limit,
659
+ format
660
+ );
661
+ });
600
662
  }
601
663
  //**********************************************************
602
664
  //************** END WMS TABLE ****************
603
665
  //**********************************************************
604
-
605
-
606
-