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