1// Markers 2function gmpCanUseAdvancedMarkers() { 3 return !!(window.google && google.maps && google.maps.marker && google.maps.marker.AdvancedMarkerElement); 4} 5function gmpGetMarkerMapInstance(map) { 6 return map && typeof map.getRawMapInstance == 'function' ? map.getRawMapInstance() : null; 7} 8function gmpNormalizeMarkerPosition(position) { 9 if (!position) { 10 return position; 11 } 12 if (typeof position.lat === 'function' && typeof position.lng === 'function') { 13 return position; 14 } 15 if (typeof position.lat !== 'undefined' && typeof position.lng !== 'undefined') { 16 return new google.maps.LatLng(position.lat, position.lng); 17 } 18 return position; 19} 20function gmpCreateAdvancedMarkerContent(icon) { 21 if (!icon || typeof icon !== 'string') { 22 return null; 23 } 24 var markerContent = document.createElement('img'); 25 26 markerContent.src = icon; 27 markerContent.alt = ''; 28 markerContent.className = 'gmp-advanced-marker-icon'; 29 markerContent.style.maxWidth = 'none'; 30 markerContent.style.position = 'absolute'; 31 markerContent.style.transform = 'translate(-50%, -100%)'; 32 markerContent.title = ''; 33 34 return markerContent; 35} 36function gmpPatchAdvancedMarker(marker) { 37 if (!marker || marker._gmpPatched) { 38 return marker; 39 } 40 marker._gmpPatched = true; 41 marker._gmpNativeSetMap = typeof marker.setMap === 'function' ? marker.setMap.bind(marker) : null; 42 marker._gmpNativeGetMap = typeof marker.getMap === 'function' ? marker.getMap.bind(marker) : null; 43 marker._gmpVisible = marker._gmpNativeGetMap ? marker._gmpNativeGetMap() !== null : marker.map !== null; 44 marker._gmpIcon = marker.content && marker.content.tagName === 'IMG' ? marker.content.src : null; 45 marker.getPosition = function () { 46 return gmpNormalizeMarkerPosition(this.position); 47 }; 48 marker.setPosition = function (position) { 49 this.position = gmpNormalizeMarkerPosition(position); 50 }; 51 marker.getMap = function () { 52 return this._gmpNativeGetMap ? this._gmpNativeGetMap() : this.map || null; 53 }; 54 marker.setMap = function (map) { 55 if (this._gmpNativeSetMap) { 56 this._gmpNativeSetMap(map); 57 } else { 58 this.map = map; 59 } 60 this._gmpVisible = map !== null; 61 }; 62 marker.getVisible = function () { 63 return this._gmpVisible; 64 }; 65 marker.setVisible = function (state) { 66 this._gmpVisible = !!state; 67 if (this._gmpNativeSetMap) { 68 this._gmpNativeSetMap(state ? this._gmpOwnerMap : null); 69 } else { 70 this.map = state ? this._gmpOwnerMap : null; 71 } 72 }; 73 marker.getIcon = function () { 74 return this._gmpIcon; 75 }; 76 marker.setIcon = function (icon) { 77 this._gmpIcon = icon; 78 this.content = gmpCreateAdvancedMarkerContent(icon); 79 }; 80 marker.setTitle = function (title) { 81 // AdvancedMarkerElement's title setter throws if given anything but a string. 82 title = typeof title === 'string' ? title : ''; 83 this.title = title; 84 if (this.content) { 85 this.content.title = ''; 86 this.content.setAttribute('aria-label', title); 87 } 88 }; 89 return marker; 90} 91function gmpGoogleMarker(map, params) { 92 this._map = map; 93 this._markerObj = null; 94 this._useAdvancedMarker = false; 95 this._hoverInfoWndTimeout = null; 96 var defaults = { 97 // Empty for now 98 }; 99 if (!params.position && params.coord_x && params.coord_y) { 100 params.position = new google.maps.LatLng(params.coord_x, params.coord_y); 101 } 102 this._markerParams = jQuery.extend({}, defaults, params); 103 this._markerParams.map = this._map.getRawMapInstance(); 104 //this._id = params.id ? params.id : 0; 105 this._infoWindow = null; 106 this._infoWndOpened = false; 107 this._infoWndWasInited = false; 108 this._infoWndDirectionsBtn = false; 109 this._infoWndPrintBtn = false; 110 this._mapDragScroll = { 111 scrollwheel: null, 112 }; 113 this.init(); 114} 115gmpGoogleMarker.prototype.infoWndOpened = function () { 116 return this._infoWndOpened; 117}; 118gmpGoogleMarker.prototype._clearHoverInfoWndTimeout = function () { 119 if (this._hoverInfoWndTimeout) { 120 clearTimeout(this._hoverInfoWndTimeout); 121 this._hoverInfoWndTimeout = null; 122 } 123}; 124gmpGoogleMarker.prototype._canUseAdvancedMarker = function () { 125 var mapId = this._map.getParam('mapId'); 126 127 return gmpCanUseAdvancedMarkers() && !!this._map.getRawMapInstance() && !!mapId; 128}; 129gmpGoogleMarker.prototype._prepareAdvancedMarkerParams = function (params) { 130 var markerParams = {
131 map: gmpGetMarkerMapInstance(this._map), 132 position: gmpNormalizeMarkerPosition(params.position), 133 gmpDraggable: !!params.draggable, 134 }; 135 136 if (params.zIndex) { 137 markerParams.zIndex = params.zIndex; 138 } 139 if (typeof params.gmpClickable !== 'undefined') { 140 markerParams.gmpClickable = !!params.gmpClickable; 141 } 142 if (typeof params.collisionBehavior !== 'undefined') { 143 markerParams.collisionBehavior = params.collisionBehavior; 144 } 145 markerParams.content = gmpCreateAdvancedMarkerContent(params.icon); 146 147 return markerParams; 148}; 149gmpGoogleMarker.prototype._bindMarkerListener = function (eventName, callback) { 150 if (!this._markerObj) { 151 return; 152 } 153 if (this._useAdvancedMarker) { 154 if (eventName === 'click') { 155 eventName = 'gmp-click'; 156 } 157 if ((eventName === 'mouseover' || eventName === 'mouseout') && this._markerObj.content && typeof this._markerObj.content.addEventListener === 'function') { 158 this._markerObj.content.addEventListener(eventName, callback); 159 return; 160 } 161 } 162 if (typeof this._markerObj.addListener == 'function') { 163 this._markerObj.addListener(eventName, callback); 164 } else { 165 google.maps.event.addListener(this._markerObj, eventName, callback); 166 } 167}; 168gmpGoogleMarker.prototype._openInfoWindow = function () { 169 if (this._useAdvancedMarker) { 170 this._infoWindow.open({ 171 map: this._map.getRawMapInstance(), 172 anchor: this._markerObj, 173 }); 174 } else { 175 this._infoWindow.open(this._map.getRawMapInstance(), this._markerObj); 176 } 177}; 178gmpGoogleMarker.prototype.init = function () { 179 var markerParamsForCreate = this._markerParams, 180 openInfoWndEvent = 'click', 181 closeInfoWndEvent = '', 182 openLinkEvent = 'click'; 183 184 if (parseInt(this._map._mapParams.hide_marker_tooltip)) { 185 this._markerParams.marker_title = this._markerParams.title; 186 delete markerParamsForCreate.title; 187 } 188 if (this._canUseAdvancedMarker()) { 189 this._markerObj = gmpPatchAdvancedMarker(new google.maps.marker.AdvancedMarkerElement(this._prepareAdvancedMarkerParams(markerParamsForCreate))); 190 this._markerObj._gmpOwnerMap = this._map.getRawMapInstance(); 191 this._markerObj.params = this._markerParams.params || {}; 192 this._markerObj.marker_group_id = this._markerParams.marker_group_id || 0; 193 this._markerObj.draggable = !!this._markerParams.draggable; 194 this._useAdvancedMarker = true; 195 } else { 196 this._markerObj = new google.maps.Marker(markerParamsForCreate); 197 if (typeof this._markerObj.setTitle === 'function') { 198 this._markerObj.setTitle(''); 199 } 200 } 201 if (this._markerParams.dragend) { 202 this._bindMarkerListener('dragend', jQuery.proxy(this._markerParams.dragend, this)); 203 } 204 if (this._markerParams.click) { 205 this._bindMarkerListener('click', jQuery.proxy(this._markerParams.click, this)); 206 } 207 if (this._markerParams.params && !(window.ontouchstart === null || navigator.msMaxTouchPoints)) { 208 if (parseInt(this._markerParams.params.description_mouse_hover)) { 209 openInfoWndEvent = 'mouseover'; 210 if (parseInt(this._markerParams.params.description_mouse_leave)) { 211 closeInfoWndEvent = 'mouseout'; 212 } 213 } 214 } 215 this._bindMarkerListener( 216 openInfoWndEvent, 217 jQuery.proxy(function () { 218 if (this._markerParams.params && !parseInt(this._markerParams.params.description_mouse_hover) && parseInt(this._markerParams.params.marker_link)) { 219 return; 220 } else if (openInfoWndEvent === 'mouseover') { 221 this._clearHoverInfoWndTimeout(); 222 this._hoverInfoWndTimeout = setTimeout( 223 jQuery.proxy(function () { 224 this.showInfoWnd(); 225 this._hoverInfoWndTimeout = null; 226 }, this), 227 500 228 ); 229 } else { 230 this.showInfoWnd(); 231 } 232 jQuery(document).trigger('gmapAfterMarkerClick', this); 233 }, this) 234 ); 235 if (closeInfoWndEvent) { 236 this._bindMarkerListener( 237 closeInfoWndEvent, 238 jQuery.proxy(function () { 239 var self = this, 240 infoWndDiv = jQuery('.gm-style-iw').parent(), 241 timeout = 300; 242 243 self._clearHoverInfoWndTimeout(); 244 245 infoWndDiv.on('mouseover', function () { 246 // Mouse is on infowindow content 247 infoWndDiv.addClass('hovering'); 248 }); 249 infoWndDiv.on('mouseleave', function () { 250 // Hide infowindow after mouse have left infowindow content 251 setTimeout(function () { 252 self.hideInfoWnd(); 253 }, timeout); 254 }); 255 setTimeout(function () { 256 // Hide infowindow if mouse is not on infowindow content 257 if (!infoWndDiv.hasClass('hovering')) { 258 self.hideInfoWnd(); 259 } 260 }, timeout); 261 }, this) 262 ); 263 } 264 if (this._markerParams.params && parseInt(this._markerParams.params.marker_link)) { 265 this._bindMarkerListener( 266 openLinkEvent, 267 jQuery.proxy(function () { 268 var isLink = /http/gi, 269 markerLink = !this._markerParams.params.marker_link_src.match(isLink) ? 'http://' + this._markerParams.params.marker_link_src : this._markerParams.params.marker_link_src; 270 271 if (parseInt(this._markerParams.params.marker_link_new_wnd)) { 272 window.open(markerLink, '_blank'); 273 } else { 274 location.href = markerLink; 275 } 276 }, this) 277 ); 278 } 279}; 280gmpGoogleMarker.prototype.showInfoWnd = function (forceUpdateInfoWnd, forceShow) { 281 var allShapes = this._map.getAllShapes(); 282 if (allShapes && allShapes.length) { 283 for (var i = 0; i < allShapes.length; i++) { 284 if (allShapes[i]._infoWndOpened) allShapes[i].hideInfoWnd(); 285 } 286 }
287 if (!this._infoWndWasInited || forceUpdateInfoWnd) { 288 this._updateInfoWndContent(); 289 this._infoWndWasInited = true; 290 } 291 if (this._infoWindow && !this._infoWndOpened) { 292 var allMapMArkers = this._map.getAllMarkers(); 293 // Google Maps Javascript API v3 allows to open several infowindows on map 294 if (allMapMArkers && allMapMArkers.length > 1 && !forceShow) { 295 for (var i = 0; i < allMapMArkers.length; i++) { 296 allMapMArkers[i].hideInfoWnd(); 297 } 298 } 299 if (parseInt(this.getMap().getParam('center_on_cur_marker_infownd')) && !GMP_DATA.isAdmin) { 300 this.getMap().setCenter(this.getMarkerParam('position')); 301 } 302 if (this._map.getParam('marker_infownd_type') == 'slide' && typeof this.showInfoWndSlide == 'function') { 303 this.showInfoWndSlide(); 304 } else { 305 this._openInfoWindow(); 306 } 307 this._infoWndOpened = true; 308 } 309}; 310gmpGoogleMarker.prototype.hideInfoWnd = function () { 311 this._clearHoverInfoWndTimeout(); 312 if (this._infoWindow && this._infoWndOpened) { 313 this._infoWindow.close(); 314 this._infoWndOpened = false; 315 316 var googleMap = this._map.getRawMapInstance(); 317 googleMap.setOptions({ scrollwheel: this._mapDragScroll.scrollwheel }); 318 319 jQuery(document).trigger('gmapAfterHideInfoWnd', this); 320 } 321}; 322gmpGoogleMarker.prototype.getRawMarkerInstance = function () { 323 return this._markerObj; 324}; 325gmpGoogleMarker.prototype.getRawMarkerParams = function () { 326 return this._markerParams; 327}; 328gmpGoogleMarker.prototype.getIcon = function () { 329 return this._markerObj.getIcon(); 330}; 331gmpGoogleMarker.prototype.setIcon = function (iconPath) { 332 this._markerObj.setIcon(iconPath); 333 this._markerParams.icon = iconPath; 334}; 335gmpGoogleMarker.prototype.setTitle = function (title, noRefresh) { 336 if (!parseInt(this._map._mapParams.hide_marker_tooltip)) this._markerObj.setTitle(title); 337 this._markerParams.title = title; 338 if (!noRefresh) this._updateInfoWndContent(); 339}; 340gmpGoogleMarker.prototype.getTitle = function () { 341 return typeof this._markerParams.title != 'undefined' ? this._markerParams.title : this._markerParams.marker_title; 342}; 343gmpGoogleMarker.prototype.getPosition = function () { 344 return this._markerObj.getPosition(); 345}; 346gmpGoogleMarker.prototype.setPosition = function (lat, lng) { 347 var position = new google.maps.LatLng(lat, lng); 348 this._markerObj.setPosition(position); 349 this._markerParams.position = position; 350}; 351gmpGoogleMarker.prototype.lat = function () { 352 return this.getPosition().lat(); 353}; 354gmpGoogleMarker.prototype.lng = function (lng) { 355 return this.getPosition().lng(); 356}; 357gmpGoogleMarker.prototype.setId = function (id) { 358 this._markerParams.id = id; 359}; 360gmpGoogleMarker.prototype.getId = function () { 361 return this._markerParams.id; 362}; 363gmpGoogleMarker.prototype.setDescription = function (description, noRefresh) { 364 this._markerParams.description = description; 365 if (!noRefresh) this._updateInfoWndContent(); 366 if (this._markerParams.params && parseInt(this._markerParams.params.show_description)) { 367 this.showInfoWnd(false, true); 368 } 369}; 370gmpGoogleMarker.prototype.getDescription = function () { 371 return this._markerParams.description; 372}; 373gmpGoogleMarker.prototype._setTitleColor = function (titleDiv) { 374 var titleColor = this._map.getParam('marker_title_color'); 375 376 if (titleColor && titleColor != '') { 377 titleDiv.css({ 378 color: titleColor, 379 }); 380 } 381 return titleDiv; 382}; 383gmpGoogleMarker.prototype._setTitleSize = function (titleDiv) { 384 var titleSize = this._map.getParam('marker_title_size'), 385 titleSizeUnits = this._map.getParam('marker_title_size_units'); 386 387 if (titleSize && titleSizeUnits && titleSize != '') { 388 titleDiv.css({ 389 'font-size': titleSize + titleSizeUnits, 390 'line-height': +titleSize + 5 + titleSizeUnits, 391 }); 392 } 393 return titleDiv; 394}; 395gmpGoogleMarker.prototype._setDescSize = function (descDiv) { 396 var descSize = this._map.getParam('marker_desc_size'), 397 descSizeUnits = this._map.getParam('marker_desc_size_units'); 398 399 if (descSize && descSizeUnits && descSize != '') { 400 descDiv.css({ 401 'font-size': descSize + descSizeUnits, 402 'line-height': parseInt(descSize) + 5 + descSizeUnits, 403 });
404 } 405 return descDiv; 406}; 407gmpGoogleMarker.prototype._updateInfoWndContent = function () { 408 var contentStr = jQuery('<div/>', {}), 409 description = this._markerParams.description ? this._markerParams.description.replace(/\n/g, '<br/>') : false, 410 title = this._markerParams.title ? this._markerParams.title : false; 411 412 if (parseInt(this._map._mapParams.hide_marker_tooltip) && !GMP_DATA.isAdmin) { 413 title = this._markerParams.marker_title ? this._markerParams.marker_title : false; 414 } 415 if (title) { 416 var titleDiv = jQuery('<div/>', {}).addClass('gmpInfoWindowtitle').html(title); 417 418 titleDiv = this._setTitleColor(titleDiv); 419 titleDiv = this._setTitleSize(titleDiv); 420 contentStr.append(titleDiv); 421 422 if (this._infoWndDirectionsBtn) { 423 this._infoWndDirectionsBtn.insertAfter(contentStr.find('.gmpInfoWindowtitle')); 424 } 425 if (this._infoWndPrintBtn) { 426 this._infoWndPrintBtn.insertAfter(contentStr.find('.gmpInfoWindowtitle')); 427 } 428 } 429 if (description) { 430 var descDiv = jQuery('<div/>', {}).addClass('egm-marker-iw').html(description); 431 432 descDiv = this._setDescSize(descDiv); 433 contentStr.append(descDiv); 434 435 // Check scripts in description, and execute them if they are there 436 var $scripts = contentStr.find('script'); 437 if ($scripts && $scripts.length) { 438 $scripts.each(function () { 439 var scriptSrc = jQuery(this).attr('src'); 440 if (scriptSrc && scriptSrc != '') { 441 jQuery.getScript(scriptSrc); 442 } 443 }); 444 } 445 } 446 this._setInfoWndContent(contentStr); 447}; 448/** 449 * Just mark it as closed 450 */ 451gmpGoogleMarker.prototype._setInfoWndClosed = function () { 452 this._infoWndOpened = false; 453 jQuery(document).trigger('gmapAfterHideInfoWnd', this); 454}; 455gmpGoogleMarker.prototype._setInfoWndContent = function (newContentHtmlObj) { 456 var self = this, 457 map = this.getMap(); 458 459 if (!this._infoWindow) { 460 var mapWidth = GMP_DATA.isAdmin ? jQuery('#gmpMapPreview').width() : jQuery('#' + map.getViewHtmlId()).width(), 461 infoWndType = map.getParam('marker_infownd_type'), 462 infoWndWidth = map.getParam('marker_infownd_width_units') == 'px' ? map.getParam('marker_infownd_width') : mapWidth - 20, 463 infoWndHeight = map.getParam('marker_infownd_height_units') == 'px' ? map.getParam('marker_infownd_height') + 'px' : false, 464 maxWndWidth = mapWidth * 0.6, 465 infoWndParams = { maxWidth: infoWndWidth < maxWndWidth ? infoWndWidth : maxWndWidth }; 466 467 switch (infoWndType) { 468 case 'rounded_edges': 469 infoWndParams.pixelOffset = new google.maps.Size(0, 10); 470 break; 471 default: 472 break; 473 } 474 475 //add disableAutoPan property if description_mouse_leave is true 476 /*if(this._markerParams.params && this._markerParams.params.description_mouse_leave) 477 infoWndParams['disableAutoPan'] = true;*/ 478 479 this._infoWindow = new google.maps.InfoWindow(infoWndParams); 480 481 google.maps.event.addListener(this._infoWindow, 'domready', function () { 482 changeInfoWndType(map); 483 changeInfoWndBgColor(map); 484 // check if tooltip text has "Gallery by Supsystic" 485 if (this.content && this.content.innerHTML && this.content.innerHTML.indexOf && this.content.innerHTML.indexOf('id="grid-gallery-') != -1) { 486 jQuery(document).trigger('ggFirInitialize'); 487 } 488 }); 489 google.maps.event.addListener(this._infoWindow, 'closeclick', function () { 490 self._setInfoWndClosed(); 491 }); 492 } 493 if (infoWndHeight) { 494 newContentHtmlObj.css('cssText', 'max-height: ' + infoWndHeight + ';'); 495 } 496 497 // Fix bug in FF - scroll on infowindow content changes map zoom 498 var scrollwheel = map.get('scrollwheel'), 499 googleMap = map.getRawMapInstance(); 500 501 //Save scrollwheel setting to container before rewrite it. 502 this._mapDragScroll.scrollwheel = scrollwheel; 503 504 newContentHtmlObj.hover( 505 function () { 506 googleMap.setOptions({ scrollwheel: false }); 507 }, 508 function () { 509 googleMap.setOptions({ scrollwheel: scrollwheel }); 510 } 511 ); 512 this._infoWindow.setContent(newContentHtmlObj[0]); 513}; 514gmpGoogleMarker.prototype.removeFromMap = function () { 515 this.getRawMarkerInstance().setMap(null); 516}; 517gmpGoogleMarker.prototype.setMarkerParams = function (params) { 518 this._markerParams = params; 519 return this; 520};
521gmpGoogleMarker.prototype.setMarkerParam = function (key, value) { 522 this._markerParams[key] = value; 523 return this; 524}; 525gmpGoogleMarker.prototype.getMarkerParam = function (key) { 526 return this._markerParams[key]; 527}; 528gmpGoogleMarker.prototype.setMap = function (map) { 529 if (this._useAdvancedMarker && map) { 530 this._markerObj._gmpOwnerMap = map; 531 } 532 this.getRawMarkerInstance().setMap(map); 533}; 534gmpGoogleMarker.prototype.getMap = function () { 535 return this._map; 536}; 537gmpGoogleMarker.prototype.setVisible = function (state) { 538 this.getRawMarkerInstance().setVisible(state); 539}; 540gmpGoogleMarker.prototype.getVisible = function () { 541 return this.getRawMarkerInstance().getVisible(); 542}; 543// Common functions 544function _gmpPrepareMarkersList(markers, params) { 545 params = params || {}; 546 if (markers) { 547 for (var i = 0; i < markers.length; i++) { 548 markers[i].coord_x = parseFloat(markers[i].coord_x); 549 markers[i].coord_y = parseFloat(markers[i].coord_y); 550 markers[i].icon = markers[i].icon_data.path; 551 if (params.dragend) { 552 markers[i].draggable = true; 553 markers[i].dragend = params.dragend; 554 } 555 } 556 } 557 return markers; 558} 559 560window.gmpGoogleMarker = gmpGoogleMarker;
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.