1/** 2 * EventON Generate Google Maps Function 3 * @version 4.9.4 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 //console.log(options); 31 32 var geocoder; 33 34 var code = {}; 35 obj = this; 36 code.obj = this; 37 38 mapBox = $('#'+options.map_canvas_id); 39 40 code = { 41 init:function(){ 42 43 // Skip if map box isnât visible or already drawn 44 if (!mapBox.is(':visible') || mapBox.find('.gm-style').length > 0) return; 45 46 mapBox.html( evo_general_params.html.preload_gmap); 47 48 //if( mapBox.hasClass('mDrawn') ) return; 49 50 // set calendar for event 51 options.cal = obj.closest('.ajde_evcal_calendar').length ? obj.closest('.ajde_evcal_calendar') : options.cal; 52 code.process_SC(); 53 54 // various methods to draw map 55 // load map on specified elements directly 56 if(options.fnt==5){ 57 if(options.delay==0){ code.draw_map(); }else{ 58 setTimeout(code.draw_map, options.delay, this); 59 } 60 } 61 62 // deprecating rest 4.6 63 // multiple maps at same time 64 if(options.fnt==1){ 65 code.load_gmap(); 66 } 67 68 if(options.fnt==2){ 69 if(options.delay==0){ code.load_gmap(); }else{ 70 setTimeout(code.load_gmap, options.delay, this); 71 } 72 } 73 if(options.fnt==3){ code.load_gmap(); } 74 75 // gmaps on popup 76 if(options.fnt==4){ 77 // check if gmaps should run 78 if( this.attr('data-gmtrig')=='1' && this.attr('data-gmap_status')!='null'){ 79 code.load_gmap(); 80 } 81 } 82 }, 83 // add unique id for map area 84 process_unique_map_id: function(){ 85 var map_element = obj.closest('.eventon_list_event').find('.evo_metarow_gmap'); 86 if (!map_element.length || !map_element.attr('id')) return false; 87 88 var map_element = obj.closest('.eventon_list_event').find('.evo_metarow_gmap'); 89 90 var randomnumber = Math.floor(Math.random() * (99 - 10 + 1)) + 10; 91 options.map_canvas_id = map_element.attr('id') + '_' + randomnumber; 92 map_element.attr('id', options.map_canvas_id); 93 return options.map_canvas_id; 94 }, 95 process_SC: function(){ 96 if (options.SC || !options.cal) return; 97 options.SC = options.cal.evo_shortcode_data(); 98 }, 99 100 // load google map 101 load_gmap: function(){ 102 var SC = options.SC, 103 ev_location = obj.find('.event_location_attrs'), 104 location_type = ev_location.attr('data-location_type'); 105 106 options.address = location_type == 'address' ? ev_location.attr('data-location_address') : ev_location.attr('data-latlng'); 107 options.location_type = location_type == 'address' ? 'add' : 'latlng'; 108 options.iconURL = SC && SC.mapiconurl ? SC.mapiconurl : options.iconURL; 109 110 if (!options.address) { 111 console.log('Location address missing in options.address'); 112 return false; 113 } 114 115 var map_canvas_id = code.process_unique_map_id(); 116 if (!map_canvas_id || !$('#' + map_canvas_id).length) { 117 console.log('Map element with id missing in page'); 118 return false; 119 } 120 121 options.zoomlevel = SC && SC.mapzoom ? parseInt(SC.mapzoom) : 12; 122 options.scroll = SC.mapscroll; 123 options.mapformat = SC.mapformat; 124 125 code.draw_map(); 126 }, 127 128 // final draw 129 draw_map: function(){ 130 131 if(!options.map_canvas_id || $('body').find('#'+options.map_canvas_id).length == 0){ 132 console.log( 'Map element with id missing in page'); return false; 133 } 134 135 // map styles 136 if( typeof gmapstyles !== 'undefined' && gmapstyles != 'default'){ 137 options.styles = JSON.parse(gmapstyles); 138 } 139 140 var myOptions = { 141 mapTypeId: options.mapformat, 142 zoom: options.zoomlevel, 143 scrollwheel: options.scroll != 'false', 144 zoomControl: true, 145 draggable: options.scroll != 'false', 146 mapId: 'DEMO_MAP_ID' 147 // Removed mapId to allow custom styles 148 }; 149 150 var map_canvas = document.getElementById(options.map_canvas_id), 151 map = new google.maps.Map(map_canvas, myOptions), 152 geocoder = new google.maps.Geocoder(); 153 154 // address from latlng 155 if(options.location_type=='latlng' && options.address !== undefined){ 156 var latlngStr = options.address.split(",",2); 157 var lat = parseFloat(latlngStr[0]); 158 var lng = parseFloat(latlngStr[1]); 159 var latlng = new google.maps.LatLng(lat, lng); 160 161 geocoder.geocode({'latLng': latlng}, function(results, status) { 162 if (status == google.maps.GeocoderStatus.OK) { 163 164 let markerOptions = { 165 map: map, 166 position: latlng 167 }; 168 169 if (options.iconURL && options.iconURL.trim() !== '') { 170 var img = new Image(); 171 img.src = options.iconURL; 172 173 img.onload = function () { 174 var imgWidth = img.width;
175 var imgHeight = img.height; 176 177 var customIcon = document.createElement('div'); 178 customIcon.className = 'custom-marker'; 179 customIcon.style.width = imgWidth + 'px'; 180 customIcon.style.height = imgHeight + 'px'; 181 customIcon.style.backgroundImage = `url(${options.iconURL})`; 182 customIcon.style.backgroundSize = 'cover'; 183 customIcon.style.position = 'absolute'; 184 185 markerOptions.content = customIcon; 186 187 const marker = new google.maps.marker.AdvancedMarkerElement(markerOptions); 188 map.setCenter(marker.position); 189 }; 190 191 img.onerror = function () { 192 console.error("Error loading marker image: " + options.iconURL); 193 const marker = new google.maps.marker.AdvancedMarkerElement(markerOptions); // Default marker 194 map.setCenter(marker.position); 195 }; 196 } else { 197 // No custom icon, use default Google Maps marker 198 const marker = new google.maps.marker.AdvancedMarkerElement(markerOptions); 199 map.setCenter(marker.position); 200 } 201 202 } else { 203 map_canvas.style.display = 'none'; 204 } 205 }); 206 207 }else if(options.address==''){ 208 //console.log('t'); 209 }else{ 210 geocoder.geocode( { 'address': options.address}, function(results, status) { 211 if (status == google.maps.GeocoderStatus.OK) { 212 map.setCenter(results[0].geometry.location); 213 new google.maps.Marker({ 214 map: map, 215 position: results[0].geometry.location, 216 icon: options.iconURL 217 }); 218 219 } else { map_canvas.style.display = 'none'; } 220 }); 221 } 222 223 // mark as map drawn 224 $('#'+ options.map_canvas_id).addClass('mDrawn'); 225 } 226 } 227 228 229 // INIT 230 code.init(); 231 }; 232 233 234// trigger load google map on dynamic map element u4.6.1 235 $.fn.evo_load_gmap = function(opt){ 236 var defs = { map_canvas_id: '', delay: 0, trigger_point: '' }, 237 OO = $.extend({}, defs, opt), 238 EL = this, 239 EL_id = OO.map_canvas_id || EL.attr('id'), 240 location_type = EL.data('location_type') == 'add' ? 'add' : 'latlng', 241 address = location_type == 'add' ? EL.data('address') : EL.data('latlng'), 242 scrollwheel = EL.data('scroll') == 'yes', 243 elms = document.querySelectorAll("[id='" + EL_id + "']"); 244 245 // Ensure unique ID 246 if (elms.length > 1) { 247 var randomnumber = Math.floor(Math.random() * (99 - 10 + 1)) + 10; 248 EL_id = EL_id + '_' + randomnumber; 249 EL.attr('id', EL_id); 250 } 251 252 // Determine delay 253 var __delay = OO.delay || EL.data('delay') || 0; 254 255 let mapData = { 256 map_canvas_id: EL_id, 257 fnt: 5, 258 location_type: location_type, 259 address: address, 260 zoomlevel: parseInt(EL.data('zoom')), 261 mapformat: EL.data('mty'), 262 scroll: scrollwheel, 263 iconURL: EL.data('mapicon') || '', 264 delay: __delay, 265 trigger_point: OO.trigger_point 266 }; 267 268 // load the map 269 EL.evoGenmaps(mapData); 270 271 272 }; 273 274 275 276}(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.