1/** 2 * @namespace WPGMZA 3 * @module GoogleMarker 4 * @requires WPGMZA.Marker 5 * @pro-requires WPGMZA.ProMarker 6 */ 7jQuery(function($) { 8 9 var Parent; 10 11 WPGMZA.GoogleMarker = function(options) 12 { 13 var self = this; 14 15 Parent.call(this, options); 16 17 var settings = {}; 18 if(options) 19 { 20 for(var name in options) 21 { 22 if(options[name] instanceof WPGMZA.LatLng) 23 { 24 settings[name] = options[name].toGoogleLatLng(); 25 } 26 else if(options[name] instanceof WPGMZA.Map || name == "icon") 27 { 28 // NB: Ignore map here, it's not a google.maps.Map, Google would throw an exception 29 // NB: Ignore icon here, it conflicts with updateIcon in Pro 30 } 31 else 32 settings[name] = options[name]; 33 } 34 } 35 36 if(WPGMZA.settings && WPGMZA.settings.googleMarkerMode && WPGMZA.settings.googleMarkerMode === WPGMZA.GoogleMarker.MARKER_MODE_ADVANCED){ 37 /* User has opted into the new render mode */ 38 this.googleMarker = new google.maps.marker.AdvancedMarkerElement(); 39 } else { 40 /* User is in classic/legacy mode, the default */ 41 this.googleMarker = new google.maps.Marker(settings); 42 43 /* Notice to swap, for more advanced users */ 44 if(WPGMZA && !WPGMZA.__hasNotifiedLegacyMarkers){ 45 WPGMZA.__hasNotifiedLegacyMarkers = true; 46 /* 47 console.log(`ð WP Go Maps: You are currently using Google Maps default Markers module, which has been deprecated. 48 \nGoogle has not discontinued this module, but is suggesting all users move over to their AdvancedMarkerElement instead, as it performs better and allows for more customization using CSS selectors. 49 \nOur team has added full support for this under Maps > Settings > Markers > Marker Render Mode, and highly recommend you try this new option on your site. 50 \nFor the moment, this is not our default, as we are still validating the new module for stability. We expect this feature to become the default in the future. 51 \nWant to disable this notice? Add the following to your Custom JavaScript block:\njQuery(($) => { WPGMZA.__hasNotifiedLegacyMarkers = true; });`); 52 */ 53 } 54 } 55 56 this.googleMarker.wpgmzaMarker = this; 57 this.googleFeature = this.googleMarker; 58 59 this.setPosition(new WPGMZA.LatLng(this.lat, this.lng)); 60 61 if(this.anim){ 62 this.setAnimation(this.anim); 63 } 64 65 if(this.animation){ 66 this.setAnimation(this.animation); 67 } 68 69 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 70 /* AdvancedMarkerElement module */ 71 this.googleMarker.addListener("gmp-click", function() { 72 self.dispatchEvent("click"); 73 self.dispatchEvent("select"); 74 }); 75 76 this.googleMarker.element.addEventListener("mouseover", function() { 77 self.dispatchEvent("mouseover"); 78 }); 79 80 this.googleMarker.element.addEventListener("mouseout", function() { 81 self.dispatchEvent("mouseout"); 82 }); 83 84 /* Add a globally shared CSS glass for users to leverage */ 85 if(this.googleMarker.element){ 86 this.googleMarker.element.classList.add('wpgmza-google-marker-advanced'); 87 } 88 } else { 89 /* Assume Marker module */ 90 google.maps.event.addListener(this.googleMarker, "click", function() { 91 self.dispatchEvent("click"); 92 self.dispatchEvent("select"); 93 }); 94 95 google.maps.event.addListener(this.googleMarker, "mouseover", function() { 96 self.dispatchEvent("mouseover"); 97 }); 98 99 google.maps.event.addListener(this.googleMarker, "mouseout", function() { 100 self.dispatchEvent("mouseout"); 101 }); 102 } 103 104 google.maps.event.addListener(this.googleMarker, "dragend", function() { 105 let googleMarkerPosition; 106 if(self.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 107 /* AdvancedMarkerElement module */ 108 googleMarkerPosition = self.googleMarker.position; 109 110 self.setPosition({ 111 lat: googleMarkerPosition.lat, 112 lng: googleMarkerPosition.lng 113 }); 114 } else { 115 /* Assume Marker module */ 116 googleMarkerPosition = self.googleMarker.getPosition(); 117 118 self.setPosition({ 119 lat: googleMarkerPosition.lat(), 120 lng: googleMarkerPosition.lng() 121 }); 122 } 123
124 self.dispatchEvent({ 125 type: "dragend", 126 latLng: self.getPosition() 127 }); 128 129 self.trigger("change"); 130 }); 131 132 this.setOptions(settings); 133 this.trigger("init"); 134 } 135 136 if(WPGMZA.isProVersion()) 137 Parent = WPGMZA.ProMarker; 138 else 139 Parent = WPGMZA.Marker; 140 WPGMZA.GoogleMarker.prototype = Object.create(Parent.prototype); 141 WPGMZA.GoogleMarker.prototype.constructor = WPGMZA.GoogleMarker; 142 143 WPGMZA.GoogleMarker.MARKER_MODE_LEGACY = 'marker'; 144 WPGMZA.GoogleMarker.MARKER_MODE_ADVANCED = 'advancedMarkerElement'; 145 146 Object.defineProperty(WPGMZA.GoogleMarker.prototype, "opacity", { 147 148 "get": function() { 149 return this._opacity; 150 }, 151 152 "set": function(value) { 153 this._opacity = value; 154 this.setOpacity(value); 155 } 156 157 }); 158 159 WPGMZA.GoogleMarker.prototype.setLabel = function(label) 160 { 161 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 162 /* AdvancedMarkerElement module */ 163 if(this.googleMarker.content){ 164 if(!label){ 165 const existing = this.googleMarker.content.querySelector('.wpgmza-google-marker-label'); 166 if(existing){ 167 existing.remove(); 168 } 169 170 return; 171 } 172 173 const labelElement = document.createElement("div"); 174 labelElement.classList.add('wpgmza-google-marker-label'); 175 labelElement.innerText = label; 176 177 this.googleMarker.content.appendChild(labelElement); 178 } 179 } else { 180 /* Assume Marker module */ 181 if(!label){ 182 this.googleMarker.setLabel(null); 183 return; 184 } 185 186 label = label.replaceAll("&", "&"); 187 188 this.googleMarker.setLabel({ 189 text: label, 190 className: 'wpgmza-google-marker-label-legacy' 191 }); 192 193 if(!this.googleMarker.getIcon()){ 194 this.googleMarker.setIcon(WPGMZA.settings.default_marker_icon); 195 } 196 } 197 } 198 199 /** 200 * Sets the position of the marker 201 * @return void 202 */ 203 WPGMZA.GoogleMarker.prototype.setPosition = function(latLng) 204 { 205 Parent.prototype.setPosition.call(this, latLng); 206 207 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 208 /* AdvancedMarkerElement module */ 209 this.googleMarker.position = { 210 lat: this.lat, 211 lng: this.lng 212 }; 213 } else { 214 /* Assume Marker module */ 215 this.googleMarker.setPosition({ 216 lat: this.lat, 217 lng: this.lng 218 }); 219 } 220 } 221 222 /** 223 * Sets the position offset of a marker 224 * @return void 225 */ 226 WPGMZA.GoogleMarker.prototype.updateOffset = function() 227 { 228 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 229 /* AdvancedMarkerElement module */ 230 if(this.googleMarker.content){ 231 this.googleMarker.content.style.setProperty('--wpgmza-nudge-x', this._offset.x + 'px'); 232 this.googleMarker.content.style.setProperty('--wpgmza-nudge-y', this._offset.y + 'px'); 233 234 this.googleMarker.content.classList.add('wpgmza-google-icon-nudge'); 235 } 236 } else { 237 /* Marker Module */ 238 var self = this; 239 var icon = this.googleMarker.getIcon(); 240 var img = new Image(); 241 var params; 242 var x = this._offset.x; 243 var y = this._offset.y; 244 245 if(!icon){ 246 if(WPGMZA.settings.default_marker_icon){ 247 icon = WPGMZA.settings.default_marker_icon; 248 } else if (this.map.settings.default_marker_icon){ 249 icon = this.map.settings.default_marker_icon; 250 } else if(this.map.settings.default_marker){ 251 icon = this.map.settings.default_marker; 252 } 253 } 254 255 if(typeof icon == "string"){ 256 params = { 257 url: icon 258 }; 259 }else{ 260 params = icon; 261 } 262 263 img.onload = function(){ 264 var defaultAnchor = { 265 x: img.width / 2, 266 y: img.height 267 }; 268 269 params.anchor = new google.maps.Point(defaultAnchor.x - x, defaultAnchor.y - y); 270 271 self.googleMarker.setIcon(params); 272 } 273 274 img.src = params.url; 275 } 276 277 } 278 279 WPGMZA.GoogleMarker.prototype.setOptions = function(options) 280 { 281 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 282 /* AdvancedMarkerElement module */ 283 for(let key in options){ 284 const value = options[key]; 285 switch(key){ 286 case 'animation': 287 this.setAnimation(value); 288 break; 289 case 'opacity': 290 this.setOpacity(value); 291 break; 292 case 'visible': 293 this.setVisible(value); 294 break; 295 case 'zIndex': 296 this.googleMarker.zIndex = value; 297 break; 298 case 'title': 299 this.googleMarker.title = value; 300 break; 301 } 302 } 303 } else { 304 /* Assume Marker module */ 305 this.googleMarker.setOptions(options); 306 } 307 } 308 309 /** 310 * Set the marker animation 311 * @return void 312 */ 313 WPGMZA.GoogleMarker.prototype.setAnimation = function(animation) 314 { 315 Parent.prototype.setAnimation.call(this, animation); 316 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 317 /* AdvancedMarkerElement module */ 318 if(this.googleMarker.content){ 319 switch(animation){ 320 case WPGMZA.Marker.ANIMATION_BOUNCE: 321 this.googleMarker.content.classList.add('wpgmza-google-marker-bounce'); 322 break; 323 case WPGMZA.Marker.ANIMATION_DROP: 324 this.googleMarker.content.classList.add('wpgmza-google-marker-drop'); 325 break; 326 case WPGMZA.Marker.ANIMATION_NONE: 327 default: 328 break; 329 } 330 } 331 } else { 332 /* Assume Marker module */ 333 this.googleMarker.setAnimation(animation); 334 } 335 } 336 337 /** 338 * Sets the visibility of the marker 339 * @return void 340 */ 341 WPGMZA.GoogleMarker.prototype.setVisible = function(visible) 342 { 343 Parent.prototype.setVisible.call(this, visible); 344 345 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 346 /* AdvancedMarkerElement module */ 347 if(this.googleMarker.element){ 348 if(visible){ 349 this.googleMarker.element.classList.remove('wpgmza-google-marker-hidden'); 350 } else { 351 this.googleMarker.element.classList.add('wpgmza-google-marker-hidden'); 352 } 353 } 354 } else { 355 /* Assume Marker module */ 356 this.googleMarker.setVisible(visible ? true : false); 357 } 358 } 359 360 WPGMZA.GoogleMarker.prototype.getVisible = function(visible) 361 { 362 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 363 /* AdvancedMarkerElement module */ 364 return this.googleMarker.element.classList.contains('wpgmza-google-marker-hidden') ? false : true; 365 } else { 366 /* Assume Marker module */ 367 return this.googleMarker.getVisible(); 368 } 369 } 370 371 WPGMZA.GoogleMarker.prototype.setDraggable = function(draggable) 372 { 373 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 374 /* AdvancedMarkerElement module */ 375 this.googleMarker.gmpDraggable = draggable; 376 } else { 377 /* Assume Marker module */ 378 this.googleMarker.setDraggable(draggable); 379 } 380 } 381 382 WPGMZA.GoogleMarker.prototype.setOpacity = function(opacity) 383 { 384 if(this.googleMarker instanceof google.maps.marker.AdvancedMarkerElement){ 385 /* AdvancedMarkerElement module */ 386 if(this.googleMarker.content){ 387 this.googleMarker.content.style.setProperty("--wpgmza-opacity", opacity); 388 this.googleMarker.content.classList.add('wpgmza-google-marker-opacity'); 389 } 390 } else { 391 /* Assume Marker module */ 392 this.googleMarker.setOpacity(opacity); 393 } 394 } 395 396});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.