1var WPGM_Path_Polygon = new Array(); 2var WPGM_Path = new Array(); 3var infoWindow_poly = Array(); 4var marker_array = Array(); 5var marker_sl = null; 6 7for (var entry in wpgmaps_localize) { 8 if ('undefined' === typeof window.jQuery) { 9 setTimeout(function(){ document.getElementById('wpgmza_map').innerHTML = 'Error: In order for WP Google Maps to work, jQuery must be installed. A check was done and jQuery was not present. Please see the <a href="http://www.wpgmaps.com/documentation/troubleshooting/jquery-troubleshooting/" title="WP Google Maps - jQuery Troubleshooting">jQuery troubleshooting section of our site</a> for more information.'; }, 5000); 10 } 11} 12 13function wpgmza_parse_theme_data(raw) 14{ 15 16 var json; 17 18 try{ 19 json = JSON.parse(raw); 20 }catch(e) { 21 try{ 22 json = eval(raw); 23 }catch(e) { 24 console.warn("Couldn't parse theme data"); 25 return []; 26 } 27 } 28 29 return json; 30} 31 32function wpgmza_get_guid() 33{ 34 function s4() { 35 return Math.floor((1 + Math.random()) * 0x10000) 36 .toString(16) 37 .substring(1); 38 } 39 return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); 40} 41 42function wpgmza_open_info_window(infoWindow, content) 43{ 44 var guid = wpgmza_get_guid(); 45 var div = $("<div hidden data-info-window-guid='" + guid + "'/>"); 46 47 wpgmza_init_infowindow(); 48 49 infoWindow.setContent(div); 50 infoWindow.open(); 51 52 $("div[data-info-window-guid='" + guid + "']").trigger("infowindowopen.wpgmza"); 53} 54 55function InitMap() { 56 57 var $ = jQuery; 58 59 if(WPGMZA.googleAPIStatus && WPGMZA.googleAPIStatus.code == "USER_CONSENT_NOT_GIVEN") 60 { 61 $("#wpgmza_map, .wpgmza_map").each(function(index, el) { 62 $(el).append($(WPGMZA.api_consent_html)); 63 $(el).css({height: "auto"}); 64 }); 65 66 $("button.wpgmza-api-consent").on("click", function(event) { 67 Cookies.set("wpgmza-api-consent-given", true); 68 window.location.reload(); 69 }); 70 71 return; 72 } 73 74 var myLatLng = { 75 lat: wpgmaps_localize[wpgmaps_mapid].map_start_lat, 76 lng: wpgmaps_localize[wpgmaps_mapid].map_start_lng 77 }; 78 79 if(typeof wpgmza_override_zoom !== "undefined") 80 MYMAP.init('#wpgmza_map', myLatLng, parseInt(wpgmza_override_zoom)); 81 else 82 MYMAP.init('#wpgmza_map', myLatLng, parseInt(wpgmaps_localize[wpgmaps_mapid].map_start_zoom)); 83 84 UniqueCode=Math.round(Math.random()*10000); 85 86 MYMAP.placeMarkers(wpgmaps_markerurl+'?u='+UniqueCode,wpgmaps_localize[wpgmaps_mapid].id,null,null,null); 87 88 if(wpgmaps_localize[wpgmaps_mapid].other_settings.store_locator_style == 'modern') 89 { 90 if(!MYMAP.map) 91 return; 92 93 MYMAP.modernStoreLocator = WPGMZA.ModernStoreLocator.createInstance(wpgmaps_mapid); 94 wpgmza_create_places_autocomplete(); 95 } 96} 97 98jQuery(function($) { 99 if (/1\.([0-7])\.([0-9])/.test(jQuery.fn.jquery)) 100 console.warn("You are running a version of jQuery which may not be compatible with WP Google Maps."); 101 102 // Fastclick adapation 103 jQuery(document).on({'DOMNodeInserted': function() { 104 jQuery('.pac-item, .pac-item span', this).addClass('needsclick'); 105 } 106 }, '.pac-container'); 107 108 var temp; 109 var selector = "#wpgmza_map"; 110 var mapElement = jQuery(selector); 111 112 var width = wpgmaps_localize[wpgmaps_mapid]['map_width']+wpgmaps_localize[wpgmaps_mapid]['map_width_type']; 113 var height = wpgmaps_localize[wpgmaps_mapid]['map_height']+wpgmaps_localize[wpgmaps_mapid]['map_height_type']; 114 115 if((temp = mapElement.attr("data-shortcode-width")) != "inherit") 116 width = temp; 117 if((temp = mapElement.attr("data-shortcode-height")) != "inherit") 118 height = temp; 119 120 mapElement.css({ 121 width: width, 122 height: height 123 }); 124 125 InitMap(); 126 jQuery('body').on('tabsactivate', function(){setTimeout(function(){InitMap();}, 500); }); 127 jQuery('body').on('tabsshow', function(){setTimeout(function(){InitMap();}, 500); }); 128 jQuery('body').on('accordionactivate', function(){setTimeout(function(){InitMap();}, 500); }); 129 jQuery('body').on('click', '.wpb_tabs_nav li', function(){setTimeout(function(){InitMap();}, 500); }); 130 jQuery('body').on('click', '.ui-tabs-nav li', function(event, ui) { InitMap(); }); 131 jQuery('body').on('click', '.tp-tabs li a', function(event, ui) { InitMap(); }); 132 jQuery('body').on('click', '.nav-tabs li a', function(event, ui) { InitMap(); }); 133 jQuery('body').on('click', '.vc_tta-panel-heading', function(){setTimeout(function(){InitMap();}, 500); }); 134 jQuery('body').on('click', '.ult_exp_section',function(){setTimeout(function(){InitMap();}, 500); }); 135 jQuery('body').on('click', '.x-accordion-heading', function(){setTimeout(function(){InitMap();}, 500); }); 136 jQuery('body').on('click', '.x-nav-tabs li', function(){setTimeout(function(){InitMap();}, 500); }); 137 jQuery('body').on('click', '.tab-title', function(){setTimeout(function(){InitMap();}, 500); }); 138 jQuery('body').on('click', '.tab-link', function(){setTimeout(function(){InitMap();}, 500); }); 139 jQuery('body').on('click', '.et_pb_tabs_controls li', function(){setTimeout(function(){InitMap();}, 500); }); 140 jQuery('body').on('click', '.fusion-tab-heading', function(){setTimeout(function(){InitMap();}, 500); }); 141 jQuery('body').on('click', '.et_pb_tab', function(){setTimeout(function(){InitMap();}, 500); }); 142 jQuery('body').on('click', '.tri-tabs-nav span', function(){setTimeout(function(){InitMap();}, 500); }); 143 jQuery('body').on('click', '.gdl-tabs li', function(){setTimeout(function(){InitMap();}, 500); }); 144 jQuery('body').on('click', '#tabnav li', function(){setTimeout(function(){InitMap();}, 500); }); 145}); 146 147var MYMAP = { 148 map: null, 149 bounds: null 150} 151 152if (wpgmaps_localize_global_settings['wpgmza_settings_map_draggable'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_draggable']) { wpgmza_settings_map_draggable = true; } else { wpgmza_settings_map_draggable = false; } 153if (wpgmaps_localize_global_settings['wpgmza_settings_map_clickzoom'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_clickzoom']) { wpgmza_settings_map_clickzoom = false; } else { wpgmza_settings_map_clickzoom = true; } 154if (wpgmaps_localize_global_settings['wpgmza_settings_map_scroll'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_scroll']) { wpgmza_settings_map_scroll = true; } else { wpgmza_settings_map_scroll = false; } 155if (wpgmaps_localize_global_settings['wpgmza_settings_map_zoom'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_zoom']) { wpgmza_settings_map_zoom = true; } else { wpgmza_settings_map_zoom = false; } 156if (wpgmaps_localize_global_settings['wpgmza_settings_map_pan'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_pan']) { wpgmza_settings_map_pan = true; } else { wpgmza_settings_map_pan = false; } 157if (wpgmaps_localize_global_settings['wpgmza_settings_map_type'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_type']) { wpgmza_settings_map_type = true; } else { wpgmza_settings_map_type = false; } 158if (wpgmaps_localize_global_settings['wpgmza_settings_map_streetview'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_streetview']) { wpgmza_settings_map_streetview = true; } else { wpgmza_settings_map_streetview = false; } 159if (wpgmaps_localize_global_settings['wpgmza_settings_map_full_screen_control'] === "" || 'undefined' === typeof wpgmaps_localize_global_settings['wpgmza_settings_map_full_screen_control']) { wpgmza_settings_map_full_screen_control = true; } else { wpgmza_settings_map_full_screen_control = false; } 160 161if ('undefined' === typeof wpgmaps_localize[wpgmaps_mapid]['other_settings']['map_max_zoom'] || wpgmaps_localize[wpgmaps_mapid]['other_settings']['map_max_zoom'] === "") { wpgmza_max_zoom = 0; } else { wpgmza_max_zoom = parseInt(wpgmaps_localize[wpgmaps_mapid]['other_settings']['map_max_zoom']); } 162if ('undefined' === typeof wpgmaps_localize[wpgmaps_mapid]['other_settings']['map_min_zoom'] || wpgmaps_localize[wpgmaps_mapid]['other_settings']['map_min_zoom'] === "") { wpgmza_min_zoom = 21; } else { wpgmza_min_zoom = parseInt(wpgmaps_localize[wpgmaps_mapid]['other_settings']['map_min_zoom']); } 163 164function wpgmza_create_places_autocomplete() { 165 166 var element = document.getElementById("addressInput"); 167 168 if(!element) 169 return; 170 171 if(!window.google) 172 return; 173 174 if(!google.maps) 175 return; 176 177 if(!google.maps.places || !google.maps.places.Autocomplete) 178 return; 179 180 if(WPGMZA.settings.engine != "google-maps") 181 return; 182 183 var options = { 184 fields: ["name", "formatted_address"], 185 types: ["geocode"] 186 }; 187 188 var restriction = wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_store_locator_restrict']; 189 190 if(restriction) 191 options.componentRestrictions = { 192 country: restriction 193 }; 194 195 autocomplete = new google.maps.places.Autocomplete(element, options); 196 google.maps.event.addListener(autocomplete, 'place_changed', function() { 197 fillInAddress(); 198 }); 199} 200 201MYMAP.init = function(selector, latLng, zoom) { 202 203 var maptype = null; 204 205 if(window.google) 206 { 207 if (typeof wpgmaps_localize[wpgmaps_mapid].type !== "undefined") { 208 if (wpgmaps_localize[wpgmaps_mapid].type === "1") { maptype = google.maps.MapTypeId.ROADMAP; } 209 else if (wpgmaps_localize[wpgmaps_mapid].type === "2") { maptype = google.maps.MapTypeId.SATELLITE; } 210 else if (wpgmaps_localize[wpgmaps_mapid].type === "3") { maptype = google.maps.MapTypeId.HYBRID; } 211 else if (wpgmaps_localize[wpgmaps_mapid].type === "4") { maptype = google.maps.MapTypeId.TERRAIN; } 212 else { maptype = google.maps.MapTypeId.ROADMAP; } 213 } else { 214 maptype = google.maps.MapTypeId.ROADMAP; 215 } 216 } 217 218 var myOptions = { 219 zoom:zoom, 220 minZoom: wpgmza_max_zoom,
221 maxZoom: wpgmza_min_zoom, 222 center: latLng, 223 zoomControl: wpgmza_settings_map_zoom, 224 panControl: wpgmza_settings_map_pan, 225 mapTypeControl: wpgmza_settings_map_type, 226 streetViewControl: wpgmza_settings_map_streetview, 227 draggable: wpgmza_settings_map_draggable, 228 disableDoubleClickZoom: wpgmza_settings_map_clickzoom, 229 scrollwheel: wpgmza_settings_map_scroll, 230 fullscreenControl: wpgmza_settings_map_full_screen_control, 231 mapTypeId: maptype 232 } 233 234 if(typeof wpgmza_force_greedy_gestures !== "undefined"){ 235 myOptions.gestureHandling = wpgmza_force_greedy_gestures; 236 } 237 238 // NB: Perry: Moved this block up here and altered it so it plays nicely with other maps styles settings 239 if ("undefined" !== typeof wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_theme_data'] && wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_theme_data'] !== false && wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_theme_data'] !== "") { 240 if(!myOptions.styles) 241 myOptions.styles = []; 242 243 wpgmza_theme_data = wpgmza_parse_theme_data(wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_theme_data']); 244 myOptions.styles = myOptions.styles.concat(wpgmza_theme_data); 245 } 246 247 if(!wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_show_points_of_interest']) 248 { 249 // Only create a new array if styles aren't set already, so no existing styles are overwritten 250 if(!myOptions.styles) 251 myOptions.styles = []; 252 253 // Push a style to hide all points of interest 254 myOptions.styles.push( 255 { 256 featureType: "poi", 257 stylers: [{visibility: "off"}] 258 } 259 ); 260 } 261 262 var element = jQuery(selector)[0]; 263 264 // DIVI compatibility fix 265 if(!element) 266 return; 267 268 element.setAttribute("data-map-id", 1); 269 element.setAttribute("data-maps-engine", WPGMZA.settings.engine); 270 this.map = WPGMZA.Map.createInstance(element, myOptions); 271 this.bounds = new WPGMZA.LatLngBounds(); 272 273 if(MYMAP.modernStoreLocator) 274 { 275 MYMAP.modernStoreLocator.element.index = 1; 276 this.map.controls[google.maps.ControlPosition.TOP_CENTER].push(MYMAP.modernStoreLocator.element); 277 wpgmza_create_places_autocomplete(); 278 } 279 280 /*var map = this.map; 281 google.maps.event.addDomListener(window, "resize", function() { 282 var center = map.getCenter(); 283 google.maps.event.trigger(map, "resize"); 284 map.setCenter(center); 285 });*/ 286 287 jQuery( "#wpgmza_map").trigger( 'wpgooglemaps_loaded' ); 288 289 if (wpgmaps_localize_polygon_settings !== null) { 290 if (typeof wpgmaps_localize_polygon_settings !== "undefined") { 291 for(var poly_entry in wpgmaps_localize_polygon_settings) { 292 add_polygon(poly_entry); 293 } 294 } 295 } 296 if (wpgmaps_localize_polyline_settings !== null) { 297 if (typeof wpgmaps_localize_polyline_settings !== "undefined") { 298 for(var poly_entry in wpgmaps_localize_polyline_settings) { 299 add_polyline(poly_entry); 300 } 301 } 302 } 303 304 if(WPGMZA.settings.engine == "google-maps") 305 { 306 if (wpgmaps_localize[wpgmaps_mapid]['bicycle'] === "1") { 307 var bikeLayer = new google.maps.BicyclingLayer(); 308 bikeLayer.setMap(MYMAP.map.googleMap); 309 } 310 if (wpgmaps_localize[wpgmaps_mapid]['traffic'] === "1") { 311 var trafficLayer = new google.maps.TrafficLayer(); 312 trafficLayer.setMap(MYMAP.map.googleMap); 313 } 314 315 if ("undefined" !== typeof wpgmaps_localize[wpgmaps_mapid]['other_settings']['transport_layer'] && wpgmaps_localize[wpgmaps_mapid]['other_settings']['transport_layer'] === 1) { 316 var transitLayer = new google.maps.TransitLayer(); 317 transitLayer.setMap(MYMAP.map.googleMap); 318 } 319 } 320 321 if(window.wpgmza_circle_data_array) { 322 window.circle_array = []; 323 324 for(var circle_id in wpgmza_circle_data_array) { 325 326 // Check that this belongs to the array itself, as opposed to its prototype, or else this will break if you add methods to the array prototype (please don't extend the native types) 327 if(!wpgmza_circle_data_array.hasOwnProperty(circle_id)) 328 continue; 329 330 add_circle(1, wpgmza_circle_data_array[circle_id]); 331 } 332 } 333 334 if(window.wpgmza_rectangle_data_array) { 335 window.rectangle_array = []; 336 337 for(var rectangle_id in wpgmza_rectangle_data_array) { 338 339 // Check that this belongs to the array itself, as opposed to its prototype, or else this will break if you add methods to the array prototype (please don't extend the native types) 340 if(!wpgmza_rectangle_data_array.hasOwnProperty(rectangle_id)) 341 continue; 342 343 add_rectangle(1, wpgmza_rectangle_data_array[rectangle_id]); 344 345 } 346 } 347 348 MYMAP.map.on("click", function(event) { 349 if(event.target instanceof WPGMZA.Marker) 350 return; 351 352 if(window.infoWindow) 353 infoWindow.close(); 354 });
355 356 window.addEventListener("keydown", function(e) { 357 var k = (e.which ? e.which : e.keyCode); 358 if(k == 27) 359 infoWindow.close(); 360 }); 361} 362 363function wpgmza_init_infowindow() 364{ 365 if(!window.WPGMZA) 366 return; 367 368 window.infoWindow = WPGMZA.InfoWindow.createInstance(); 369 370 if(wpgmaps_localize_global_settings['wpgmza_settings_infowindow_width'] && wpgmaps_localize_global_settings['wpgmza_settings_infowindow_width'].length) 371 infoWindow.setOptions({maxWidth: wpgmaps_localize_global_settings['wpgmza_settings_infowindow_width']}); 372} 373 374function wpgmza_get_zoom_from_radius(radius, units) 375{ 376 // With thanks to Jeff Jason http://jeffjason.com/2011/12/google-maps-radius-to-zoom/ 377 378 if(units == WPGMZA.Distance.MILES) 379 radius *= WPGMZA.Distance.KILOMETERS_PER_MILE; 380 381 return Math.round(14-Math.log(radius)/Math.LN2); 382} 383 384var wpgmza_last_default_circle = null; 385 386function wpgmza_show_store_locator_radius(map_id, center, radius, distance_type) 387{ 388 var style = wpgmaps_localize[map_id].other_settings.wpgmza_store_locator_radius_style; 389 390 // Force legacy style on iOS, it appears CanvasLayer crashes some iOS devices 391 if(WPGMZA.isDeviceiOS()) 392 style = "legacy"; 393 394 switch(style) 395 { 396 case "modern": 397 if(MYMAP.modernStoreLocatorCircle) 398 MYMAP.modernStoreLocatorCircle.destroy(); 399 400 MYMAP.modernStoreLocatorCircle = WPGMZA.ModernStoreLocatorCircle.createInstance(map_id); 401 402 MYMAP.modernStoreLocatorCircle.setOptions({ 403 visible: true, 404 center: center, 405 radius: radius * (distance_type == 1 ? WPGMZA.Distance.KILOMETERS_PER_MILE : 1), 406 radiusString: radius 407 }); 408 409 break; 410 411 default: 412 var options = { 413 strokeColor: '#FF0000', 414 strokeOpacity: 0.25, 415 strokeWeight: 2,
416 fillColor: '#FF0000', 417 fillOpacity: 0.15, 418 map: MYMAP.map, 419 center: center 420 }; 421 422 if (distance_type == "1") 423 options.radius = parseInt(radius / 0.000621371); 424 else 425 options.radius = parseInt(radius / 0.001); 426 427 if(typeof wpgmza_last_default_circle !== "undefined" && wpgmza_last_default_circle !== null){ 428 wpgmza_last_default_circle.setMap(null); 429 wpgmza_last_default_circle = null; 430 } 431 432 wpgmza_last_default_circle = WPGMZA.Circle.createInstance(options); 433 break; 434 } 435} 436 437MYMAP.placeMarkers = function(filename,map_id,radius,searched_center,distance_type) { 438 var check1 = 0, 439 slNotFoundMessage = jQuery('.js-not-found-msg'); 440 if (wpgmaps_localize_global_settings.wpgmza_settings_marker_pull === '1') { 441 jQuery.get(filename, function(xml){ 442 jQuery(xml).find("marker").each(function(){ 443 var wpmgza_map_id = jQuery(this).find('map_id').text(); 444 445 if (wpmgza_map_id == map_id) { 446 var wpmgza_address = jQuery(this).find('address').text(); 447 var lat = jQuery(this).find('lat').text(); 448 var lng = jQuery(this).find('lng').text(); 449 var wpmgza_anim = jQuery(this).find('anim').text(); 450 var wpmgza_infoopen = jQuery(this).find('infoopen').text(); 451 var current_lat = jQuery(this).find('lat').text(); 452 var current_lng = jQuery(this).find('lng').text(); 453 var show_marker_radius = true; 454 var wpmgza_marker_id = jQuery(this).find('marker_id').text(); 455 456 if (radius !== null) { 457 458 var R = 0; 459 if (distance_type == "1") { 460 R = 3958.7558657440545; 461 } else { 462 R = 6378.16; 463 } 464 var dLat = toRad(searched_center.lat-current_lat); 465 var dLon = toRad(searched_center.lng-current_lng); 466 var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(toRad(current_lat)) * Math.cos(toRad(searched_center.lat)) * Math.sin(dLon/2) * Math.sin(dLon/2); 467 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 468 var d = R * c; 469 470 if (d < radius) { show_marker_radius = true; } else { show_marker_radius = false; } 471 } 472 473 var point = new WPGMZA.LatLng(parseFloat(lat),parseFloat(lng)); 474 475 // MYMAP.bounds.extend(point); 476 477 if (show_marker_radius === true) { 478 479 var options = { 480 position: point, 481 map: MYMAP.map 482 } 483 484 if(wpmgza_anim) 485 options.animation = wpmgza_anim; 486 487 var marker = WPGMZA.Marker.createInstance(options); 488 489 var d_string = ""; 490 if (radius !== null) { 491 if (distance_type == "1") { 492 d_string = "<p style='min-width:100px; display:block;'>"+Math.round(d,2)+" "+wpgmaps_lang_m_away+"</p>"; 493 } else { 494 d_string = "<p style='min-width:100px; display:block;'>"+Math.round(d,2)+" "+wpgmaps_lang_km_away+"</p>"; 495 } 496 } else { d_string = ''; } 497 498 499 var html='<span style=\'min-width:100px; display:block;\'>'+wpmgza_address+'</span>'+d_string; 500 if (wpmgza_infoopen === "1" && !wpgmaps_localize_global_settings["wpgmza_settings_disable_infowindows"]) { 501 502 if(!window.infoWindow) 503 wpgmza_init_infowindow(); 504 505 infoWindow.setContent(html); 506 infoWindow.open(MYMAP.map, marker); 507 } 508 509 temp_actiontype = 'click'; 510 511 if (typeof wpgmaps_localize_global_settings.wpgmza_settings_map_open_marker_by !== "undefined" && wpgmaps_localize_global_settings.wpgmza_settings_map_open_marker_by == '2') { 512 temp_actiontype = 'mouseover'; 513 } 514 515 if(WPGMZA.isTouchDevice()) 516 temp_actiontype = "click"; 517 518 marker.on(temp_actiontype, function() { 519 if(window.infoWindow) 520 infoWindow.close(); 521 if(!wpgmaps_localize_global_settings["wpgmza_settings_disable_infowindows"]) 522 { 523 if(!window.infoWindow) 524 wpgmza_init_infowindow(); 525 526 infoWindow.setContent(html); 527 infoWindow.open(MYMAP.map, marker); 528 } 529 }); 530 531 marker_array[wpmgza_marker_id] = marker; 532 } 533 } 534 }); 535 536 }); 537 } else { 538 539 if (Object.keys(wpgmaps_localize_marker_data).length > 0) { 540 var markerStoreLocatorsNum = 0; 541 542 if (typeof wpgmaps_localize_marker_data !== "undefined") { 543 544 jQuery.each(wpgmaps_localize_marker_data, function(i, val) { 545 546 var wpmgza_map_id = val.map_id; 547 548 if (wpmgza_map_id == map_id) { 549 550 var wpmgza_address = val.address; 551 var wpmgza_anim = val.anim; 552 var wpmgza_infoopen = val.infoopen; 553 var lat = val.lat; 554 var lng = val.lng; 555 var point = new WPGMZA.LatLng(lat, lng); 556 var wpmgza_marker_id = val.marker_id; 557 558 559 var current_lat = val.lat; 560 var current_lng = val.lng; 561 var show_marker_radius = true; 562 563 if (radius !== null) { 564 if (check1 > 0 ) { } else { 565 566 567 var point = searched_center; 568 // MYMAP.bounds.extend(point); 569 if (typeof wpgmaps_localize[wpgmaps_mapid]['other_settings']['store_locator_bounce'] === "undefined" || wpgmaps_localize[wpgmaps_mapid]['other_settings']['store_locator_bounce'] === 1) { 570 var marker = WPGMZA.Marker.createInstance({ 571 position: point, 572 map: MYMAP.map/*, 573 animation: google.maps.Animation.BOUNCE*/ 574 }); 575 marker_sl = marker; 576 } else { /* dont show icon */ } 577 578 wpgmza_show_store_locator_radius(map_id, point, radius, distance_type); 579 580 check1 = check1 + 1; 581 } 582 var R = 0; 583 if (distance_type == "1") { 584 R = 3958.7558657440545; 585 } else { 586 R = 6378.16; 587 } 588 var dLat = toRad(searched_center.lat-current_lat); 589 var dLon = toRad(searched_center.lng-current_lng); 590 var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.
590cos(toRad(current_lat)) * Math.cos(toRad(searched_center.lat)) * Math.sin(dLon/2) * Math.sin(dLon/2); 591 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 592 var d = R * c; 593 594 if (d < radius) { 595 show_marker_radius = true; 596 markerStoreLocatorsNum++; 597 } else { 598 show_marker_radius = false; 599 } 600 } 601 602 var point = { 603 lat: parseFloat(lat), 604 lng: parseFloat(lng) 605 }; 606 607 // Prevent JS error in Gutenberg editor (Temporary fix) 608 if(WPGMZA.is_admin == "1") 609 return; 610 611 if (show_marker_radius === true) { 612 613 var marker = WPGMZA.Marker.createInstance({ 614 position: point, 615 map: MYMAP.map 616 }); 617 618 if(wpmgza_anim) 619 marker.setAnimation(wpmgza_anim); 620 621 var d_string = ""; 622 if (radius !== null) { 623 if (distance_type == "1") { 624 d_string = "<p style='min-width:100px; display:block;'>"+Math.round(d,2)+" "+wpgmaps_lang_m_away+"</p>"; 625 } else { 626 d_string = "<p style='min-width:100px; display:block;'>"+Math.round(d,2)+" "+wpgmaps_lang_km_away+"</p>"; 627 } 628 } else { d_string = ''; } 629 630 631 var html='<span>'+wpmgza_address+'</span>'+d_string; 632 if (wpmgza_infoopen === "1" && !wpgmaps_localize_global_settings["wpgmza_settings_disable_infowindows"]) { 633 wpgmza_init_infowindow(); 634 635 infoWindow.setContent(html); 636 infoWindow.open(MYMAP.map, marker); 637 } 638 temp_actiontype = 'click'; 639 if (typeof wpgmaps_localize_global_settings.wpgmza_settings_map_open_marker_by !== "undefined" && wpgmaps_localize_global_settings.wpgmza_settings_map_open_marker_by == '2') { 640 temp_actiontype = 'mouseover'; 641 } 642 643 if(WPGMZA.isTouchDevice()) 644 temp_actiontype = "click"; 645 646 //google.maps.event.addListener(marker, temp_actiontype, function() { 647 marker.on(temp_actiontype, function(event) { 648 /*if(window.infoWindow) 649 infoWindow.close(); 650 if(!wpgmaps_localize_global_settings["wpgmza_settings_disable_infowindows"]) 651 { 652 wpgmza_init_infowindow(); 653 654 infoWindow.setContent(html); 655 infoWindow.open(MYMAP.map, marker); 656 }*/ 657 658 this.openInfoWindow(); 659 this.infoWindow.setContent(html); 660 }); 661 662 marker_array[wpmgza_marker_id] = marker; 663 } 664 } 665 }); 666 667 if ('' !== jQuery('#addressInput').val() && markerStoreLocatorsNum < 1) { 668 slNotFoundMessage.addClass('is-active'); 669 setTimeout(function () { 670 slNotFoundMessage.removeClass('is-active'); 671 }, 5000); 672 } 673 } 674 } 675 } 676 677 if (check1 == 0 && radius) { 678 var point = new WPGMZA.LatLng(parseFloat(searched_center.lat),parseFloat(searched_center.lng)); 679 // MYMAP.bounds.extend(point); 680 if (typeof wpgmaps_localize[wpgmaps_mapid]['other_settings']['store_locator_bounce'] === "undefined" || wpgmaps_localize[wpgmaps_mapid]['other_settings']['store_locator_bounce'] === 1) { 681 var marker = WPGMZA.Marker.createInstance({ 682 position: point, 683 map: MYMAP.map, 684 animation: WPGMZA.Marker.ANIMATION_BOUNCE 685 }) 686 687 marker_sl = marker; 688 } 689 690 wpgmza_show_store_locator_radius(map_id, point, radius, distance_type); 691 692 check1 = check1 + 1; 693 } 694} 695 696function add_polygon(polygonid) { 697 698 if(WPGMZA.settings.engine != "google-maps") 699 return; 700 701 var tmp_data = wpgmaps_localize_polygon_settings[polygonid]; 702 var current_poly_id = polygonid; 703 var tmp_polydata = tmp_data['polydata']; 704 var WPGM_PathData = new Array(); 705 for (tmp_entry2 in tmp_polydata) { 706 if (typeof tmp_polydata[tmp_entry2][0] !== "undefined") { 707 708 WPGM_PathData.push(new google.maps.LatLng(tmp_polydata[tmp_entry2][0], tmp_polydata[tmp_entry2][1])); 709 } 710 } 711 if (tmp_data['lineopacity'] === null || tmp_data['lineopacity'] === "") { 712 tmp_data['lineopacity'] = 1; 713 } 714 715 var bounds = new google.maps.LatLngBounds(); 716 for (i = 0; i < WPGM_PathData.length; i++) { 717 bounds.extend(WPGM_PathData[i]); 718 } 719 720 WPGM_Path_Polygon[polygonid] = new google.maps.Polygon({ 721 path: WPGM_PathData, 722 clickable: true, /* must add option for this */ 723 strokeColor: "#"+tmp_data['linecolor'], 724 fillOpacity: tmp_data['opacity'], 725 strokeOpacity: tmp_data['lineopacity'], 726 fillColor: "#"+tmp_data['fillcolor'], 727 strokeWeight: 2, 728 map: MYMAP.map.googleMap 729 }); 730 WPGM_Path_Polygon[polygonid].setMap(MYMAP.map.googleMap); 731 732 polygon_center = bounds.getCenter(); 733 734 if (tmp_data['title'] !== "") { 735 infoWindow_poly[polygonid] = new google.maps.InfoWindow(); 736 google.maps.event.addListener(WPGM_Path_Polygon[polygonid], 'click', function(event) { 737 infoWindow_poly[polygonid].setPosition(event.latLng); 738 content = ""; 739 if (tmp_data['link'] !== "") { 740 var content = "<a href='"+tmp_data['link']+"'>"+tmp_data['title']+"</a>"; 741 } else { 742 var content = tmp_data['title']; 743 } 744 if(!wpgmaps_localize_global_settings["wpgmza_settings_disable_infowindows"]) 745 { 746 infoWindow_poly[polygonid].setContent(content); 747 infoWindow_poly[polygonid].open(MYMAP.map,this.position); 748 } 749 }); 750 } 751 752 753 754} 755function add_polyline(polyline) { 756 757 if(WPGMZA.settings.engine != "google-maps") 758 return; 759 760 var tmp_data = wpgmaps_localize_polyline_settings[polyline]; 761 762 var current_poly_id = polyline; 763 var tmp_polydata = tmp_data['polydata']; 764 var WPGM_Polyline_PathData = new Array(); 765 for (tmp_entry2 in tmp_polydata) { 766 if (typeof tmp_polydata[tmp_entry2][0] !== "undefined" && typeof tmp_polydata[tmp_entry2][1] !== "undefined") { 767 var lat = tmp_polydata[tmp_entry2][0].replace(')', ''); 768 lat = lat.replace('(',''); 769 var lng = tmp_polydata[tmp_entry2][1].replace(')', ''); 770 lng = lng.replace('(',''); 771 WPGM_Polyline_PathData.push(new google.maps.LatLng(lat, lng)); 772 } 773 774 775 } 776 if (tmp_data['lineopacity'] === null || tmp_data['lineopacity'] === "") { 777 tmp_data['lineopacity'] = 1; 778 } 779 780 WPGM_Path[polyline] = new google.maps.Polyline({ 781 path: WPGM_Polyline_PathData, 782 strokeColor: "#"+tmp_data['linecolor'], 783 strokeOpacity: tmp_data['opacity'], 784 strokeWeight: tmp_data['linethickness'], 785 map: MYMAP.map.googleMap 786 }); 787 WPGM_Path[polyline].setMap(MYMAP.map.googleMap); 788 789 790} 791 792 793jQuery("body").on("keypress","#addressInput", function(event) { 794 if ( event.which == 13 ) { 795 jQuery('.wpgmza_sl_search_button').trigger('click'); 796 } 797}); 798var autocomplete; 799function fillInAddress() { 800 // Get the place details from the autocomplete object. 801 //var place = autocomplete.getPlace(); 802} 803 804jQuery(window).on("load", function() { 805 wpgmza_create_places_autocomplete(); 806}); 807 808 809function searchLocations(map_id) { 810 var address = document.getElementById("addressInput").value; 811 812 if(address.length == 0) 813 { 814 document.getElementById("addressInput").focus(); 815 return; 816 } 817 818 //var geocoder = new google.maps.Geocoder(); 819 var geocoder = WPGMZA.Geocoder.createInstance(); 820 821 var options = { 822 address: address 823 }; 824 825 var restrict = wpgmaps_localize[wpgmaps_mapid]['other_settings']['wpgmza_store_locator_restrict']; 826 if(restrict && restrict.length) 827 options.componentRestrictions = { 828 country: restrict 829 }; 830 831 geocoder.geocode(options, function(results, status) { 832 833 var event = { 834 type: "storelocatorgeocodecomplete",
835 results: results, 836 status: status 837 }; 838 839 MYMAP.map.trigger(event); 840 841 if(status == WPGMZA.Geocoder.SUCCESS) 842 { 843 searchLocationsNear(map_id,results[0].geometry.location); 844 } 845 else 846 { 847 alert(address + ' not found'); 848 } 849 850 }); 851} 852function clearLocations() { 853 if(window.infoWindow) 854 infoWindow.close(); 855} 856function searchLocationsNear(mapid,center_searched) { 857 clearLocations(); 858 var distance_type = wpgmaps_localize[mapid].other_settings.store_locator_distance; 859 860 var radius = document.getElementById('radiusSelect').value; 861 var zoomie = wpgmza_get_zoom_from_radius(radius); 862 863 MYMAP.map.setCenter(center_searched); 864 MYMAP.map.setZoom(zoomie); 865 if (typeof marker_array !== "undefined") { 866 jQuery.each(marker_array,function(i,v){ 867 /* remove any instance of a marker first tio avoid using a full reinit which causes the map to flicker */ 868 if (typeof v !== 'undefined') { 869 870 v.setMap(null); 871 /* Check which map we are working on, and only reset the correct markers. (Store locator, etc) */ 872 } 873 }); 874 } 875 if (marker_sl !== null){ 876 marker_sl.setMap(null); 877 } 878 MYMAP.placeMarkers(wpgmaps_markerurl+'?u='+UniqueCode,wpgmaps_localize[wpgmaps_mapid].id,radius,center_searched,distance_type); 879 880 var event = { 881 type: "storelocatorresult", 882 position: center_searched 883 }; 884 885 MYMAP.map.trigger(event); 886} 887 888function toRad(Value) { 889 /** Converts numeric degrees to radians */ 890 return Value * Math.PI / 180; 891} 892 893(function($) { 894 895 if(!window.WPGMZA) 896 return; 897 898 WPGMZA.hexToRgba = function(hex) { 899 var c; 900 if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){ 901 c= hex.substring(1).split(''); 902 if(c.length== 3){ 903 c= [c[0], c[0], c[1], c[1], c[2], c[2]]; 904 } 905 c= '0x'+c.join(''); 906 907 return { 908 r: (c>>16)&255, 909 g: (c>>8)&255, 910 b: c&255, 911 a: 1 912 }; 913 } 914 throw new Error('Bad Hex'); 915 } 916 917 WPGMZA.rgbaToString = function(rgba) { 918 return "rgba(" + rgba.r + ", " + rgba.g + ", " + rgba.b + ", " + rgba.a + ")"; 919 } 920 921 // GoogleAPIErrorHandler moved to /js/v8/google-api-error-handler.js 922 923})(jQuery); 924 925function add_circle(mapid, data) 926{ 927 if(WPGMZA.settings.engine != "google-maps") 928 return; 929 930 data.map = MYMAP.map.googleMap; 931 932 if(!(data.center instanceof google.maps.LatLng)) { 933 934 if(typeof data.center != "string") 935 return; 936 937 var m = data.center.match(/-?\d+(\.\d*)?/g); 938 data.center = new google.maps.LatLng({ 939 lat: parseFloat(m[0]), 940 lng: parseFloat(m[1]), 941 }); 942 } 943 944 data.radius = parseFloat(data.radius); 945 data.fillColor = data.color; 946 data.fillOpacity = parseFloat(data.opacity); 947 948 data.strokeOpacity = 0; 949 950 var circle = new google.maps.Circle(data); 951 circle_array.push(circle); 952} 953 954function add_rectangle(mapid, data) 955{ 956 if(WPGMZA.settings.engine != "google-maps") 957 return; 958 959 data.map = MYMAP.map.googleMap; 960 961 data.fillColor = data.color; 962 data.fillOpacity = parseFloat(data.opacity); 963 964 var northWest = data.cornerA; 965 var southEast = data.cornerB; 966 967 var m = northWest.match(/-?\d+(\.\d+)?/g); 968 var north = parseFloat(m[0]); 969 var west = parseFloat(m[1]); 970 971 m = southEast.match(/-?\d+(\.\d+)?/g); 972 var south = parseFloat(m[0]); 973 var east = parseFloat(m[1]); 974 975 data.bounds = { 976 north: north, 977 west: west, 978 south: south, 979 east: east 980 }; 981 982 data.strokeOpacity = 0; 983 984 var rectangle = new google.maps.Rectangle(data); 985 rectangle_array.push(rectangle); 986}
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.