1/** 2 * EventON Generate Google Maps Function 3 * @version 0.2 4 */ 5(function($){ 6 $.fn.evoGenmaps = function(opt){ 7 8 var defaults = { 9 delay: 0, 10 fnt: 1, 11 cal: '', 12 map_canvas_id: '', 13 location_type:'', 14 address:'', 15 styles:'', 16 zoomlevel:'', 17 mapformat:'', 18 scroll:false, 19 iconURL:'', 20 }; 21 var options = $.extend({}, defaults, opt); 22 23 var geocoder; 24 25 var code = {}; 26 obj = this; 27 code.obj = this; 28 29 code = { 30 init:function(){ 31 32 // set calendar for event 33 if( obj.closest('.ajde_evcal_calendar').length>0){ 34 options.cal = obj.closest('.ajde_evcal_calendar'); 35 } 36 37 if( options.cal === undefined){ 38 console.log('Cannot find the calendar'); return false; 39 } 40 41 code.process_SC(); 42 43 // various methods to draw map 44 // multiple maps at same time 45 if(options.fnt==1){ 46 code.load_gmap(); 47 } 48 49 if(options.fnt==2){ 50 if(options.delay==0){ code.load_gmap(); }else{ 51 setTimeout(code.load_gmap, options.delay, this); 52 } 53 } 54 if(options.fnt==3){ code.load_gmap(); } 55 56 // gmaps on popup 57 if(options.fnt==4){ 58 // check if gmaps should run 59 if( this.attr('data-gmtrig')=='1' && this.attr('data-gmap_status')!='null'){ 60 code.load_gmap(); 61 } 62 } 63 64 // load map on specified elements directly 65 // eg. location archive page 66 if(options.fnt==5){ 67 code.draw_map(); 68 } 69 }, 70 // add unique id for map area 71 process_unique_map_id: function(){ 72 var map_element = obj.closest('.eventon_list_event').find('.evo_metarow_gmap'); 73 74 if(map_element === undefined ) return false; 75 76 var old_map_canvas_id = map_element.attr('id'); 77 if(old_map_canvas_id === undefined) return false; 78 79 // GEN 80 maximum = 99; 81 minimum = 10; 82 var randomnumber = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; 83 84 map_canvas_id = old_map_canvas_id+'_'+randomnumber; 85 map_element.attr('id', map_canvas_id).addClass('test'); 86 87 options.map_canvas_id = map_canvas_id; 88 89 return map_canvas_id; 90 }, 91 process_SC: function(){ 92 CAL = options.cal; 93 if(CAL == '') return false; 94 options.SC = CAL.evo_shortcode_data(); 95 }, 96 97 // load google map 98 load_gmap: function(){ 99 SC = options.SC; 100 101 var ev_location = obj.find('.evcal_desc'); 102 103 var location_type = ev_location.attr('data-location_type'); 104 if(location_type=='address'){ 105 options.address = ev_location.attr('data-location_address'); 106 options.location_type = 'add'; 107 }else{ 108 options.address = ev_location.attr('data-latlng'); 109 options.location_type = 'latlng'; 110 } 111 112 // marker icons 113 if( 'mapiconurl' in SC) options.iconURL = SC.mapiconurl; 114 115 // make sure there is address present to draw map 116 if( options.address === undefined || options.address == '') return false; 117 118 map_canvas_id = code.process_unique_map_id(); 119 120 if(!map_canvas_id || $('#'+map_canvas_id).length == 0) return false; 121 122 var zoom = SC.mapzoom; 123 options.zoomlevel = (typeof zoom !== 'undefined' && zoom !== false)? parseInt(zoom):12; 124 options.scroll = SC.mapscroll; 125 options.mapformat = SC.mapformat; 126 127 128 code.draw_map(); 129 }, 130 131 // final draw 132 draw_map: function(){ 133 134 if(!options.map_canvas_id || $('#'+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 geocoder = new google.maps.Geocoder(); 144 //var latlng = new google.maps.LatLng(45.524732, -122.677031); 145 146 var latlng = 0; 147 148 if(options.scroll == 'false' || options.scroll == false){ 149 150 var myOptions = { 151 //center: latlng, 152 mapTypeId: options.mapformat, 153 zoom: options.zoomlevel, 154 scrollwheel: false, 155 styles: options.styles, 156 zoomControl:true, 157 draggable:false 158 } 159 }else{ 160 var myOptions = { 161 //center: latlng, 162 mapTypeId: options.mapformat, 163 zoom: options.zoomlevel, 164 styles: options.styles, 165 zoomControl:true, 166 scrollwheel: true, 167 } 168 } 169 170 var map_canvas = document.getElementById(options.map_canvas_id); 171 map = new google.maps.Map(map_canvas, myOptions); 172 173 // address from latlng 174 if(options.location_type=='latlng' && options.address !== undefined){ 175 var latlngStr = options.address.split(",",2); 176 var lat = parseFloat(latlngStr[0]); 177 var lng = parseFloat(latlngStr[1]); 178 var latlng = new google.maps.LatLng(lat, lng); 179 180 geocoder.geocode({'latLng': latlng}, function(results, status) { 181 if (status == google.maps.GeocoderStatus.OK) { 182 var marker = new google.maps.Marker({ 183 map: map, 184 position: latlng, 185 icon: options.iconURL 186 });
187 //map.setCenter(results[0].geometry.location); 188 map.setCenter(marker.getPosition()); 189 190 } else { 191 document.getElementById(options.map_canvas_id).style.display='none'; 192 } 193 }); 194 195 }else if(options.address==''){ 196 //console.log('t'); 197 }else{ 198 geocoder.geocode( { 'address': options.address}, function(results, status) { 199 if (status == google.maps.GeocoderStatus.OK) { 200 //console.log('map '+results[0].geometry.location); 201 map.setCenter(results[0].geometry.location); 202 var marker = new google.maps.Marker({ 203 map: map, 204 position: results[0].geometry.location, 205 icon: options.iconURL 206 }); 207 208 } else { 209 document.getElementById(options.map_canvas_id).style.display='none'; 210 } 211 }); 212 } 213 } 214 } 215 216 217 // INIT 218 code.init(); 219 220 221 }; 222}(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.