PageSourceSearch

https://web.cusco.gob.pe/wp-content/plugins/eventon-lite/assets/js/maps/eventon_gen_maps.js?ver=2.2.20

js cusco.gob.pe collected 2026-10-02 10:32:40 UTC 7,181 bytes, 289 lines download raw bytes

1/**
2 * EventON Generate Google Maps Function
3 * @version  4.2
4 */
5(function($){
6
7
8// ADD notes on how to run this after approval
9
10// map loader function 
11	$.fn.evoGenmaps = function(opt){
12
13		var defaults = {
14			delay:	0,
15			fnt:	1,
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		};
27		var options = $.extend({}, defaults, opt); 
28
29		var geocoder;
30
31		var code = {};
32		obj = this;
33		code.obj = this;
34
35		code = {	
36			init:function(){	
37
38				// set calendar for event
39				if( obj.closest('.ajde_evcal_calendar').length>0){
40					options.cal = obj.closest('.ajde_evcal_calendar');
41				}
42
43				
44				if( options.cal === undefined){
45					console.log('Cannot find the calendar'); return false;
46				}
47
48				code.process_SC();
49
50				// various methods to draw map
51					// multiple maps at same time
52					if(options.fnt==1){
53						code.load_gmap();
54					}
55					
56					if(options.fnt==2){
57						if(options.delay==0){	code.load_gmap();	}else{
58							setTimeout(code.load_gmap, options.delay, this);
59						}			
60					} 
61					if(options.fnt==3){	code.load_gmap();	}
62					
63					// gmaps on popup
64					if(options.fnt==4){
65						// check if gmaps should run
66						if( this.attr('data-gmtrig')=='1' && this.attr('data-gmap_status')!='null'){	
67							code.load_gmap();			
68						}	
69					}
70
71					// load map on specified elements directly
72					// eg. location archive page
73					if(options.fnt==5){
74						code.draw_map();
75					}
76			},
77			// add unique id for map area
78			process_unique_map_id: function(){
79				var map_element = obj.closest('.eventon_list_event').find('.evo_metarow_gmap');
80
81				if(map_element === undefined ) return false;
82
83				var old_map_canvas_id = map_element.attr('id');	
84				if(old_map_canvas_id === undefined) return false;
85
86				// GEN
87				maximum = 99;
88				minimum = 10;
89				var randomnumber = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
90
91				map_canvas_id = old_map_canvas_id+'_'+randomnumber;
92				map_element.attr('id', map_canvas_id).addClass('test');
93				
94				options.map_canvas_id = map_canvas_id;
95
96				return map_canvas_id;
97			},
98			process_SC: function(){
99				CAL = options.cal;
100				if( options.SC !== '') return;
101				if(CAL == '') return false;
102				options.SC = CAL.evo_shortcode_data();
103			},
104
105			// load google map
106			load_gmap: function(){
107				SC = options.SC;
108						
109				var ev_location = obj.find('.event_location_attrs');
110
111				var location_type = ev_location.attr('data-location_type');
112				if(location_type=='address'){
113					options.address = ev_location.attr('data-location_address');
114					options.location_type = 'add';
115				}else{			
116					options.address = ev_location.attr('data-latlng');
117					options.location_type = 'latlng';				
118				}
119
120
121
122				// marker icons
123				if( SC !== undefined && SC != '' &&  'mapiconurl' in SC) options.iconURL = SC.mapiconurl;
124
125				// make sure there is address present to draw map
126				if( options.address === undefined || options.address == '') return false;
127
128				map_canvas_id = code.process_unique_map_id();
129
130				if(!map_canvas_id || $('#'+map_canvas_id).length == 0) return false;
131
132				var zoom = SC.mapzoom;
133				options.zoomlevel = (typeof zoom !== 'undefined' && zoom !== false)? parseInt(zoom):12;				
134				options.scroll = SC.mapscroll;	
135				options.mapformat = SC.mapformat;	
136
137													
138				code.draw_map();
139			},
140
141			// final draw
142			draw_map: function(){
143
144				if(!options.map_canvas_id || $('#'+options.map_canvas_id).length == 0){
145					console.log( 'Map element with id missing in page'); return false;
146				}
147
148				// map styles
149				if( typeof gmapstyles !== 'undefined' && gmapstyles != 'default'){
150					options.styles = JSON.parse(gmapstyles);
151				}
152
153				geocoder = new google.maps.Geocoder();					
154				//var latlng = new google.maps.LatLng(45.524732, -122.677031);
155
156				var latlng = 0;
157				
158				if(options.scroll == 'false' || options.scroll == false){
159
160					var myOptions = {			
161						//center: latlng,	
162						mapTypeId: 	options.mapformat,	
163						zoom: 		options.zoomlevel,	
164						scrollwheel: false,
165						styles: options.styles,
166						zoomControl:true,
167						draggable:false
168					}
169				}else{
170					var myOptions = {	
171						//center: latlng,	
172						mapTypeId: options.mapformat,	
173						zoom: options.zoomlevel,
174						styles: options.styles,
175						zoomControl:true,
176						scrollwheel: true,
177					}
178				}
179
180				//console.log(myOptions);
181
182				
183				var map_canvas = document.getElementById(options.map_canvas_id);
184				map = new google.maps.Map(map_canvas, myOptions);
185		
186				// address from latlng
187				if(options.location_type=='latlng' && options.address !== undefined){
188					var latlngStr = options.address.split(",",2);
189					var lat = parseFloat(latlngStr[0]);
190					var lng = parseFloat(latlngStr[1]);
191					var latlng = new google.maps.LatLng(lat, lng);
192
193					geocoder.geocode({'latLng': latlng}, function(results, status) {
194						if (status == google.maps.GeocoderStatus.OK) {				
195							var marker = new google.maps.Marker({
196								map: map,
197								position: latlng,
198								icon: options.iconURL
199							});
200							//map.setCenter(results[0].geometry.location);
201							map.setCenter(marker.getPosition());
202
203						} else {				
204							document.getElementById(options.map_canvas_id).style.display='none';
205						}
206					});
207					
208				}else if(options.address==''){
209					//console.log('t');
210				}else{
211					geocoder.geocode( { 'address': options.address}, function(results, status) {
212						if (status == google.maps.GeocoderStatus.OK) {		
213							//console.log('map '+results[0].geometry.location);
214							map.setCenter(results[0].geometry.location);
215							var marker = new google.maps.Marker({
216								map: map,
217								position: results[0].geometry.location,
218								icon: options.iconURL
219							});				
220							
221						} else {
222							document.getElementById(options.map_canvas_id).style.display='none';				
223						}
224					});
225				}
226			}
227		}
228
229
230		// INIT
231		code.init();
232
233		
234	};
235
236// trigger map load on calendar
237// @since 4.2
238	$('body').on('evo_load_map_on_cals',function (){
239		
240		if( $('body').find('.ajde_evcal_calendar').length < 1 ) return;
241
242		$('body').find('.ajde_evcal_calendar').each(function(){
243			var el = $(this);
244			el.find('.desc_trig').each(function(index){
245				var self = this;
246				setTimeout(function(){
247					$(self).evoGenmaps({'fnt':2,'cal': el});
248				},index*600);					
249			});
250		});
251	});
252
253	// trigger load google map on dynamic map element
254	$.fn.evo_load_gmap = function(opt){
255		var defs = {
256			'map_canvas_id':'',
257			'delay':0,
258		};
259		var OO = $.extend({}, defs, opt);
260
261		EL = this;
262
263		var location_type = 'add';
264		var location_type = EL.data('location_type');
265
266		if(location_type=='add'){
267			var address = EL.data('address');				
268		}else{			
269			var address = EL.data('latlng');
270			var location_type = 'latlng';				
271		}
272		scrollwheel = EL.data('scroll') == 'yes'? true: false;
273
274		EL.evoGenmaps({
275			map_canvas_id: EL.attr('id'),
276			fnt: 5,
277			location_type:	location_type,
278			address: address,
279			zoomlevel: parseInt( EL.data('zoom') ),
280			mapformat: EL.data('mty'),
281			scroll: scrollwheel,
282			delay:  EL.data('delay') ? EL.data('delay') : OO.delay
283		});
284
285	};
286
287
288
289}(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.