1(function( $ ) { 2 'use strict'; 3 4 // Create the defaults once 5 var pluginName = "storeLocatorSingle", 6 defaults = { 7 map_min_height: 300, 8 earthRadi: { 9 mi: 3963.1676, 10 km: 6378.1, 11 ft: 20925524.9, 12 mt: 6378100, 13 "in": 251106299, 14 yd: 6975174.98, 15 fa: 3487587.49, 16 na: 3443.89849, 17 ch: 317053.408, 18 rd: 1268213.63, 19 fr: 31705.3408 20 }, 21 }; 22 23 // The actual plugin constructor 24 function Plugin ( element, options ) { 25 this.element = element; 26 this.settings = $.extend( {}, defaults, options ); 27 this._defaults = defaults; 28 29 this.settings.lat = $(element).data('lat'); 30 this.settings.lng = $(element).data('lng'); 31 32 this._name = pluginName; 33 this.init(); 34 } 35 36 // Avoid Plugin.prototype conflicts 37 $.extend( Plugin.prototype, { 38 init: function() { 39 var that = this; 40 this.window = $(window); 41 this.documentHeight = $( document ).height(); 42 this.windowHeight = this.window.height(); 43 this.settings.singleStoreShowMapZoom = parseInt(that.settings.singleStoreShowMapZoom); 44 this.templateCache = {}; 45 this.bounds = new google.maps.LatLngBounds(); 46 47 that.initStoreLocatorSingle(); 48 }, 49 initStoreLocatorSingle: function() { 50 var that = this; 51 52 that.initMap(function(){ 53 that.createMarker(); 54 55 if(that.settings.singleStoreLivePosition == "1") { 56 that.createLivePosition(); 57 } 58 }); 59 }, 60 initMap: function(callback) { 61 62 var that = this; 63 64 var mapContainer = $(this.element); 65 var singleStoreShowMapZoom = this.settings.singleStoreShowMapZoom; 66 var mapDefaultType = this.settings.mapDefaultType; 67 var mapDefaultLat = Number(this.settings.lat); 68 var mapDefaultLng = Number(this.settings.lng); 69 70 var mapStyling = this.settings.mapStyling; 71 if( !this.isEmpty(mapStyling) ) { 72 mapStyling = JSON.parse(mapStyling); 73 } else { 74 mapStyling = ""; 75 } 76 77 var options = { 78 zoom: singleStoreShowMapZoom, 79 center: new google.maps.LatLng(mapDefaultLat, mapDefaultLng), 80 mapTypeId: google.maps.MapTypeId[mapDefaultType], 81 scrollwheel: false, 82 styles: mapStyling, 83 mapId: 'store_locator_single_map_render', 84 }; 85 86 if(this.settings.singleStoreShowMapDisablePanControl == "1") { 87 options.panControl = false; 88 } 89 90 if(this.settings.singleStoreShowMapDisableZoomControl == "1") { 91 options.zoomControl = false; 92 } 93 94 if(this.settings.singleStoreShowMapDisableScaleControl == "1") { 95 options.scaleControl = false; 96 } 97 98 if(this.settings.singleStoreShowMapDisableStreetViewControl == "1") { 99 options.streetViewControl = false; 100 } 101 102 if(this.settings.singleStoreShowMapDisableFullscreenControl == "1") { 103 options.fullscreenControl = false; 104 } 105 106 if(this.settings.singleStoreShowMapDisableMapTypeControl == "1") { 107 options.mapTypeControl = false; 108 } 109 110 // Construct Map 111 this.map = new google.maps.Map(mapContainer[0], options); 112 113 callback(); 114 }, 115 createMarker: function() { 116 var marker; 117 var store = {}; 118 119 store.map = this.map; 120 store.position = new google.maps.LatLng(this.settings.lat, this.settings.lng); 121 122 this.bounds.extend(store.position); 123 124 const image = document.createElement("img"); 125 image.src = this.settings.singleStorenMapIcon; 126 image.setAttribute('alt', store.name); 127 var marker = new google.maps.marker.AdvancedMarkerElement({ 128 map: this.map, 129 position: store.position, 130 131 title: store.name, 132 content: image 133 }); 134 135 136 marker.setMap(this.map); 137 }, 138 createLivePosition : function() { 139 140 var that = this; 141 142 if( that.isEmpty(that.settings.live_lat) || that.settings.live_lat == "0" || that.isEmpty(that.settings.live_lng) || that.settings.live_lng == "0") { 143 return; 144 } 145 146 that.liveStore = {}; 147 148 that.liveStore.map = that.map; 149 that.liveStore.position = new google.maps.LatLng(that.settings.live_lat, that.settings.live_lng); 150 that.liveStore.icon = { "url": that.settings.singleStoreLivePositionMapIcon } ; 151 152 that.liveStoreMarker = new google.maps.Marker(that.liveStore); 153 that.liveStoreMarker.setMap(that.map); 154 that.liveStoreMarker.position = false;
155 156 setInterval( function(){ 157 158 jQuery.ajax({ 159 url: that.settings.ajax_url, 160 type: 'post', 161 dataType: 'JSON', 162 data: { 163 action: 'get_single_store_live_position', 164 post_id: that.settings.post_id, 165 }, 166 success : function( response ) { 167 168 var newLatLngKey = response.lat + response.lng; 169 var newPosition = new google.maps.LatLng(response.lat, response.lng); 170 if(that.liveStoreMarker.latLngKey == newLatLngKey) { 171 return; 172 } 173 174 that.liveStoreMarker.latLngKey = newLatLngKey; 175 176 that.liveStoreMarker.setPosition(newPosition); 177 178 that.bounds.extend(newPosition); 179 that.map.fitBounds(that.bounds); 180 }, 181 error: function(jqXHR, textStatus, errorThrown) { 182 183 alert('An Error Occured: ' + jqXHR.status + ' ' + errorThrown + '! Please contact System Administrator!'); 184 } 185 }); 186 187 }, that.settings.singleStoreLivePositionInterval); 188 189 190// // 1. Create a marker and keep a reference to it: 191 192// var latLng = new google.maps.LatLng(-12.042, -77.028333), 193// marker = new google.maps.Marker({ position: latLng , map: map }); 194 195// marker.setMap(map); 196 197// // 2. Move it around by setting a new position: 198 199// var newPosition = new google.maps.LatLng(-12.042, -78.028333); 200// marker.setPosition(newPosition); 201 202 }, 203 ////////////////////// 204 ///Helper Functions/// 205 ////////////////////// 206 isEmpty: function(obj) { 207 208 if (obj == null) return true; 209 if (obj.length > 0) return false; 210 if (obj.length === 0) return true; 211 212 for (var key in obj) { 213 if (hasOwnProperty.call(obj, key)) return false; 214 } 215 216 return true; 217 }, 218 sprintf: function parse(str) { 219 var args = [].slice.call(arguments, 1), 220 i = 0; 221 222 return str.replace(/%s/g, function() { 223 return args[i++]; 224 }); 225 }, 226 getCookie: function(cname) { 227 var name = cname + "="; 228 var ca = document.cookie.split(';'); 229 for(var i=0; i<ca.length; i++) { 230 var c = ca[i]; 231 while (c.charAt(0)==' ') c = c.substring(1); 232 if (c.indexOf(name) === 0) return c.substring(name.length, c.length); 233 } 234 return ""; 235 }, 236 } ); 237 238 // Constructor wrapper 239 $.fn[ pluginName ] = function( options ) { 240 return this.each( function() { 241 if ( !$.data( this, "plugin_" + pluginName ) ) { 242 $.data( this, "plugin_" + 243 pluginName, new Plugin( this, options ) ); 244 } 245 } ); 246 }; 247 248 $(document).ready(function() { 249 250 var mapsLoaded; 251 mapsLoaded = setInterval( function() { 252 if ( typeof google === 'object' && typeof google.maps === 'object' ) { 253 clearInterval( mapsLoaded ); 254 255 $( ".store_locator_single_map_render" ).storeLocatorSingle( 256 store_locator_options 257 ); 258 259 } 260 }, 500 ); 261 262 263 264 } ); 265 266})( jQuery );
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.