1/** 2 * EventON Generate Google Maps Function 3 * @version 4.9.13 4 */ 5 6//return; 7 8(function($){ 9 10// map loader function 11 $.fn.evoGenmaps = function(opt){ 12 13 var defaults = { 14 delay: 0, 15 fnt: 5, 16 cal: '', 17 SC: '', 18 map_canvas_id: '', 19 location_type:'', 20 address:'', 21 styles:'', 22 zoomlevel:'', 23 mapformat:'', 24 scroll:false, 25 iconURL:'', 26 trigger_point: '', 27 }; 28 var options = $.extend({}, defaults, opt); 29 30 //return; 31 32 //console.log(options); 33 34 var geocoder; 35 36 var code = {}; 37 obj = this; 38 code.obj = this; 39 40 mapBox = $('#'+options.map_canvas_id); 41 42 code = { 43 init:function(){ 44 45 // Skip if map box isnât visible or already drawn 46 if (!mapBox.is(':visible') || mapBox.find('.gm-style').length > 0) return; 47 48 mapBox.html( evo_general_params.html.preload_gmap); 49 50 //if( mapBox.hasClass('mDrawn') ) return; 51 52 // set calendar for event 53 options.cal = obj.closest('.ajde_evcal_calendar').length ? obj.closest('.ajde_evcal_calendar') : options.cal; 54 code.process_SC(); 55 56 // various methods to draw map 57 // load map on specified elements directly 58 if(options.fnt==5){ 59 if(options.delay==0){ code.draw_map(); }else{ 60 setTimeout(code.draw_map, options.delay, this); 61 } 62 } 63 64 65 // deprecating rest 4.6 66 // multiple maps at same time 67 if(options.fnt==1){ 68 code.load_gmap(); 69 } 70 71 if(options.fnt==2){ 72 if(options.delay==0){ code.load_gmap(); }else{ 73 setTimeout(code.load_gmap, options.delay, this); 74 } 75 } 76 if(options.fnt==3){ code.load_gmap(); } 77 78 // gmaps on popup 79 if(options.fnt==4){ 80 // check if gmaps should run 81 if( this.attr('data-gmtrig')=='1' && this.attr('data-gmap_status')!='null'){ 82 code.load_gmap(); 83 } 84 } 85 }, 86 // add unique id for map area 87 process_unique_map_id: function(){ 88 var map_element = obj.closest('.eventon_list_event').find('.evo_metarow_gmap'); 89 if (!map_element.length || !map_element.attr('id')) return false; 90 91 var map_element = obj.closest('.eventon_list_event').find('.evo_metarow_gmap'); 92 93 var randomnumber = Math.floor(Math.random() * (99 - 10 + 1)) + 10; 94 options.map_canvas_id = map_element.attr('id') + '_' + randomnumber; 95 map_element.attr('id', options.map_canvas_id); 96 return options.map_canvas_id; 97 }, 98 process_SC: function(){ 99 if (options.SC || !options.cal) return; 100 options.SC = options.cal.evo_shortcode_data(); 101 }, 102 103 // load google map 104 load_gmap: function(){ 105 var SC = options.SC, 106 ev_location = obj.find('.event_location_attrs'), 107 location_type = ev_location.attr('data-location_type'); 108 109 options.address = location_type == 'address' ? ev_location.attr('data-location_address') : ev_location.attr('data-latlng'); 110 options.location_type = location_type == 'address' ? 'add' : 'latlng'; 111 options.iconURL = SC && SC.mapiconurl ? SC.mapiconurl : options.iconURL; 112 113 if (!options.address) { 114 console.log('Location address missing in options.address'); 115 return false; 116 } 117 118 var map_canvas_id = code.process_unique_map_id(); 119 if (!map_canvas_id || !$('#' + map_canvas_id).length) { 120 console.log('Map element with id missing in page'); 121 return false; 122 } 123 124 options.zoomlevel = SC && SC.mapzoom ? parseInt(SC.mapzoom) : 12; 125 options.scroll = SC.mapscroll; 126 options.mapformat = SC.mapformat; 127 128 code.draw_map(); 129 }, 130 131 // final draw 132 draw_map: function(){ 133 134 if(!options.map_canvas_id || $('body').find('#'+options.map_canvas_id).length == 0){ 135 console.log( 'Map element with id missing in page'); return false; 136 } 137 138 // map styles 139 if( typeof gmapstyles !== 'undefined' && gmapstyles != 'default'){ 140 options.styles = JSON.parse(gmapstyles); 141 } 142 143 //console.log(options); 144 145 var myOptions = { 146 mapTypeId: options.mapformat, 147 zoom: options.zoomlevel, 148 scrollwheel: options.scroll != 'false', 149 zoomControl: true, 150 draggable: options.scroll != 'false', 151 mapId: 'DEMO_MAP_ID' 152 // Removed mapId to allow custom styles 153 }; 154 155 var map_canvas = document.getElementById(options.map_canvas_id), 156 map = new google.maps.Map(map_canvas, myOptions), 157 geocoder = new google.maps.Geocoder(); 158 159 // Setup directions services 160 var directionsService = new google.maps.DirectionsService(); 161 var directionsRenderer = new google.maps.DirectionsRenderer({ 162 map: map, 163 panel: document.getElementById('directions-panel-' + options.map_canvas_id) // Text steps panel 164 }); 165 166 // Event listener for directions button 167 $('#get-directions-' + options.map_canvas_id).on('click', function() { 168 var userAddress = $('#user-address-' + options.map_canvas_id).val(); 169 if (!userAddress.trim()) { 170 alert('Please enter a starting address'); 171 return; 172 } 173 174 geocoder.geocode({ 'address': userAddress }, function(userResults, userStatus) { 175 if (userStatus !== google.maps.GeocoderStatus.OK) { 176 alert('Invalid starting address'); 177 return; 178 } 179 180 // Get event location (from options or geocoded) 181 var eventLocation; 182 if (options.location_type === 'latlng' && options.address) { 183 var latlngStr = options.address.split(','); 184 eventLocation = new google.maps.LatLng(parseFloat(latlngStr[0]), parseFloat(latlngStr[1])); 185 } else { 186 // For address type, you'd need to geocode it first or store from earlier results 187 geocoder.geocode({ 'address': options.address }, function(eventResults, eventStatus) { 188 if (eventStatus === google.maps.GeocoderStatus.OK) { 189 eventLocation = eventResults[0].geometry.location; 190 code.renderDirections(directionsService, directionsRenderer, userResults[0].geometry.location, eventLocation); 191 } 192 }); 193 return; 194 } 195 196 code.renderDirections(directionsService, directionsRenderer, userResults[0].geometry.location, eventLocation); 197 }); 198 }); 199 200 // Helper function to render directions (add this as a new method in code object) 201 code.renderDirections = function(directionsService, directionsRenderer, origin, destination) { 202 var request = { 203 origin: origin, 204 destination: destination, 205 travelMode: google.maps.TravelMode.DRIVING // Change to WALKING/BICYCLING if needed 206 }; 207 208 directionsService.route(request, function(result, status) { 209 if (status === google.maps.DirectionsStatus.OK) { 210 directionsRenderer.setDirections(result); 211 } else { 212 alert('Directions could not be calculated: ' + status); 213 } 214 }); 215 }; 216 217 // address from latlng 218 if(options.location_type=='latlng' && options.address !== undefined){ 219 var latlngStr = options.address.split(",",2); 220 var lat = parseFloat(latlngStr[0]); 221 var lng = parseFloat(latlngStr[1]); 222 var latlng = new google.maps.LatLng(lat, lng); 223 224 geocoder.geocode({'latLng': latlng}, function(results, status) { 225 if (status == google.maps.GeocoderStatus.OK) { 226 227 let markerOptions = { 228 map: map, 229 position: latlng 230 }; 231 232 if (options.iconURL && options.iconURL.trim() !== '') { 233 var img = new Image(); 234 img.src = options.iconURL; 235 236 img.onload = function () { 237 var imgWidth = img.width;
238 var imgHeight = img.height; 239 240 var customIcon = document.createElement('div'); 241 customIcon.className = 'custom-marker'; 242 customIcon.style.width = imgWidth + 'px'; 243 customIcon.style.height = imgHeight + 'px'; 244 customIcon.style.backgroundImage = `url(${options.iconURL})`; 245 customIcon.style.backgroundSize = 'cover'; 246 customIcon.style.position = 'absolute'; 247 248 markerOptions.content = customIcon; 249 250 const marker = new google.maps.marker.AdvancedMarkerElement(markerOptions); 251 map.setCenter(marker.position); 252 }; 253 254 img.onerror = function () { 255 console.error("Error loading marker image: " + options.iconURL); 256 const marker = new google.maps.marker.AdvancedMarkerElement(markerOptions); // Default marker 257 map.setCenter(marker.position); 258 }; 259 } else { 260 // No custom icon, use default Google Maps marker 261 const marker = new google.maps.marker.AdvancedMarkerElement(markerOptions); 262 map.setCenter(marker.position); 263 } 264 265 } else { 266 map_canvas.style.display = 'none'; 267 } 268 }); 269 270 }else if(options.address==''){ 271 //console.log('t'); 272 }else{ 273 geocoder.geocode( { 'address': options.address}, function(results, status) { 274 if (status == google.maps.GeocoderStatus.OK) { 275 map.setCenter(results[0].geometry.location); 276 new google.maps.Marker({ 277 map: map, 278 position: results[0].geometry.location, 279 icon: options.iconURL 280 }); 281 282 } else { map_canvas.style.display = 'none'; } 283 }); 284 } 285 286 // mark as map drawn 287 $('#'+ options.map_canvas_id).addClass('mDrawn'); 288 } 289 } 290 291 292 // INIT 293 code.init(); 294 }; 295 296 297// trigger load google map on dynamic map element u4.6.1 298 $.fn.evo_load_gmap = function(opt){ 299 var defs = { map_canvas_id: '', delay: 0, trigger_point: '' }, 300 OO = $.extend({}, defs, opt), 301 EL = this, 302 EL_id = OO.map_canvas_id || EL.attr('id'), 303 location_type = EL.data('location_type') == 'add' ? 'add' : 'latlng', 304 address = location_type == 'add' ? EL.data('address') : EL.data('latlng'), 305 scrollwheel = EL.data('scroll') == 'yes', 306 elms = document.querySelectorAll("[id='" + EL_id + "']"); 307 308 309 // Ensure unique ID 310 if (elms.length > 1) { 311 var randomnumber = Math.floor(Math.random() * (99 - 10 + 1)) + 10; 312 EL_id = EL_id + '_' + randomnumber; 313 EL.attr('id', EL_id); 314 } 315 316 // Determine delay 317 var __delay = OO.delay || EL.data('delay') || 0; 318 319 let mapData = { 320 map_canvas_id: EL_id, 321 cal: OO.cal, 322 fnt: 5, 323 location_type: location_type, 324 address: address, 325 zoomlevel: parseInt(EL.data('zoom')), 326 mapformat: EL.data('mty'), 327 scroll: scrollwheel, 328 iconURL: EL.data('mapicon') || '', 329 delay: __delay, 330 trigger_point: OO.trigger_point 331 }; 332 333 //console.log(mapData); 334 335 // load the map 336 EL.evoGenmaps(mapData); 337 338 339 }; 340 341 342 343}(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.