-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewer.js
2388 lines (2167 loc) · 80 KB
/
viewer.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
OpenLayers.Lang.nl = OpenLayers.Util.applyDefaults({
'Overlays': 'Informatielagen'
});
OpenLayers.Lang.setCode('nl');
var Geogem = Geogem || {};
Geogem.VERSION = '2020.09.23';
Geogem.Settings = {
/**
* Reverse geocoder settings:
* default is geoserver.nl GET
*/
reverseGeocoder: {
//url: location.protocol + '//' + location.hostname + '/geocoder-1.0.1/revgeocoder',
url: location.protocol + '//geodata.nationaalgeoregister.nl/locatieserver/revgeo?',
method: 'GET'
},
/**
* Geocoder settings:
* Viewer zal adresveld bovenin krijgen met tooltip die te wijzigen is door
* gemeente Nieuwegein (in settings.js)
* Inzoomen op straat kent een bepaalde marge rond extent, en een minimum scale
* (instelbaar in settings.js); inzoomen op verblijfsobject kent ook een
* bepaalde marge en minimum scale
* Autocomplete van adresveld is instelbaar; standaard na 3 tekens, 0.5 sec, en max 10 resultaten
* 40 posities in adresveld voor straat + huisnr
*/
geocoder: {
//tooltip: 'Zoek op postcode of straat, met huisnummers.',
extentMargin: 100, // postcode en straat
pointMargin: 20, // coordinaat van verblijfsobject
minimumZoomScale: 500,
autocomplete: {
minLength: 3,
delay: 200
},
inputSize: 40,
// nieuwegein geocoder (alleen werkend voor Nieuwegein!)
// heeft 'autocomplete'
//url: location.protocol + '//' + location.host + '/geocoder/geocode?',
// pdok geocoder
// heeft GEEN 'autocomplete' omdat de pdok geocoder geen wildcards ondersteund
//url: location.protocol + '//geodata.nationaalgeoregister.nl/geocoder/Geocoder?',
//type: 'pdok',
//city: 'nieuwegein',
// pdok locatieserver V3
//url: location.protocol + '//geodata.nationaalgeoregister.nl/locatieserver/v3/suggest?',
//type: 'pdoklocatieserver',
//city: 'nieuwegein',
// pdok locatieserver V3
url: location.protocol + '//geodata.nationaalgeoregister.nl/locatieserver/v3/suggest?',
type: 'pdoklocatieserver',
city: 'nieuwegein'
},
// NL tileschema PDOK
//maxExtent: new OpenLayers.Bounds(-65200.96, 242799.04, 375200.96, 683200.96),
// centrum Geonovum NL tileschema
// tileOrigin: new OpenLayers.LonLat(155000, 463000),
// NL tileschema Geonovum
maxExtent: new OpenLayers.Bounds(-285401.920, 22598.080, 595401.920, 903401.920),
resolutions: new Array(
3440.640,
1720.320,
860.160,
430.080,
215.040,
107.520,
53.760,
26.880,
13.440,
6.720,
3.360,
1.680,
0.840,
0.420,
0.210,
0.105,
0.0525
),
restrictedExtent: new OpenLayers.Bounds(130000, 445000, 140000, 455000),
nieuwegeinExtent: new OpenLayers.Bounds(128253, 445498, 141747, 453226),
defaultPopupSize: '400,400',
baseLayers: [{
title: 'Luchtfoto',
url: location.protocol + '//' + location.hostname + '/mapproxy/service',
params: {
layers: 'basisluchtfoto', // geowebcache layer
format: 'image/jpeg'
},
options: {
attribution: 'Luchtfoto 2018'
//transitionEffect:'resize'
}
},
{
title: 'Kaart',
url: location.protocol + '//' + location.hostname + '/mapproxy/service',
params: {
layers: 'basistopo', // geowebcache layer
format: 'image/jpeg'
},
options: {
//transitionEffect:'resize'
}
}
],
overLays: [
// see template app for possibilities
],
/**
* Let op: url moet eindigen op ? of &
*/
urlParams: {},
/**
* If provide a (fixed) legend, it will be shown in the map
*/
legendUrl: null,
/**
* If provided a infourl, an 'i'-button will be shown, and
* the info from the url will be shown in sidebar content
* when clicked on the i-button
*/
infoUrl: null,
/**
* If property 'geolocation'=='locate' or 'track', the geolocation control
* will be activated and
* try to do a one time 'find my position' (in case of 'locate')
* try to track every x seconds (in case of 'track')
*/
geolocation: false, // default false, or either 'locate' or 'track'
/**
* position flag/icon showing after a geocoding result
*/
usePositionFlag: true, // defaulting to true
keepPositionFlag: false, // to NOT let it fade away after 2 zoom/pans
controls: [],
infoTab: null,
featureInfoScreen: false,
};
Geogem.popup = null;
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
var isMobile = ua.indexOf("mobile") > -1;
var isIthing = (ua.match(/iphone/i)) || (ua.match(/ipod/i)) || (ua.match(/ipad/i));
if (isAndroid || isMobile || isIthing) {
// will only work in apps, NOT in basisviewer2 itself!!
document.write('<link rel="stylesheet" href="../../basisviewer2/styles/mobile.css" type="text/css" />');
}
Geogem.combine_url_params = function (url, data) {
if (!isType(data, 'object')) {
return url;
}
return url + (url.indexOf('?') < 0 ? '?' : (url[url.length - 1] == '&' ? '' : '&')) + $.param(data);
};
Geogem.openFormulier = function (url) {
// doorsturen
// in mobiele apparaten in hetzelfde window, op desktop in nieuw window
if (isMobile) {
location.href = url;
} else {
// eform openen in nieuw window
window.open(url, "eform");
}
};
Geogem.formatAttributes = function (attributes, title, fields) {
// when this feature holds ONLY null/undefined values return ""
function isEmpty(_map) {
for (var key in _map) {
if (_map[key]) {
return false;
}
}
return true;
}
if (isEmpty(attributes)) {
return "";
}
var html = '';
if (!fields) {
// use attribute names if fields are missing
fields = {};
for (var field in attributes) {
fields[field] = field;
}
}
if (title) {
html += '<h3>' + title + '</h3>';
}
if (attributes) {
//html += '<table border=0 id="attrpopuptable">'
var row = 0;
var rowstyle;
var value;
for (var field in fields) {
row++;
rowstyle = row % 2;
if (field in attributes === false) {
// either wrongly configured fields, OR at this zoomlevel there are other fields?
// Anyway: ignore
}
/*else if (field.substring(0, 5) == 'DATUM') {
// reorder year, month and date
console.log(fields[field])
html += '<tr><td class="first">' + fields[field] + '</td><td class="second">' + attributes[field].substring(8, 10) + '-' + attributes[field].substring(5, 7) + '-' + attributes[field].substring(0, 4) + '</td></tr>';
}*/
else if (field.substring(0, 7) == 'snippet') {
// for KML: NO style attribute
} else if (field.substring(0, 5) == 'style') {
// for KML: NO style attribute
} else if (field.substring(0, 5) == 'label') {
// for KML: a label attribute is NOT to be shown in popup
} else if (field.substring(0, 11) == 'description') {
// for KML: NO 'key' in front of information (description is html already)
html += '<tr><td colspan="2">' + attributes[field] + '</td></tr>';
} else if (field.substring(0, 4) == 'name') {
// for KML: NO 'name' or 'description' in front of information
html = '<tr><td colspan="2"><b>' + attributes[field] + '</b></td></tr>' + html;
//html += '<tr><td colspan="2"><b>'+ attributes[field] + '</b></td></tr>';
} else if (field.substring(0, 10) == 'visibility') {
// for KML: NO 'visibility'
} else if (attributes[field] instanceof Object) {
// for KML from for example qgis
value = attributes[field]['value'];
if (value !== undefined) {
if (value.slice(0, 4) == 'http') {
// clean url: lets try to make it a link
value = '<a href="' + value + '" target="_blank">' + value + '</a>';
}
html += '<tr class="inforow' + rowstyle + '"><td class="first"><b>' + attributes[field]['displayName'] + '</b></td class="second"><td>' + value + '</td></tr>';
}
} else if (field.substring(0, 4).toUpperCase() == 'FOTO') {
value = attributes[field];
// development
//value = "http://geoserver.nieuwegein.nl/beheer2014fotos/m_reparatieplekken_reparatieplek8.jpg";
if (value && value.length > 5) {
html += '<tr class="inforow' + rowstyle + '"><td class="first">' + fields[field] + '</td></tr>';
if (value.indexOf('|') !== -1) {
html += '<tr><td colspan="2">';
var fotoarray = value.split('|');
$.each($(fotoarray), function(index, item) {
html += '<a href="' + item + '" target="basisviewer_foto"><img style="border:0;width:220px;" src="' + item + '"/></a>';
});
html += '</td></tr>';
} else {
html += '<tr><td colspan="2"><a href="' + value + '" target="basisviewer_foto"><img style="border:0;width:220px;" src="' + value + '"/></a></td></tr>';
}
}
} else if (field.substring(0, 5).toUpperCase() == 'VIDEO') {
value = attributes[field];
// development
//value = "http://geoserver.nieuwegein.nl/beheer2014fotos/m_reparatieplekken_reparatieplek8.jpg";
if (value && value.length > 5) {
html += '<tr class="inforow' + rowstyle + '"><td class="first">' + fields[field] + '</td></tr>';
html += '<tr><td colspan="2"><video width="480" controls>' +
'<source src="' + value + '">' +
'</video><br><br></td></tr>';
}
} else {
value = attributes[field];
// config error
/*if (field in attributes == false){
//alert("Configuratie fout: '"+field+"' is niet een attribuut van deze laag");
}
else {*/
// value could be null
if (value === undefined) {
value = ' - ';
}
// tricky: value can be a boolean: like false; make a string from it for this test
else if (("" + value).slice(0, 4) == 'http') {
// clean url: lets try to make it a link
value = '<a href="' + value + '" target="_blank">' + value + '</a>';
}
// tricky: value can be a boolean: like false; make a string from it for this test
else if (("" + value).slice(0, 10) == 'data:image') {
// clean url: lets try to make it a link
value = '<img src="' + value + '" width="100%"/>';
}
html += '<tr class="inforow' + rowstyle + '"><td class="first">' + fields[field] + '</td><td class="second">' + value + '</td></tr>';
//}
}
}
html = '<table border=0 id="attrpopuptable">' + html + '</table><br/>';
}
return html;
};
if (location.search !== '') {
var params = location.search.substr(1).split('&');
for (var i = 0; i < params.length; i++) {
var pos = params[i].indexOf('=');
if (pos > 0) {
var value = params[i].substr(pos + 1);
if (value == 'true') {
value = true;
} else if (value == 'false') {
value = false;
} else if (value.match(/^[0-9]+$/)) {
value = parseInt(value);
} else if (value.match(/^\-?[0-9]*\.[0-9]*$/)) {
value = parseFloat(value);
}
Geogem.Settings.urlParams[params[i].substr(0, pos)] = value;
}
}
}
/**
* Zorg dat OpenLayers alleen voor zichtbare lagen (in-range) de feature info
* opvraagt. Dit gebeurd door hieronder calculateInRange() te gebruiken samen met
* getVisibility().
*/
OpenLayers.Control.WMSGetFeatureInfo.prototype.findLayers = function () {
var candidates = this.layers || this.map.layers;
var layers = [];
var layer, url;
for (var i = 0, len = candidates.length; i < len; ++i) {
layer = candidates[i];
if (layer instanceof OpenLayers.Layer.WMS &&
(!this.queryVisible || (layer.getVisibility() && layer.calculateInRange()))) {
url = layer.url instanceof Array ? layer.url[0] : layer.url;
// if the control was not configured with a url, set it
// to the first layer url
if (this.drillDown === false && !this.url) {
this.url = url;
}
if (this.drillDown === true || this.urlMatches(url)) {
layers.push(layer);
}
}
}
return layers;
};
/*
We want to be able to see only ONE layer viewable at a time
(so like the datalayers are a radio group)
You can do that by setting singleDataLayerView to true in a layerSwitcher instance:
Like:
layermanager = new OpenLayers.Control.LayerSwitcher();
layermanager.singleDataLayerView=true;
*/
OpenLayers.Control.LayerSwitcher.prototype.onButtonClick = function (evt) {
// we remove all popups and make sure the sidebar doesn't open!
var ls_popup = true;
Geogem.removeAllPopups(ls_popup);
var button = evt.buttonElement;
if (button === this.minimizeDiv) {
this.minimizeControl();
} else if (button === this.maximizeDiv) {
this.maximizeControl();
} else if (button._layerSwitcher === this.id) {
if (button["for"]) {
button = document.getElementById(button["for"]);
}
if (!button.disabled) {
if (button.type == "radio") {
button.checked = true;
this.map.setBaseLayer(this.map.getLayer(button._layer));
} else {
var checked = !button.checked;
if (checked && this.singleDataLayerView) {
for (var i = 0, len = this.dataLayers.length; i < len; i++) {
var layerEntry = this.dataLayers[i];
if (button._layer == layerEntry.inputElem._layer) {
layerEntry.layer.setVisibility(true);
} else {
layerEntry.layer.setVisibility(false);
}
}
} else if (this.singleDataLayerView) {
} else {
button.checked = !button.checked;
}
//this.updateMap();
this.updateMap(this.map.getLayer(button._layer));
}
}
}
};
Geogem.onFeatureSelect = function (e) {
var feature = e.feature;
var layer = e.object;
var content = null;
var attributes = null;
if (feature.cluster) {
if (feature.attributes.count > 1) {
content += 'Aantal features: ' + feature.attributes.count;
} else {
attributes = feature.cluster ? feature.cluster[0].attributes : feature.attributes;
}
} else {
attributes = feature.attributes;
}
// layer can have a attribute 'geogem_fields', set in settings/init of the layer
if (layer && layer.geogem_fields) {
content = Geogem.formatAttributes(attributes, '', layer.geogem_fields);
} else {
content = Geogem.formatAttributes(attributes);
}
if (content) {
var popupSize = null;
var tmp = '$POPUP_SIZE$';
if (tmp === '' || tmp.indexOf('$') >= 0) {
tmp = Geogem.Settings.defaultPopupSize;
}
tmp = tmp.split(',');
if (tmp.length == 2) {
popupSize = new OpenLayers.Size(parseInt(tmp[0]), parseInt(tmp[1]));
} else {
alert('Fout bij instellen popupafmeting');
}
// remove all (old) popups
Geogem.removeAllPopups();
if ($('#sidebar').length === 0) {
// new popup
Geogem.popup = null;
Geogem.popup = new OpenLayers.Popup.FramedCloud("geoviewerpopup", // id
feature.geometry.getBounds().getCenterLonLat(), // lonlat
popupSize, // contentSize
content, // contentHTML
null, // anchor
true, // closeBox
Geogem.onPopupClose // closeBoxCallback
);
if (popupSize) {
Geogem.popup.maxSize = popupSize;
}
feature.popup = Geogem.popup;
Geogem.popup.feature = feature;
this.map.addPopup(Geogem.popup);
} else {
// sidebar
Geogem.showSidebarContent(content);
}
}
};
Geogem.onPopupClose = function (e) {
//console.log(Geogem.popup.feature);
//Geogem.removeAllPopups();
Geogem.selectControl.unselect(Geogem.popup.feature);
};
Geogem.onFeatureUnselect = function (e) {
var feature = e.feature;
var popup = feature.popup;
if (!popup) {
//alert('feature popup is null');
OpenLayers.Console.warn('feature popup is null');
var popupElement = document.getElementById("geoviewerpopup");
var map = feature.layer.map;
if (map.popups.length == 1 && map.popups[0].div === popupElement) {
popup = map.popups[0];
}
}
if (popup !== null && popup.map !== null && feature.layer.map.popups.length > 0) {
feature.layer.map.removePopup(popup);
popup.destroy();
}
feature.popup = null;
};
Geogem.removeAllPopups = function (ls_popup) {
if (Geogem.map.popups.length > 0) {
for (var i = 0; i < Geogem.map.popups.length; i++) {
Geogem.map.removePopup(Geogem.map.popups[i]);
}
}
if ($('#sidebar').length > 0 && $('#sidebar').hasClass('sidebarhide')) {
if (ls_popup !== true) {
//$('#sidebar').toggleClass('sidebarhide');
}
}
};
Geogem.handleLoadStart = function (e) {
Geogem.removeAllPopups();
};
/*
config = {
type: 'kml',
title: 'Dit is een kml laag',
protocolOptions: {
url: "kunstroute.kml"
,format: new OpenLayers.Format.KML({
kmlns: "http://earth.google.com/kml/2.2",
extractStyles: true,
extractAttributes: true })
}
}
*/
Geogem.createKmlLayer = function (config) {
// default kml protocol options:
// extract styles and attributes
// kmlns: "http://earth.google.com/kml/2.2"
// to be overridden in settings
var kmlProtocolOptions = {
url: "",
format: new OpenLayers.Format.KML({
kmlns: "http://earth.google.com/kml/2.2",
extractStyles: true,
extractAttributes: true
})
};
OpenLayers.Util.extend(kmlProtocolOptions, config.protocolOptions);
// defining default and select styles for KML layers
var style = {
externalGraphic: '/basisviewer2/img/marker.png',
cursor: 'pointer',
graphicTitle: " ${name} ",
graphicWidth: 24,
graphicHeight: 32,
graphicXOffset: -9,
graphicYOffset: -30,
strokeColor: '#88179F',
strokeOpacity: 0.6,
strokeWidth: 4,
strokeDashstyle: 'solid', // solid | dot | dash | dashdot | longdash | longdashdot | solid
labelOutlineWidth: 3
};
if (config.style) {
OpenLayers.Util.extend(style, config.style);
}
var styleOptions = {};
// if there is a label config
if (config.labels) {
// label - {String} The text for an optional label. For browsers that use the canvas renderer, this requires either
// fillText or mozDrawText to be available.
// labelAlign - {String} Label alignment. This specifies the insertion point relative to the text. It is a string
// composed of two characters. The first character is for the horizontal alignment, the second for the vertical
// alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for vertical
// alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb". Default is "cm".
// labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer.
// labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer.
// labelSelect - {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls.
// Default is false.
// labelOutlineColor - {String} The color of the label outline. Default is 'white'. Only supported by the canvas & SVG renderers.
// labelOutlineWidth - {Number} The width of the label outline. Default is 3, set to 0 or null to disable. Only supported by the canvas & SVG renderers.
// fontColor - {String} The font color for the label, to be provided like CSS.
// fontOpacity - {Number} Opacity (0-1) for the label
// fontFamily - {String} The font family for the label, to be provided like in CSS.
// fontSize - {String} The font size for the label, to be provided like in CSS.
// fontStyle - {String} The font style for the label, to be provided like in CSS.
// fontWeight - {String} The font weight for the label, to be provided like in CSS.
var labelProps = {
label: "${" + config.labels + "}",
labelSelect: true,
labelAlign: "lt",
labelXOffset: "5",
fontColor: "#000000",
fontFamily: "Arial,Helvetica,sans-serif",
fontWeight: "bold",
fontSize: "11px",
labelOutlineColor: "white",
labelOutlineWidth: 5
};
if (config.labels == 'name') {
labelProps.labels = "${" + config.labels + "}";
} else {
// KML labels can also come from the extended attributes
// we need a context plus function then:
// http://gis-lab.info/share/DR/sandbox/kml-markers.html
labelProps.label = "${getLabel}";
labelProps.context = {};
labelProps.context.getLabel = function (f) {
var lbl = '';
if (f.attributes[config.labels]) {
lbl = f.attributes[config.labels].value;
}
return lbl;
};
}
OpenLayers.Util.applyDefaults(style, labelProps);
styleOptions = {
context: labelProps.context
};
}
if (config.styleOptions) {
OpenLayers.Util.extend(styleOptions, config.styleOptions);
}
var defaultStyle = new OpenLayers.Style(style, styleOptions);
var selectStyle = {
externalGraphic: '/basisviewer2/img/marker.png',
cursor: 'pointer',
graphicTitle: " ${name} ",
graphicWidth: 36,
graphicHeight: 48,
graphicXOffset: -12,
graphicYOffset: -46,
strokeColor: '#88179F',
strokeOpacity: 0.8,
strokeWidth: 6,
strokeDashstyle: 'solid' // solid | dot | dash | dashdot | longdash | longdashdot | solid
};
var styleMap = new OpenLayers.StyleMap(OpenLayers.Feature.Vector.style);
OpenLayers.Util.extend(styleMap.styles.default, defaultStyle);
OpenLayers.Util.extend(styleMap.styles.select, selectStyle);
// if user has overridden one of the style props, include here
/*
if (Geogem.Settings.kmlLayer && Geogem.Settings.kmlLayer.defaultStyle){
styleMap = OpenLayers.Util.applyDefaults(Geogem.Settings.kmlLayer.defaultStyle, styleMap.styles['default']);
}
if (Geogem.Settings.kmlLayer && Geogem.Settings.kmlLayer.selectStyle){
OpenLayers.Util.extend(styleMap.styles['select'], Geogem.Settings.kmlLayer.selectStyle);
}*/
var options = {
styleMap: styleMap,
projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP(kmlProtocolOptions)
};
OpenLayers.Util.extend(options, config.options);
var kml = new OpenLayers.Layer.Vector(config.title, options);
// sld based styling
if (config.sld) {
OpenLayers.Request.GET({
url: config.sld,
async: false,
success: function (req) {
var format = new OpenLayers.Format.SLD();
var sld = format.read(req.responseXML || req.responseText);
for (var l in sld.namedLayers) {
var styles = sld.namedLayers[l].userStyles,
style;
for (var i = 0, ii = styles.length; i < ii; ++i) {
style = styles[i];
//if (style.isDefault) {
//kml.styleMap.styles["default"] = style;
//OpenLayers.Util.extend(kml.styleMap.styles["default"], style);
OpenLayers.Util.extend(style, kml.styleMap.styles["default"]);
break;
//}
}
}
},
failure: function (req) {
alert("Fout bij het ophalen van het style bestand (sld): '" + config.sld + "'");
}
});
}
// if the kml style is NOT parsed there is no tooltip,
// so here we add tooltip when adding the features
kml.events.on({
"featureadded": function (evt) {
var tt = ' ' + evt.feature.attributes.name + ' ';
if (evt.feature && evt.feature.style) {
evt.feature.style.title = tt;
evt.feature.style.graphicTitle = tt;
}
}
});
// always select control for KML layer?
if (config.infopopup === undefined || config.infopopup === true) {
//if (true) {
Geogem.selectControl = new OpenLayers.Control.SelectFeature(
kml, {
clickout: true,
multiple: false,
hover: false,
displayClass: 'olControlNavigation'
});
kml.events.on({
'featureselected': Geogem.onFeatureSelect,
'featureunselected': Geogem.onFeatureUnselect
});
// without this two lines, we cannot pan a map with a overlay filled with polygons:
Geogem.selectControl.handlers.feature.stopDown = false;
Geogem.selectControl.handlers.feature.stopUp = false;
Geogem.map.addControl(Geogem.selectControl);
Geogem.selectControl.activate();
}
return kml;
};
Geogem.createWfsLayer = function (config) {
// to be overridden in settings
var wfsProtocolOptions = {
version: '1.1.0',
srsName: 'EPSG:28992',
url: '',
featureType: '',
featurePrefix: '',
featureNS: ''
//,geometryName: 'geom'
};
OpenLayers.Util.extend(wfsProtocolOptions, config.protocolOptions);
// defining default and select styles for WFS layers
var style = {
externalGraphic: '/basisviewer2/img/marker.png',
cursor: 'pointer',
graphicTitle: " ${name} ",
graphicWidth: 24,
graphicHeight: 32,
graphicXOffset: -9,
graphicYOffset: -30,
strokeColor: '#88179F',
strokeOpacity: 0.6,
strokeWidth: 4,
strokeDashstyle: 'solid', // solid | dot | dash | dashdot | longdash | longdashdot | solid
labelOutlineWidth: 3
};
if (config.style) {
OpenLayers.Util.extend(style, config.style);
}
var styleOptions = {};
// if there is a label config
if (config.labels) {
// label - {String} The text for an optional label. For browsers that use the canvas renderer, this requires either
// fillText or mozDrawText to be available.
// labelAlign - {String} Label alignment. This specifies the insertion point relative to the text. It is a string
// composed of two characters. The first character is for the horizontal alignment, the second for the vertical
// alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for vertical
// alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb". Default is "cm".
// labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer.
// labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer.
// labelSelect - {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls.
// Default is false.
// labelOutlineColor - {String} The color of the label outline. Default is 'white'. Only supported by the canvas & SVG renderers.
// labelOutlineWidth - {Number} The width of the label outline. Default is 3, set to 0 or null to disable. Only supported by the canvas & SVG renderers.
// fontColor - {String} The font color for the label, to be provided like CSS.
// fontOpacity - {Number} Opacity (0-1) for the label
// fontFamily - {String} The font family for the label, to be provided like in CSS.
// fontSize - {String} The font size for the label, to be provided like in CSS.
// fontStyle - {String} The font style for the label, to be provided like in CSS.
// fontWeight - {String} The font weight for the label, to be provided like in CSS.
var labelProps = {
label: "${" + config.labels + "}",
labelSelect: true,
labelAlign: "lt",
labelXOffset: "5",
fontColor: "#000000",
fontFamily: "Arial,Helvetica,sans-serif",
fontWeight: "bold",
fontSize: "11px",
labelOutlineColor: "white",
labelOutlineWidth: 5
};
if (config.labels == 'name') {
labelProps.labels = "${" + config.labels + "}";
} else {
// KML labels can also come from the extended attributes
// we need a context plus function then:
// http://gis-lab.info/share/DR/sandbox/kml-markers.html
labelProps.label = "${getLabel}";
labelProps.context = {};
labelProps.context.getLabel = function (f) {
var lbl = '';
if (f.attributes[config.labels]) {
lbl = f.attributes[config.labels].value;
}
return lbl;
};
}
OpenLayers.Util.applyDefaults(style, labelProps);
styleOptions = {
context: labelProps.context
};
}
if (config.styleOptions) {
OpenLayers.Util.extend(styleOptions, config.styleOptions);
}
var defaultStyle = new OpenLayers.Style(style, styleOptions);
var selectStyle = {
externalGraphic: '/basisviewer2/img/marker.png',
cursor: 'pointer',
graphicTitle: " ${name} ",
graphicWidth: 36,
graphicHeight: 48,
graphicXOffset: -12,
graphicYOffset: -46,
strokeColor: '#88179F',
strokeOpacity: 0.8,
strokeWidth: 6,
strokeDashstyle: 'solid' // solid | dot | dash | dashdot | longdash | longdashdot | solid
};
var styleMap = new OpenLayers.StyleMap(OpenLayers.Feature.Vector.style);
OpenLayers.Util.extend(styleMap.styles.default, defaultStyle);
OpenLayers.Util.extend(styleMap.styles.select, selectStyle);
// if user has overridden one of the style props, include here
/*
if (Geogem.Settings.kmlLayer && Geogem.Settings.kmlLayer.defaultStyle){
styleMap = OpenLayers.Util.applyDefaults(Geogem.Settings.kmlLayer.defaultStyle, styleMap.styles['default']);
}
if (Geogem.Settings.kmlLayer && Geogem.Settings.kmlLayer.selectStyle){
OpenLayers.Util.extend(styleMap.styles['select'], Geogem.Settings.kmlLayer.selectStyle);
}*/
var options = {
styleMap: styleMap,
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.WFS(wfsProtocolOptions)
};
OpenLayers.Util.extend(options, config.options);
var wfs = new OpenLayers.Layer.Vector(config.title, options);
// sld based styling
if (config.sld) {
OpenLayers.Request.GET({
url: config.sld,
async: false,
success: function (req) {
var format = new OpenLayers.Format.SLD();
var sld = format.read(req.responseXML || req.responseText);
for (var l in sld.namedLayers) {
var styles = sld.namedLayers[l].userStyles,
style;
for (var i = 0, ii = styles.length; i < ii; ++i) {
style = styles[i];
//if (style.isDefault) {
//kml.styleMap.styles["default"] = style;
//OpenLayers.Util.extend(kml.styleMap.styles["default"], style);
OpenLayers.Util.extend(style, wfs.styleMap.styles["default"]);
break;
//}
}
}
},
failure: function (req) {
alert("Fout bij het ophalen van het style bestand (sld): '" + config.sld + "'");
}
});
}
// if the kml style is NOT parsed there is no tooltip,
// so here we add tooltip when adding the features
wfs.events.on({
"featureadded": function (evt) {
var tt = ' ' + evt.feature.attributes.name + ' ';
if (evt.feature && evt.feature.style) {
evt.feature.style.title = tt;
evt.feature.style.graphicTitle = tt;
}
}
});
// always select control for KML layer
Geogem.selectControl = new OpenLayers.Control.SelectFeature(
wfs, {
clickout: true,
multiple: false,
hover: false,
displayClass: 'olControlNavigation'
});
wfs.events.on({
'featureselected': Geogem.onFeatureSelect,
'featureunselected': Geogem.onFeatureUnselect
});
// without this two lines, we cannot pan a map with a overlay filled with polygons:
Geogem.selectControl.handlers.feature.stopDown = false;
Geogem.selectControl.handlers.feature.stopUp = false;
Geogem.map.addControl(Geogem.selectControl);
Geogem.selectControl.activate();
return wfs;
};
Geogem.findWMSLayer = function (layername, vis) {
var layers = Geogem.map.layers;
var layer;
for (var i = 0; i < layers.length; i++)
if (layers[i].params && layers[i].params.LAYERS) {
{
if (vis === true) {if (layers[i].visibility === false) {continue;}}
// layers[i].params.LAYERS can be a list (layer1,layer2,layer3)
var layersparam = layers[i].params.LAYERS.split(',');
if ($.inArray(layername, layersparam) >= 0) {
//if (layers[i].params.LAYERS==layersParam){
layer = layers[i];
break;
}
}
}
if (!layer) {
//alert('Configuratie fout. Laagnaam niet gevonden. Workspace?');
}
return layer;
};
Geogem.createWMSLayer = function (config) {
var params = {
transparent: 'true',
format: 'image/png'
};
OpenLayers.Util.extend(params, config.params);
var options = {
isBaseLayer: false,
hover: false // defaulting to NO hover on getfeatureinfo
};
OpenLayers.Util.extend(options, config.options);
var lyr = new OpenLayers.Layer.WMS(
config.title,
config.url,
params,
options
);
lyr.params.LAYERS = lyr.params.LAYERS.trim();
// setting attribuut mapping fields in layer object as 'geomgemfields'
if (config.fields) {
lyr.geogemfields = config.fields; // fields can be fields of several layers
}
if (config.wmsinfoformat /*&& config.wmsinfoformat != 'none'*/ ) {
//var infoformat = 'text/html';//layerConfigObj.wmsinfoformat; // text/plain, application/vnd.ogc.gml, application/vnd.ogc.gml/3.1.1, text/html
var infoformat = config.wmsinfoformat;
var popupContent = '';
if (this.map.infoControl) {
this.map.infoControl.layers.push(lyr);
} else {
var info = new OpenLayers.Control.WMSGetFeatureInfo({
url: config.url,
infoFormat: infoformat,
hover: options.hover,
title: 'Info voor ' + config.title,
layers: [lyr],
queryVisible: true,
eventListeners: {
beforegetfeatureinfo: function () {
// cleanup popups OR sidebar content
$('#sidebar_content').html('');
while (this.map.popups.length) {
this.map.removePopup(this.map.popups[0]);