@@ -742,6 +742,32 @@ function initMap() {
742
742
}
743
743
}
744
744
745
+ /**
746
+ * Create a marker icon.
747
+ * @param {string } sourceUrl Link to marker image.
748
+ * @param {boolean } isVisible Create a hidden marker, or not.
749
+ * @param {string= } label Optional label.
750
+ * @return {!HTMLDivElement } Marker node containing the image.
751
+ */
752
+ function createMarkerIcon ( sourceUrl , isVisible , label ) {
753
+ const iconContainer = document . createElement ( "div" ) ;
754
+ if ( ! isVisible ) {
755
+ iconContainer . style . visibility = "hidden" ;
756
+ }
757
+ const icon = document . createElement ( "img" ) ;
758
+ icon . src = sourceUrl ;
759
+ iconContainer . appendChild ( icon ) ;
760
+ if ( label === undefined ) {
761
+ return iconContainer ;
762
+ }
763
+ iconContainer . classList . add ( "municipalityContainer" ) ;
764
+ const labelContainer = document . createElement ( "div" ) ;
765
+ labelContainer . classList . add ( "municipalityLabel" ) ;
766
+ labelContainer . innerText = label ;
767
+ iconContainer . appendChild ( labelContainer ) ;
768
+ return iconContainer ;
769
+ }
770
+
745
771
/**
746
772
* Add a marker to the map.
747
773
* @param {!Object } publication Publication object.
@@ -781,10 +807,7 @@ function initMap() {
781
807
function onMouseOver ( ) {
782
808
appState . markersArray . forEach ( function ( markerObject ) {
783
809
if ( markerObject . url === publication . urlDoc ) {
784
- markerObject . marker . setIcon ( {
785
- "url" : "img/" + iconName + "-highlight.png" ,
786
- "size" : iconSize
787
- } ) ;
810
+ markerObject . marker . content . getElementsByTagName ( "img" ) [ 0 ] . src = "img/" + iconName + "-highlight.png" ;
788
811
}
789
812
} ) ;
790
813
}
@@ -795,7 +818,7 @@ function initMap() {
795
818
function onMouseOut ( ) {
796
819
appState . markersArray . forEach ( function ( markerObject ) {
797
820
if ( markerObject . url === publication . urlDoc ) {
798
- markerObject . marker . setIcon ( icon ) ;
821
+ markerObject . marker . content . getElementsByTagName ( "img" ) [ 0 ] . src = "img/" + iconName + ".png" ;
799
822
}
800
823
} ) ;
801
824
}
@@ -806,21 +829,13 @@ function initMap() {
806
829
// "TVM- 7 PV reserveren - Monnikendammerweg 27-37 - 03-07/10/2022, Monnikendammerweg 27";
807
830
// 125171;
808
831
// 488983
809
- // https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions
832
+ // https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElementOptions
810
833
const age = getDaysPassed ( publication . date ) ;
811
834
const iconName = getIconName ( publication . title , publication . type ) ;
812
- const iconSize = new google . maps . Size ( 35 , 45 ) ; // Make sure image is already scaled
813
- const icon = {
814
- "url" : "img/" + iconName + ".png" ,
815
- "size" : iconSize
816
- } ;
817
- const marker = new google . maps . Marker ( {
835
+ const marker = new google . maps . marker . AdvancedMarkerElement ( {
818
836
"map" : appState . map ,
819
837
"position" : position ,
820
- "clickable" : true ,
821
- "optimized" : true ,
822
- "visible" : isMarkerVisible ( age , periodToShow ) ,
823
- "icon" : icon ,
838
+ "content" : createMarkerIcon ( "img/" + iconName + ".png" , isMarkerVisible ( age , periodToShow ) ) ,
824
839
"zIndex" : appState . zIndex ,
825
840
"title" : publication . title
826
841
} ) ;
@@ -835,8 +850,8 @@ function initMap() {
835
850
appState . markersArray . push ( markerObject ) ;
836
851
marker . addListener ( "click" , onClick ) ;
837
852
// Highlight the icon (and related icons) on hover
838
- marker . addListener ( "mouseover" , onMouseOver ) ;
839
- marker . addListener ( "mouseout" , onMouseOut ) ;
853
+ marker . content . addEventListener ( "mouseover" , onMouseOver ) ;
854
+ marker . content . addEventListener ( "mouseout" , onMouseOut ) ;
840
855
return markerObject ;
841
856
}
842
857
@@ -959,18 +974,10 @@ function initMap() {
959
974
const municipalityNames = Object . keys ( appState . municipalities ) ;
960
975
municipalityNames . forEach ( function ( municipalityName ) {
961
976
const municipalityObject = appState . municipalities [ municipalityName ] ;
962
- let marker = new google . maps . Marker ( {
977
+ const marker = new google . maps . marker . AdvancedMarkerElement ( {
963
978
"map" : appState . map ,
964
979
"position" : municipalityObject . center ,
965
- "label" : municipalityName , // https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerLabel
966
- "clickable" : true ,
967
- "optimized" : true ,
968
- //"scaleControl": true,
969
- "visible" : municipalityName !== appState . activeMunicipality ,
970
- "icon" : {
971
- "url" : "img/gemeente.png" ,
972
- "size" : new google . maps . Size ( 50 , 61 ) // Make sure image is already scaled
973
- } ,
980
+ "content" : createMarkerIcon ( "img/gemeente.png" , municipalityName !== appState . activeMunicipality , municipalityName ) ,
974
981
"title" : municipalityName
975
982
} ) ;
976
983
appState . municipalityMarkers . push ( {
@@ -991,6 +998,20 @@ function initMap() {
991
998
} ) ;
992
999
}
993
1000
1001
+ /**
1002
+ * Show or hide a marker.
1003
+ * @param {!Object } marker Marker object.
1004
+ * @param {boolean } isVisible Set visibility.
1005
+ * @return {void }
1006
+ */
1007
+ function setMarkerVisibility ( marker , isVisible ) {
1008
+ if ( isVisible ) {
1009
+ marker . content . style . visibility = "visible" ;
1010
+ } else {
1011
+ marker . content . style . visibility = "hidden" ;
1012
+ }
1013
+ }
1014
+
994
1015
/**
995
1016
* Reset time filter. This is done when the municipality is changed.
996
1017
* @return {void }
@@ -1015,7 +1036,7 @@ function initMap() {
1015
1036
}
1016
1037
}
1017
1038
appState . markersArray . forEach ( function ( markerObject ) {
1018
- markerObject . marker . setVisible ( isMarkerVisible ( markerObject . age , periodFilter . periodToShow ) ) ;
1039
+ setMarkerVisibility ( markerObject . marker , isMarkerVisible ( markerObject . age , periodFilter . periodToShow ) ) ;
1019
1040
} ) ;
1020
1041
}
1021
1042
}
@@ -1231,11 +1252,11 @@ function initMap() {
1231
1252
{
1232
1253
"backgroundColor" : "#9CC0F9" , // https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.backgroundColor
1233
1254
"clickableIcons" : false , // https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.clickableIcons
1234
- // Paid feature - "mapId": "c2a918307d540be7",
1235
1255
"center" : new google . maps . LatLng ( mapSettings . center . lat , mapSettings . center . lng ) ,
1236
1256
"mapTypeId" : google . maps . MapTypeId . ROADMAP , // https://developers.google.com/maps/documentation/javascript/reference/map#MapTypeId
1237
1257
"gestureHandling" : "greedy" , // When scrolling, keep scrolling
1238
- "zoom" : mapSettings . zoomLevel
1258
+ "zoom" : mapSettings . zoomLevel ,
1259
+ "mapId" : "fa8c70ada3bf211a"
1239
1260
}
1240
1261
) ;
1241
1262
determineRequestPeriod ( ) ;
@@ -1387,7 +1408,7 @@ function initMap() {
1387
1408
function hideActiveMunicipalityMarker ( ) {
1388
1409
appState . municipalityMarkers . forEach ( function ( markerObject ) {
1389
1410
if ( markerObject . municipalityName === appState . activeMunicipality ) {
1390
- markerObject . marker . setVisible ( false ) ;
1411
+ setMarkerVisibility ( markerObject . marker , false ) ;
1391
1412
}
1392
1413
} ) ;
1393
1414
}
@@ -1551,7 +1572,7 @@ function initMap() {
1551
1572
markerObject . marker . setMap ( null ) ;
1552
1573
} ) ;
1553
1574
appState . municipalityMarkers . forEach ( function ( markerObject ) {
1554
- markerObject . marker . setVisible ( markerObject . municipalityName !== municipalityToHide ) ;
1575
+ setMarkerVisibility ( markerObject . marker , markerObject . municipalityName !== municipalityToHide ) ;
1555
1576
} ) ;
1556
1577
appState . markersArray = [ ] ;
1557
1578
appState . delayedMarkersArray = [ ] ;
0 commit comments