-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.js
1634 lines (1560 loc) · 77.3 KB
/
map.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
/*jslint browser: true, for: true, long: true, unordered: true, nomen: true */
/*global window console google */
/**
* Op zoek naar de website?
* Bezoek https://basgroot.github.io/bekendmakingen/?in=Hoorn
*
* This function is called by Google Maps API, after loading the library. Function name is sent as query parameter.
* @return {void}
*/
async function initMap() {
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
const appState = {
// The map itself:
"map": null,
// Periods
"periods": null,
// Municipalities
"municipalities": null,
// The selected (or initial) municipality:
"activeMunicipality": "Hoorn",
// The zoom level when starting the app:
"initialZoomLevel": 16,
// The marker objects of the municipalities:
"municipalityMarkers": [],
// Te list with markers on the map:
"markersArray": [],
// The markers outside the screen, to be shown after becoming visible (scroll):
"delayedMarkersArray": [],
// The publications to display:
"publicationsArray": [],
// Backup of the recent publications, because loading them again is slow:
"publicationsArrayBackup": [],
// Indicates the status of the time filter:
"isHistoryActive": false,
// Indicates if all parts are loaded:
"isFullyLoaded": false,
// Order of different license markers, newest on top. Set to some high number:
"zIndex": 2147483647,
// Wait custor when loading data:
"loadingIndicator": document.createElement("img"),
// The info window shown when clicking on a marker:
"infoWindow": null,
// Start date of the query and indication if history must be retrieved:
"requestPeriod": {}
};
/**
* Customize the map based on query parameters.
* Examples:
* ?in=Hoorn&zoom=15¢er=52.6603118963%2C5.0608995325
* ?in=Oostzaan
* @return {!Object} Map settings.
*/
function getInitialMapSettings() {
let zoomLevel = appState.initialZoomLevel;
let center = Object.assign({}, appState.municipalities[appState.activeMunicipality].center); // Create new copy
let lat;
let lng;
if (window.URLSearchParams) {
const urlSearchParams = new window.URLSearchParams(window.location.search);
let zoomParam = urlSearchParams.get("zoom");
let centerParam = urlSearchParams.get("center");
const municipalityParam = urlSearchParams.get("in");
if (municipalityParam && appState.municipalities[municipalityParam] !== undefined) {
appState.activeMunicipality = municipalityParam;
console.log("Adjusted municipality from URL: " + municipalityParam);
}
center = Object.assign({}, appState.municipalities[appState.activeMunicipality].center);
if (zoomParam && centerParam) {
zoomParam = parseFloat(zoomParam);
if (zoomParam > 14 && zoomParam < 20) {
zoomLevel = zoomParam;
console.log("Adjusted zoom level from URL: " + zoomParam);
}
centerParam = centerParam.split(",");
lat = parseFloat(centerParam[0]);
lng = parseFloat(centerParam[1]);
if (Number.isFinite(lat) && Number.isFinite(lng)) {
center.lat = lat;
center.lng = lng;
console.log("Adjusted center from URL");
}
}
updateUrl(zoomLevel, new google.maps.LatLng(center.lat, center.lng));
}
return {
"zoomLevel": zoomLevel,
"center": center
};
}
/**
* Display the popup window.
* https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow.open
* @param {!Object} marker Marker showing the popup.
* @param {string} iconName Icon file name.
* @param {string} header Title.
* @param {string} body Contents.
* @return {void}
*/
function showInfoWindow(marker, iconName, header, body) {
let map;
appState.infoWindow.setContent("<div><img src=\"img/" + iconName + ".svg\" width=\"105\" height=\"135\" class=\"info_window_image\"><h2 class=\"info_window_heading\">" + header + "</h2><div class=\"info_window_body\"><p>" + body + "</p></div></div>");
if (appState.map.getStreetView().getVisible()) {
console.log("Streetview is visible. Showing infoWindow there.");
map = appState.map.getStreetView();
} else {
map = appState.map;
}
appState.infoWindow.open({
"anchor": marker,
"map": map,
"shouldFocus": true
});
appState.infoWindow.setMap(map); // Workaround for issue with infoWindow not showing in Street View: https://issuetracker.google.com/issues/35828818?pli=1
}
/**
* Parse the response of the license document to find the date the license is granted.
* @param {string} responseXml XML.
* @return {!Array<?>|!NodeList<!Element>} Alineas.
*/
function getAlineas(responseXml) {
/**
* Replaces tags in the given value.
* @param {string} value The value to replace tags in.
* @return {string} The value with tags replaced.
*/
function replaceTags(value) {
const tags = [
["<extref doc=\"https://www.alkmaar.nl/bestuur-en-organisatie/het-ergens-niet-mee-eens-zijn/bezwaar-en-beroep\">website</extref>", "website"], // Alkmaar https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-77888/1/xml/gmb-2023-77888.xml
["<extref doc=\"https://www.alkmaar.nl/direct-regelen/wonen-verhuizen-en-verbouwen/bezwaar-en-beroep\">website</extref>", "website"], // Alkmaar https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-23049/1/xml/gmb-2023-23049.xml
["<!--Element br verwijderd -->", ""], // Zaanstad https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-77748/1/xml/gmb-2023-77748.xml
["<nadruk type=\"vet\">", ""], // Hoorn https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-74922/1/xml/gmb-2023-74922.xml
["<nadruk type=\"cur\">", ""], // Hoorn https://repository.overheid.nl/frbr/officielepublicaties/gmb/2022/gmb-2022-577976/1/xml/gmb-2022-577976.xml
["<nadruk type=\"ondlijn\">", ""], // Hoorn https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-32648/1/xml/gmb-2023-32648.xml
["</nadruk>", ""], // Hoorn
[" :", ":"] // Den Helder https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-81009/1/xml/gmb-2023-81009.xml
];
let result = value;
// Remove all double spaces in all forms: Landsmeer https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-74508/1/xml/gmb-2023-74508.xml
result = result.replace(/\s\s+/g, " ");
tags.forEach(function (tag) {
result = result.replaceAll(tag[0], tag[1]);
});
return result;
}
const parser = new window.DOMParser();
let xmlDoc;
let zakelijkeMededeling;
try {
xmlDoc = parser.parseFromString(replaceTags(responseXml).toLowerCase(), "text/xml");
} catch (e) {
console.error("Error parsing " + responseXml);
console.error(e);
return [];
}
// gemeenteblad / zakelijke-mededeling / zakelijke-mededeling-tekst / tekst / <al>Verzonden naar aanvrager op: 20-09-2022</al>
zakelijkeMededeling = xmlDoc.getElementsByTagName("zakelijke-mededeling-tekst");
return (
zakelijkeMededeling.length === 0
? []
: zakelijkeMededeling[0].querySelectorAll("al,tussenkop") // Tussenkop is required for Den Haag https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-78971/1/xml/gmb-2023-78971.xml
);
}
/**
* Calculate the period since the license was granted, to see if it is applicable for formal objection.
* @param {!Date} date Decision date.
* @return {number} Number of days passed.
*/
function getDaysPassed(date) {
const today = new Date(new Date().toDateString()); // Rounded date
const dateFrom = new Date(date.toDateString());
return Math.round((today.getTime() - dateFrom.getTime()) / (1000 * 60 * 60 * 24));
}
/**
* Parse the response of the license document to find the date the license is granted.
* @param {string} responseXml XML response.
* @param {!Object} publication Publication object.
* @param {string} licenseId License ID.
* @return {void}
*/
function parseBekendmaking(responseXml, publication, licenseId) {
/**
* Converts month names to their corresponding numeric values.
* @param {string} value The month name to convert.
* @return {string} The numeric value of the month.
*/
function convertMonthNames(value) {
return value.replace("januari", "01").replace("februari", "02").replace("maart", "03").replace("april", "04").replace("mei", "05").replace("juni", "06").replace("juli", "07").replace("augustus", "08").replace("september", "09").replace("oktober", "10").replace("november", "11").replace("december", "12");
}
/**
* Parses a date value.
* @param {string} value The date value to parse.
* @return {!Object} Object with parsed date, if valid.
*/
function parseDate(value) {
const result = {
"isValid": false
};
const year = value.substring(6, 10);
const month = value.substring(3, 5);
const day = value.substring(0, 2);
let datumBekendgemaakt;
if (Number.isNaN(parseInt(year, 10)) || Number.isNaN(parseInt(month, 10)) || Number.isNaN(parseInt(day, 10))) {
console.error("Error parsing date (" + value + ") of license " + publication.urlApi);
return result;
}
datumBekendgemaakt = new Date(year + "-" + month + "-" + day);
result.date = new Date(datumBekendgemaakt.toDateString()); // Rounded date
result.isValid = true;
return result;
}
/**
* Retrieves the date from the given text value.
* @param {string} value The text value to extract the date from.
* @param {!Object} publication The publication source.
* @return {!Object} Object with parsed date, if valid.
*/
function getDateFromText(value, publication) {
const identifier = "@@@";
const identifiersStart = [
"verzonden naar aanvrager op: ",
"de gemeente heeft op ",
"de gemeente opmeer heeft op ", // Opmeer https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-79622/1/xml/gmb-2023-79622.xml
"besluit verzonden: ", // Zaandam https://repository.overheid.nl/frbr/officielepublicaties/gmb/2022/gmb-2022-580371/1/xml/gmb-2022-580371.xml
"besluitdatum: ", // Landsmeer https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-74508/1/xml/gmb-2023-74508.xml
"gemeente amstelveen heeft op ", // Amstelveen https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-95322/1/xml/gmb-2023-95322.xml
"verzonden op: ", // Dijk en Waard https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-85385/1/xml/gmb-2023-85385.xml
"(verzonden ", // Waterland https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-67428/1/xml/gmb-2023-67428.xml
"verzonden ", // Hoorn https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-86314/1/xml/gmb-2023-86314.xml
"verleende omgevingsvergunning is verzonden op ", // Hoorn https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-84721/1/xml/gmb-2023-84721.xml
"verleende omgevingsvergunning is verzonden ", // Hoorn https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-29091/1/xml/gmb-2023-29091.xml
"verzenddatum besluit: ", // Koggenland https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-68991/1/xml/gmb-2023-68991.xml
"verzenddatum: ", // Den Helder https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-2603/1/xml/gmb-2023-2603.xml
"verzendatum: ", // Den Helder https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-59281/1/xml/gmb-2023-59281.xml
"bekendmakingsdatum: ", // Heemskerk https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-67866/1/xml/gmb-2023-67866.xml
"datum besluit: ", // Edam-Volendam https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-74723/1/xml/gmb-2023-74723.xml
"datum verzending besluit: ", // Almere https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-31954/1/xml/gmb-2023-31954.xml
"de burgemeester van den helder maakt bekend, dat hij op " // Den Helder https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-20399/1/xml/gmb-2023-20399.xml
];
const identifiersStartWithObjectionStart = [
"de termijn voor het indienen van een bezwaar start op " // Gouda https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-37420/1/xml/gmb-2023-37420.xml
];
const identifiersWithDeadline = [
"als u het niet eens bent met dit besluit dan kunt u binnen zes weken na de verzenddatum bezwaar maken. op onze website kunt u lezen hoe u online of per post uw bezwaar kunt indienen. uw bezwaarschrift moet vóór ", // Alkmaar
"u kunt het college van de gemeente heemstede tot en met ", // Heemstede https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-77700/1/xml/gmb-2023-77700.xml
"u kunt de gemeente tot " // Dijk en Waard https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-76678/1/xml/gmb-2023-76678.xml
];
const identifiersMiddle = [
" het besluit is verzonden op ", // Bloemendaal https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-94061/1/xml/gmb-2023-94061.xml
" (verzonden ", // Texel
", verzonden ", // Haarlem https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-31494/1/xml/gmb-2023-31494.xml
", verzenddatum ", // Bergen NH https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-76348/1/xml/gmb-2023-76348.xml
" (verzenddatum ", // Groningen https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-79536/1/xml/gmb-2023-79536.xml
", verleend op ", // Beverwijk https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-81123/1/xml/gmb-2023-81123.xml
" (datum besluit ", // Rotterdam https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-92486/1/xml/gmb-2023-92486.xml
"de termijn voor het indienen van een bezwaarschrift start op " // Aalsmeer https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-63996/1/xml/gmb-2023-63996.xml
];
const identifiersAfter = [
" is een omgevingsvergunning verleend" // Noordoostpolder https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-93843/1/xml/gmb-2023-93843.xml
];
const identifierNextValueIsDate = "datum bekendmaking besluit:"; // Den Haag https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-79557/1/xml/gmb-2023-79557.xml
let i;
let pos;
let isDateOfDeadline = false;
let isObjectionStartDate = false;
let result;
if (value === identifierNextValueIsDate) {
isNextValueBekendmakingsDate = true;
} else {
value = convertMonthNames(value);
if (isNextValueBekendmakingsDate === true) {
value = identifier + value;
}
isNextValueBekendmakingsDate = false;
}
// If not found, try the regular way of publishing:
if (value.substring(0, identifier.length) !== identifier) {
for (i = 0; i < identifiersStart.length; i += 1) {
if (value.substring(0, identifiersStart[i].length) === identifiersStart[i]) {
value = value.replace(identifiersStart[i], identifier);
break;
}
}
}
// If not found, try the regular way of publishing objection start date:
if (value.substring(0, identifier.length) !== identifier) {
for (i = 0; i < identifiersStartWithObjectionStart.length; i += 1) {
pos = value.indexOf(identifiersStartWithObjectionStart[i]);
if (pos !== -1) {
value = identifier + value.substring(pos + identifiersStartWithObjectionStart[i].length);
isObjectionStartDate = true;
break;
}
}
}
// If not found, try the Noordoostpolder way of publishing:
if (value.substring(0, identifier.length) !== identifier) {
for (i = 0; i < identifiersAfter.length; i += 1) {
// Noordoostpolder has this in the title: https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-93843/1/xml/gmb-2023-93843.xml
pos = value.indexOf(identifiersAfter[i]);
if (pos !== -1) {
value = identifier + value.substring(pos - 10, pos);
break;
}
}
}
// If not found, try the Alkmaar way of publishing:
if (value.substring(0, identifier.length) !== identifier) {
for (i = 0; i < identifiersWithDeadline.length; i += 1) {
if (value.substring(0, identifiersWithDeadline[i].length) === identifiersWithDeadline[i]) {
value = value.replace(identifiersWithDeadline[i], identifier);
isDateOfDeadline = true;
break;
}
}
}
// If not found, try the Texel way of publishing:
if (value.substring(0, identifier.length) !== identifier) {
// Velsen repeats part of title (Zeeweg 343, interne constructiewijziging (07/02/2022) 143528-2022):
identifiersMiddle.push(publication.title.substring(publication.title.length - 4).toLowerCase() + " ("); // Velsen https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-69953/1/xml/gmb-2023-69953.xml
for (i = 0; i < identifiersMiddle.length; i += 1) {
// Bergen, Castricum etc. have this in the title: https://repository.overheid.nl/frbr/officielepublicaties/gmb/2023/gmb-2023-76348/1/xml/gmb-2023-76348.xml
pos = publication.title.indexOf(identifiersMiddle[i]);
if (pos !== -1) {
// Haarlem: ...activiteit handelen in strijd met regels ruimtelijke ordening, verzonden 16 januari 2023
value = identifier + convertMonthNames(publication.title.substring(pos + identifiersMiddle[i].length));
break;
}
pos = value.indexOf(identifiersMiddle[i]);
if (pos !== -1) {
value = identifier + value.substring(pos + identifiersMiddle[i].length);
break;
}
}
}
if (value.substring(0, identifier.length) === identifier) {
value = value.substring(identifier.length);
if (value.substring(1, 2) === " " || value.substring(1, 2) === "-") {
value = "0" + value;
}
// Remove time from dates:
result = parseDate(value);
if (result.isValid) {
if (isDateOfDeadline) {
// This is the last date you can object to a decision. Extract 6 weeks.
result.date.setDate(result.date.getDate() - (7 * 6));
} else if (isObjectionStartDate) {
result.date.setDate(result.date.getDate() - 1); // Objection period starts one day after date 'verzonden'
}
return result;
}
}
return {
"isValid": false
};
}
const alineas = getAlineas(responseXml);
const maxLooptijd = (6 * 7) + 1; // 6 weken de tijd om bezwaar te maken
const dateFormatOptions = {"weekday": "long", "year": "numeric", "month": "long", "day": "numeric"};
let datumBekendgemaakt; // Datum verzonden aan belanghebbende(n)
let looptijd;
let resterendAantalDagenBezwaartermijn;
let i;
let j;
let alinea;
let textToShow = "";
let isNextValueBekendmakingsDate = false;
let isBezwaartermijnFound = false;
for (i = 0; i < alineas.length; i += 1) {
alinea = alineas[i];
if (alinea.childNodes.length > 0) {
for (j = 0; j < alinea.childNodes.length; j += 1) {
if (alinea.childNodes[j].nodeName === "#text") {
datumBekendgemaakt = getDateFromText(alinea.childNodes[j].nodeValue.trim(), publication);
if (datumBekendgemaakt.isValid) {
isBezwaartermijnFound = true;
looptijd = getDaysPassed(datumBekendgemaakt.date);
resterendAantalDagenBezwaartermijn = maxLooptijd - looptijd;
textToShow = "Gepubliceerd: " + publication.date.toLocaleDateString("nl-NL", dateFormatOptions) + ".<br />Bekendgemaakt aan belanghebbende: " + datumBekendgemaakt.date.toLocaleDateString("nl-NL", dateFormatOptions) + ".<br />" + (
resterendAantalDagenBezwaartermijn > 0
? "Resterend aantal dagen voor bezwaar: " + resterendAantalDagenBezwaartermijn + "."
: "<b>Geen bezwaar meer mogelijk.</b>"
) + "<br /><br />";
}
break;
}
}
}
}
if (!isBezwaartermijnFound) {
textToShow = "Gepubliceerd: " + publication.date.toLocaleDateString("nl-NL", dateFormatOptions) + ".<br /><br />";
}
document.getElementById(licenseId).innerHTML = textToShow;
}
/**
* Call the government API for a specific license, to get more details. This is done to get the date the license is granted.
* @param {string} licenseId License ID.
* @param {!Object} publication Publication object.
* @return {void}
*/
function collectBezwaartermijn(licenseId, publication) {
if (publication.urlApi === "UNAVAILABLE") {
console.error("Unable to get data for license " + publication.urlDoc);
return;
}
// Endpoint: https://repository.overheid.nl/frbr/officielepublicaties/gmb/2022/gmb-2022-425209/1/xml/gmb-2022-425209.xml
fetch(
publication.urlApi,
{
"method": "GET"
}
).then(function (response) {
if (response.ok) {
response.text().then(function (xml) {
parseBekendmaking(xml, publication, licenseId);
});
} else {
console.error(response);
}
}).catch(function (error) {
console.error(error);
});
}
/**
* Create the option of a drop down element. This is used for the municipality drop down and the period drop down.
* @param {string} value Key.
* @param {string} displayValue Value.
* @param {boolean} isSelected Selected or not?
* @return {!HTMLOptionElement} Option element.
*/
function createOption(value, displayValue, isSelected) {
const option = document.createElement("option");
option.text = displayValue;
option.value = value;
if (isSelected) {
option.setAttribute("selected", true);
}
return option;
}
/**
* Create the spinner shown when retrieving all licenses. This is shown in the center right.
* @return {void}
*/
function createMapsControlLoadingIndicator() {
const controlDiv = document.createElement("div"); // Create a DIV to attach the control UI to the Map.
controlDiv.appendChild(appState.loadingIndicator);
appState.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push(controlDiv);
}
/**
* Create the drop down with all municipalities of The Netherlands.
* @return {void}
*/
function createMapsControlMunicipalities() {
/**
* Creates an option element with the specified value. The active municipality is selected by default.
* @param {string} value The value of the option.
* @return {!HTMLOptionElement} The created option element.
*/
function createOptionEx(value) {
return createOption(value, value, value === appState.activeMunicipality);
}
const controlDiv = document.createElement("div"); // Create a DIV to attach the control UI to the Map.
const combobox = document.createElement("select");
const municipalityNames = Object.keys(appState.municipalities);
combobox.id = "idCbxMunicipality";
combobox.title = "Gemeente selecteren";
municipalityNames.forEach(function (municipalityName) {
combobox.add(createOptionEx(municipalityName));
});
combobox.addEventListener("change", function () {
loadData(true);
});
combobox.classList.add("controlStyle");
controlDiv.appendChild(combobox);
appState.map.controls[google.maps.ControlPosition.TOP_CENTER].push(controlDiv);
}
/**
* Create the drop down with time filter. This is shown in the bottom center.
* @return {void}
*/
function createMapsControlPeriods() {
/**
* Creates an option element with the specified value. Period 14d is selected by default.
* @param {string} value The value of the option.
* @param {string} displayValue The value of the option to display.
* @return {!HTMLOptionElement} The created option element.
*/
function createOptionEx(value, displayValue) {
return createOption(value, displayValue, value === "14d");
}
const controlDiv = document.createElement("div"); // Create a DIV to attach the control UI to the Map.
const combobox = document.createElement("select");
combobox.id = "idCbxPeriod";
combobox.title = "Periode van de bekendmaking selecteren";
appState.periods.forEach(function (period) {
combobox.add(createOptionEx(period.key, period.val));
});
combobox.addEventListener("change", updatePeriodFilter);
combobox.classList.add("controlStyle");
controlDiv.appendChild(combobox);
appState.map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(controlDiv);
}
/**
* Create the button linking to this source code. This is shown in the bottom left.
* @return {void}
*/
function createMapsControlSource() {
const controlDiv = document.createElement("div"); // Create a DIV to attach the control UI to the Map.
const button = document.createElement("button");
button.id = "idBtnSource";
button.textContent = "Broncode";
button.title = "Source op GitHub bekijken";
button.type = "button";
button.addEventListener("click", function () {
const url = "https://github.com/basgroot/bekendmakingen";
if (window.open(url) === null) {
// Popup blocker or something preventing a new tab
window.location.href = url;
}
});
button.classList.add("controlStyle");
controlDiv.appendChild(button);
appState.map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(controlDiv);
}
/**
* Create the elements on the map. This includes the loading indicator, the municipality drop down and the period drop down.
* https://developers.google.com/maps/documentation/javascript/examples/control-custom
* @return {void}
*/
function createMapsControls() {
createMapsControlLoadingIndicator();
createMapsControlMunicipalities();
createMapsControlPeriods();
createMapsControlSource();
}
/**
* Parse the license ID. This is the last part of the URL.
* Options: https://zoek.officielebekendmakingen.nl/prb-2023-962.html
* https://zoek.officielebekendmakingen.nl/gmb-2023-56454.html
* https://zoek.officielebekendmakingen.nl/wsb-2023-801.html
* https://zoek.officielebekendmakingen.nl/stcrt-2023-128.html
* @param {string} websiteUrl Link to document.
* @return {string|boolean} License ID or false.
*/
function getLicenseIdFromUrl(websiteUrl) {
const startOfUrl = "https://zoek.officielebekendmakingen.nl/";
const endOfUrl = ".html";
if (websiteUrl.startsWith(startOfUrl)) {
return websiteUrl.substring(startOfUrl.length, websiteUrl.length - endOfUrl.length);
}
return false;
}
/**
* Choose what image to use for a license type.
* Text mining to get distinguish the different license states and types
* Images are converted to SVG using https://png2svg.com/
* Resized to 35x45 using https://www.iloveimg.com/resize-image/resize-svg#resize-options,pixels
* Optmized using https://svgoptimizer.com/
* @param {string} title Name of permit.
* @param {string} type Permit type.
* @return {string} Icon file name without extension.
*/
function getIconName(title, type) {
const exploitatievergunningen = [
"drank- en horecavergunning",
"exploitatievergunning",
"gebruiksvergunning",
"kansspelvergunning",
"openingstijden"
];
const evenementenvergunningen = [
"collectevergunning",
"evenementenvergunning",
"vuurwerkvergunning"
];
const onttrekkingsvergunningen = [
"leegstandvergunning",
"onttrekkingsvergunning",
"splitsingsvergunning"
];
const watervergunningen = [
"aanlegvergunning",
"ligplaatsvergunning",
"watervergunning"
];
const milieuvergunningen = [
"bodembeschermingsvergunning",
"geluidvergunning",
"huisafval",
"milieu-informatie",
"milieueffectrapportage besluit",
"milieuvergunning",
"natuurbeschermingsvergunning"
];
const verkeersvergunningen = [
"apv vergunning",
"gehandicaptenparkeervergunning",
"in- en uitritvergunning",
"verkeersbesluit"
];
const bouwvergunningen = [
"bouwvergunning",
"monumentenvergunning",
"omgevingsvergunning",
"sloopvergunning"
];
title = title.toLowerCase();
if (title.indexOf("aanvraag") !== -1 || title.indexOf("verlenging") !== -1) {
return "aanvraag"; // Halfwitty, CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0, via Wikimedia Commons
}
if (exploitatievergunningen.indexOf(type) !== -1 || title.indexOf("exploitatievergunning") !== -1 || title.indexOf("alcoholwetvergunning") !== -1) {
return "bar";
}
if (evenementenvergunningen.indexOf(type) !== -1 || title.indexOf("evenement") !== -1) {
return "evenement";
// De 'loterij' met type 'overig' valt eruit!
}
if (title.indexOf("bed & breakfast") !== -1 || title.indexOf("vakantieverhuur") !== -1) {
return "hotel";
}
if (type === "kapvergunning" || title.indexOf("houtopstand") !== -1 || title.indexOf("(kap)") !== -1) {
return "boomkap";
}
if (title.indexOf("oplaadplaats") !== -1 || title.indexOf("opladen") !== -1 || title.indexOf("laadpaal") !== -1) {
return "laadpaal";
}
if (title.indexOf("apv vergunning") !== -1 || title.indexOf("parkeervakken") !== -1 || title.indexOf("tvm") !== -1) {
// Verify this after 'laadpaal':
return "tvm";
}
if (verkeersvergunningen.indexOf(type) !== -1) {
// Verify this after 'parkeervakken/tvm':
return "verkeer";
}
if (onttrekkingsvergunningen.indexOf(type) !== -1) {
return "kamerverhuur"; // EpicPupper, CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0, via Wikimedia Commons
}
if (watervergunningen.indexOf(type) !== -1) {
return "boot"; // Barbetorte, CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0, via Wikimedia Commons
}
if (type === "reclamevergunning") {
return "reclame"; // Verdy_p (complete construction and vectorisation, based on mathematical properties of the symbol, and not drawn manually, and then manually edited without using any SVG editor)., Public domain, via Wikimedia Commons
}
if (milieuvergunningen.indexOf(type) !== -1) {
return "milieu";
}
if (bouwvergunningen.indexOf(type) !== -1) {
return "constructie";
}
return "wetboek"; // By No machine-readable author provided. Chris-martin assumed (based on copyright claims). Own work assumed (based on copyright claims)., CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=1010176
// "aanwijzingsbesluit",
// "agenda en notulen",
// "bestemmingsplan",
// "inspraak",
// "mededelingen",
// "meldingen",
// "overig",
// "rectificatie",
// "register kinderopvang",
// "standplaatsvergunning",
// "verkiezingen",
// "verordeningen en reglementen",
}
/**
* When two licenses are on the same location, move the second, to see them both.
* @param {!Object} proposedCoordinate Coordinate to place marker.
* @return {!Object} Coordinate to place marker.
*/
function findUniquePosition(proposedCoordinate) {
/**
* Checks if a coordinate is available.
* @param {!Object} coordinate The coordinate to check.
* @return {boolean} True if the coordinate is available, false otherwise.
*/
function isCoordinateAvailable(coordinate) {
let isAvailable = true; // Be positive
let i;
let marker;
for (i = 0; i < appState.markersArray.length; i += 1) {
// Don't use forEach, to gain some performance.
marker = appState.markersArray[i];
if (marker.position.lat === coordinate.lat && marker.position.lng === coordinate.lng) {
isAvailable = false;
break;
}
}
return isAvailable;
}
const destinationCoordinate = {
"lat": proposedCoordinate.lat,
"lng": proposedCoordinate.lng
};
// The deviation from the original coordinate
const latShift = 0.000017;
const lngShift = 0.000016;
while (!isCoordinateAvailable(destinationCoordinate)) {
destinationCoordinate.lat = destinationCoordinate.lat + latShift;
destinationCoordinate.lng = destinationCoordinate.lng + lngShift;
}
return destinationCoordinate;
}
/**
* Set visibility of the markers, based on time filter.
* @param {number} age Days in the past.
* @param {string} periodToShow Selected period.
* @return {boolean} Is marker visible?
*/
function isMarkerVisible(age, periodToShow) {
switch (periodToShow) {
case "3d":
return age <= 3;
case "7d":
return age <= 7;
case "14d":
return age <= 14;
default:
return true;
}
}
/**
* Create a marker icon.
* @param {string} sourceUrl Link to marker image.
* @param {string=} label Optional label.
* @return {!HTMLDivElement} Marker node containing the image.
*/
function createMarkerIcon(sourceUrl, label) {
const iconContainer = document.createElement("div");
const icon = document.createElement("img");
icon.src = sourceUrl;
iconContainer.appendChild(icon);
if (label === undefined) {
return iconContainer;
}
iconContainer.classList.add("municipalityContainer");
const labelContainer = document.createElement("div");
labelContainer.classList.add("municipalityLabel");
labelContainer.innerText = label;
iconContainer.appendChild(labelContainer);
return iconContainer;
}
/**
* Add a marker to the map.
* @param {!Object} publication Publication object.
* @param {string} periodToShow Selected period.
* @param {!Object} position Coordinate.
* @return {!Object} Marker object. This is used to remove the marker later.
*/
function addMarker(publication, periodToShow, position) {
/**
* Handles the click event. Show the info window.
*/
function onClick() {
const description = publication.description + "<br /><br />Meer info: <a href=\"" + publication.urlDoc + "\" target=\"blank\">" + publication.urlDoc + "</a>.";
const licenseId = getLicenseIdFromUrl(publication.urlDoc);
// Supported is "Gemeentelijk blad (gmb)", "Provinciaal blad (prb)", "Waterschapsblad (wsb) and Staatscourant (stcrt)"
// Options: https://zoek.officielebekendmakingen.nl/prb-2023-962.html
// https://zoek.officielebekendmakingen.nl/gmb-2023-56454.html
// https://zoek.officielebekendmakingen.nl/wsb-2023-801.html
// https://zoek.officielebekendmakingen.nl/stcrt-2023-128.html
// Not supported:
// https://www.zaanstad.nl/mozard/!suite42.scherm1260?mObj=211278
// https://bekendmakingen.amsterdam.nl/bekendmakingen/overige/decos/C174AC3CD0754F9089D1553C31CD5B7A
if (licenseId === false) {
// Errors: https://www.zaanstad.nl/mozard/!suite42.scherm1260?mObj=211278
// https://bekendmakingen.amsterdam.nl/bekendmakingen/overige/decos/C174AC3CD0754F9089D1553C31CD5B7A
showInfoWindow(marker, iconName, publication.title, description);
} else {
showInfoWindow(marker, iconName, publication.title, "<div id=\"" + licenseId + "\"><br /><br /><br /></div>" + description);
collectBezwaartermijn(licenseId, publication);
}
}
/**
* Handles the hover event. Highlight the icon (and related icons) on hover.
*/
function onMouseOver() {
appState.markersArray.forEach(function (markerObject) {
if (markerObject.url === publication.urlDoc) {
markerObject.marker.content.getElementsByTagName("img")[0].src = "img/" + iconName + "-highlight.png";
}
});
}
/**
* Handles the mouse out event. Remove the highlight.
*/
function onMouseOut() {
appState.markersArray.forEach(function (markerObject) {
if (markerObject.url === publication.urlDoc) {
markerObject.marker.content.getElementsByTagName("img")[0].src = "img/" + iconName + ".png";
}
});
}
// 2022-09-05T09:04:57.175Z;
// https://zoek.officielebekendmakingen.nl/gmb-2022-396401.html;
// "Besluit apv vergunning Verleend Monnikendammerweg 27";
// "TVM- 7 PV reserveren - Monnikendammerweg 27-37 - 03-07/10/2022, Monnikendammerweg 27";
// 125171;
// 488983
// https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElementOptions
const age = getDaysPassed(publication.date);
const iconName = getIconName(publication.title, publication.type);
const marker = new AdvancedMarkerElement({
"map": (
isMarkerVisible(age, periodToShow)
? appState.map
: null
),
"position": position,
"content": createMarkerIcon("img/" + iconName + ".png"),
"zIndex": appState.zIndex,
"title": publication.title
});
const markerObject = {
"url": publication.urlDoc,
"age": age,
"position": position,
"isSvg": true,
"marker": marker
};
appState.zIndex -= 1; // Input is sorted by modification date - most recent first. Give them a higher zIndex, so Besluit is in front of Verlenging (which is in front of Aanvraag)
appState.markersArray.push(markerObject);
marker.addListener("click", onClick);
// Highlight the icon (and related icons) on hover
marker.content.addEventListener("mouseover", onMouseOver);
marker.content.addEventListener("mouseout", onMouseOut);
return markerObject;
}
/**
* If visible, create the marker. Otherwise move it to a list and show it when the map is scrolled.
* This reduces load in the browser.
* @param {!Object} publication Publication object.
* @param {string} periodToShow Selected period.
* @param {!Object} position Coordinate.
* @param {!Object} bounds Visible map.
* @return {void}
*/
function prepareToAddMarker(publication, periodToShow, position, bounds) {
if (bounds.contains(position)) {
addMarker(publication, periodToShow, position);
} else {
appState.delayedMarkersArray.push({
"publication": publication,
"position": position
});
}
}
/**
* Determine what time filter must be used.
* @return {!Object} Time filter.
*/
function getPeriodFilter() {
/**
* Checks if a value represents a historical period. Historical periods are notated like '2023-11'.
* @param {string} value The value to check.
* @return {boolean} Returns true if the value represents a historical period, otherwise returns false.
*/
function isHistoricalPeriod(value) {
// Values of historical periods are notated like '2023-03'
return value.length === 7 && value.substring(4, 5) === "-";
}
const result = {
"elm": document.getElementById("idCbxPeriod"),
"period": "14d",
"periodToShow": "14d",
"isHistory": false
};
if (result.elm === null) {
return result; // Default when loading
}
// If this is an historical period, default to 'all':
result.period = result.elm.value;
if (isHistoricalPeriod(result.elm.value)) {
result.periodToShow = "all";
result.isHistory = true;
} else {
result.periodToShow = result.elm.value;
}
return result;
}
/**
* Create (new) latitude/longitude object.
* @param {string} locatiepunt Latitude/longitude. Input example: "52.35933 4.893097".
* @return {!Object} Coordinate.
*/
function createCoordinate(locatiepunt) {
const coordinate = locatiepunt.split(" ");
return {
"lat": parseFloat(coordinate[0]),
"lng": parseFloat(coordinate[1])
};
}
/**
* Add markers to the map. This is done in batches, to improve performance.
* @param {number} startRecord Number of record of current batch.
* @param {boolean} isMoreDataAvailable More to load?
* @return {void}
*/
function addMarkers(startRecord, isMoreDataAvailable) {
const periodFilter = getPeriodFilter();
const bounds = appState.map.getBounds();
let position;
let i;
let publication;
if (appState.publicationsArray.length > 0) {
console.log("Adding markers " + startRecord + " to " + appState.publicationsArray.length);
}
for (i = startRecord - 1; i < appState.publicationsArray.length; i += 1) {
publication = appState.publicationsArray[i];
if (typeof publication.location === "string") {
position = findUniquePosition(createCoordinate(publication.location));
prepareToAddMarker(publication, periodFilter.periodToShow, position, bounds);
} else if (Array.isArray(publication.location)) {
publication.location.forEach(function (locatiepunt) {
position = findUniquePosition(createCoordinate(locatiepunt));
prepareToAddMarker(publication, periodFilter.periodToShow, position, bounds);
});
} else if (publication.location === undefined) {
console.error("Publication without position: " + JSON.stringify(publication, null, 4));
// Take the center of the municipality:
position = findUniquePosition(appState.municipalities[appState.activeMunicipality].center);
prepareToAddMarker(publication, periodFilter.periodToShow, position, bounds);
} else {
console.error("Unsupported publication location: " + JSON.stringify(publication, null, 4));
}
}
if (!isMoreDataAvailable) {
setLoadingIndicatorVisibility("hide");
if (!appState.isHistoryActive) {
appState.isFullyLoaded = true;
}
}
}
/**
* Add municipality markers to the map. This is done in batches, to improve performance.
* @return {void}
*/
function addMunicipalitiyMarkers() {
const municipalityNames = Object.keys(appState.municipalities);
municipalityNames.forEach(function (municipalityName) {
const municipalityObject = appState.municipalities[municipalityName];
const marker = new AdvancedMarkerElement({
"map": (
municipalityName === appState.activeMunicipality
? null
: appState.map
),
"position": municipalityObject.center,
"content": createMarkerIcon("img/gemeente.png", municipalityName),
"title": municipalityName
});
appState.municipalityMarkers.push({
"municipalityName": municipalityName,
"marker": marker
});
marker.addListener(
"click",
function () {
const municipalityComboElm = document.getElementById("idCbxMunicipality");
if (municipalityComboElm !== null) {