PageSourceSearch

https://www.icehearts.eu/js/jquery.gmap.js

js icehearts.eu collected 2026-09-26 02:31:49 UTC 16,652 bytes, 628 lines download raw bytes

1/**
2 * jQuery gMap - Google Maps API V3
3 *
4 * @license MIT License; http://www.opensource.org/licenses/mit-license.php
5 * @url   http://github.com/marioestrada/jQuery-gMap
6 * @author  Mario Estrada <[email protected]> based on original plugin by Cedric Kastner <[email protected]>
7 * @version 2.1.5
8 */
9/* global google */
10(function($)
11{
12	// Main plugin function
13	$.fn.gMap = function(options, methods_options)
14	{
15		// Optional methods
16		switch(options)
17		{
18			case 'addMarker':
19				return $(this).trigger(
20					'gMap.addMarker',
21					[methods_options.latitude, methods_options.longitude, methods_options.content, methods_options.icon, methods_options.popup, methods_options.url, methods_options.markerId]
22				);
23			case 'centerAt':
24				return $(this).trigger('gMap.centerAt', [methods_options.latitude, methods_options.longitude, methods_options.address, methods_options.zoom]);
25			case 'setZoom':
26				return $(this).trigger('gMap.setZoom', [methods_options.zoom]);
27			case 'clearMarkers':
28				return $(this).trigger('gMap.clearMarkers');
29			case 'openMarker':
30				return $(this).trigger('gMap.openMarker', [methods_options.markerId, methods_options.zoom]);
31			case 'closeMarkers':
32				return $(this).trigger('gMap.closeMarkers');
33		}
34
35		// Build main options before element iteration
36		var opts = $.extend({}, $.fn.gMap.defaults, options);
37
38		// Iterate through each element
39		return this.each(function()
40		{
41			// Create map and set initial options
42			var $gmap = new google.maps.Map(this);
43
44			$(this).data('gMap.reference', $gmap);
45
46			// Create new object to geocode addresses
47			var $geocoder = new google.maps.Geocoder();
48
49			// Check for address to center on
50			if (opts.address)
51			{
52				// Get coordinates for given address and center the map
53				$geocoder.geocode(
54					{
55						address: opts.address
56					}, function(gresult, status)
57					{
58						if(status == google.maps.GeocoderStatus.OK) {
59							$gmap.setCenter(gresult[0].geometry.location);
60							
61							if ( typeof(gresult[0].geometry.bounds) != 'undefined' )
62								$gmap.fitBounds(gresult[0].geometry.bounds);
63						}
64					}
65				);
66			}else{
67				// Check for coordinates to center on
68				if (opts.latitude && opts.longitude)
69				{
70					// Center map to coordinates given by option
71					$gmap.setCenter(new google.maps.LatLng(opts.latitude, opts.longitude));
72				}
73				else
74				{
75					// Check for a marker to center on (if no coordinates given)
76					if ($.isArray(opts.markers) && opts.markers.length > 0 && opts.markers.length < 2)
77					{
78						// Check if the marker has an address
79						if (opts.markers[0].address)
80						{
81							// Get the coordinates for given marker address and center
82							$geocoder.geocode(
83								{
84									address: opts.markers[0].address
85								}, function(gresult, status)
86								{
87									if(gresult && gresult.length > 0) {
88										$gmap.setCenter(gresult[0].geometry.location);
89									}
90								}
91							);
92						}else{
93							// Center the map to coordinates given by marker
94							$gmap.setCenter(new google.maps.LatLng(opts.markers[0].latitude, opts.markers[0].longitude));
95						}
96					} else{
97						// Revert back to world view
98						$gmap.setCenter(new google.maps.LatLng(53.515449, 13.546767));
99					}
100				}
101			}
102			
103			// Set the preferred map type
104			$gmap.setMapTypeId(google.maps.MapTypeId[opts.maptype]);
105
106			// Set scrollwheel option
107			var map_options = { scrollwheel: opts.scrollwheel, disableDoubleClickZoom: !opts.doubleclickzoom };
108			// Check for map controls
109			if(opts.controls === false){
110				$.extend(map_options, { disableDefaultUI: true });
111			}else if (opts.controls.length !== 0){
112				$.extend(map_options, opts.controls, { disableDefaultUI: true });
113			}
114
115			$gmap.setOptions(map_options);
116
117			// Create new icon
118			var gicon = new google.maps.Marker();
119			var marker_icon;
120			var marker_shadow;
121
122			// Set icon properties from global options
123			marker_icon = new google.maps.MarkerImage(opts.icon.image);
124			marker_icon.size = new google.maps.Size(opts.icon.iconsize[0], opts.icon.iconsize[1]);
125			marker_icon.anchor = new google.maps.Point(opts.icon.iconanchor[0], opts.icon.iconanchor[1]);
126			gicon.setIcon(marker_icon);
127
128			if(opts.icon.shadow)
129			{
130				marker_shadow = new google.maps.MarkerImage(opts.icon.shadow);
131				marker_shadow.size = new google.maps.Size(opts.icon.shadowsize[0], opts.icon.shadowsize[1]);
132				marker_shadow.anchor = new google.maps.Point(opts.icon.shadowanchor[0], opts.icon.shadowanchor[1]);
133				gicon.setShadow(marker_shadow);
134			}
135
136			// Bind actions
137			$(this).bind('gMap.centerAt', function(e, latitude, longitude, address, zoom)
138			{
139				// Check for address to center on
140				if (address)
141			{
142					// Create new object to geocode addresses
143					var $geocoder = new google.maps.Geocoder();
144			
145					// Get coordinates for given address and center the map
146					$geocoder.geocode(
147						{
148							address: opts.address
149						}, function(gresult, status)
150						{
151							if(status == google.maps.GeocoderStatus.OK) {
152								$gmap.panTo(gresult[0].geometry.location);
153							}
154						}
155					);
156				} else
157					$gmap.panTo(new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude)));
158				
159				if (zoom) {
160					$gmap.setZoom(zoom);
161				}
162			});
163			
164			// Bind actions
165			$(this).bind('gMap.setZoom', function(e,  zoom)
166			{
167				$gmap.setZoom(zoom);
168			});
169
170			// Clear Markers
171			var overlays = [],
172				infoWindows = [];
173			var last_infowindow;
174			var bounds = new google.maps.LatLngBounds();
175			var boundsCount = 0;
176			
177			// add custom bounds
178			if (opts.bounds) {
179				for (i in opts.bounds) {
180					bounds.extend(new google.maps.LatLng(opts.bounds[i].latitude, opts.bounds[i].longitude));
181				}
182			}
183			
184			$(this).data('gMap.overlays', overlays);
185			$(this).data('gMap.infoWindows', infoWindows);
186			$(this).bind('gMap.clearMarkers', function()
187			{
188				while(overlays[0]) {
189					overlays.pop().setMap(null);
190				}
191			});
192			
193			$(this).bind('gMap.openMarker', function(e, markerId, zoom)
194			{
195				var gmarker = overlays[markerId];
196				var infowindow = infoWindows[markerId];
197				var latLng = gmarker.getPosition(); // returns LatLng object
198				$gmap.setCenter(latLng); // setCenter takes a LatLng object
199				
200				$gmap.setZoom(zoom);
201				
202				if (last_infowindow) {
203					last_infowindow.close();
204				}
205				infowindow.open($gmap, gmarker);
206				last_infowindow = infowindow;
207			});
208			
209			$(this).bind('gMap.closeMarkers', function(e)
210			{
211				if (last_infowindow) {
212					last_infowindow.close();
213				}
214				last_infowindow = null;
215				
216				$gmap.fitBounds(bounds);
217			});
218			
219			
220			$(this).bind('gMap.addMarker', function(e, latitude, longitude, content, icon, popup, url, markerId)
221			{
222				var marker_icon;
223				var marker_shadow;
224				var glatlng = new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude));
225
226				var gmarker = new google.maps.Marker({
227					animation: google.maps.Animation.DROP,
228					position: glatlng
229				});
230
231				if(icon)
232				{
233					marker_icon = new google.maps.MarkerImage(icon.image);
234					marker_icon.size = new google.maps.Size(icon.iconsize[0], icon.iconsize[1]);
235					marker_icon.anchor = new google.maps.Point(icon.iconanchor[0], icon.iconanchor[1]);
236					gmarker.setIcon(marker_icon);
237
238					if(icon.shadow)
239					{
240						marker_shadow = new google.maps.MarkerImage(icon.shadow);
241						marker_shadow.size = new google.maps.Size(icon.shadowsize[0], icon.shadowsize[1]);
242						marker_shadow.anchor = new google.maps.Point(icon.shadowanchor[0], icon.shadowanchor[1]);
243						gicon.setShadow(marker_shadow);
244					}
245				}else{
246					gmarker.setIcon(gicon.getIcon());
247					gmarker.setShadow(gicon.getShadow());
248				}
249
250				if(content)
251				{
252					if(content === '_latlng') {
253						content = latitude + ', ' + longitude;
254					}
255
256					var infowindow = new google.maps.InfoWindow({
257						content: opts.html_prepend + content + opts.html_append
258					});
259
260					google.maps.event.addListener(gmarker, 'click', function()
261					{
262						if (last_infowindow) {
263							last_infowindow.close();
264						}
265						infowindow.open($gmap, gmarker);
266						last_infowindow = infowindow;
267					});
268					
269					if(popup)
270					{
271						google.maps.event.addListenerOnce($gmap, 'tilesloaded', function()
272						{
273							infowindow.open($gmap, gmarker);
274						});
275					}
276					
277					infoWindows[markerId] = infowindow;
278				}
279				else if (url)
280				{
281					gmarker.addListener('click', function()
282					{
283						document.location.href = url;	
284					});
285				}
286				
287				if (opts.centerAll) {
288					boundsCount++;
289					bounds.extend(new google.maps.LatLng(latitude, longitude));
290					
291					if ( opts.markers.length == boundsCount ) {
292						$gmap.fitBounds(bounds);
293						
294						if ( opts.zoom ) {
295							$gmap.setZoom(opts.zoom);
296						}
297					}
298				}
299				
300				if ( opts.markers.length == boundsCount && opts.zoom ) {
301					$gmap.setZoom(opts.zoom);
302				}
303				
304				gmarker.setMap($gmap);
305				overlays[markerId] = gmarker;
306				
307			});
308	
309			/* Directions */
310			if ( opts.directions ) {
311				var directionsService = new google.maps.DirectionsService();
312				// Create a renderer for directions and bind it to the map.
313				var rendererOptions = {
314					map: $gmap
315					,suppressMarkers: true
316					,suppressInfoWindows: true
317					,preserveViewport: true
318					,polylineOptions : {
319						strokeWeight: 5
320					}
321				}
322				var allPoints = opts.directions.length;
323				var currentPoints = 0;
324				var self = this;
325				
326				// calculate route and place it
327				function calcRoute( start, waypoints, end, travelMode, lineColor) {
328					// Retrieve the start and end locations and create
329					// a DirectionsRequest using WALKING directions.
330					var request = {
331						origin: start,
332						destination: end,
333						waypoints: waypoints,
334						travelMode: travelMode,
335						avoidFerries: true
336					};
337					
338					// Route the directions and pass the response to a
339					// function to create markers for each step.
340					directionsService.route(request, function(response, status) {
341						currentPoints++;
342						
343						if (status == google.maps.DirectionsStatus.OK) {
344							if ( lineColor )
345								rendererOptions.polylineOptions.strokeColor = lineColor;
346							else
347								rendererOptions.polylineOptions.strokeColor = null;
348								
349							var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
350							directionsDisplay.setDirections(response);
351							// showSteps(response);
352						}
353						else {
354							console.log ( response );
355						}
356						
357						if ( currentPoints == allPoints ) {
358							
359							$(self).trigger(
360								'gMap.centerAt',
361								[response.routes[0].legs[0].end_location.A, response.routes[0].legs[0].end_location.F, opts.zoom]
362							);
363							
364							if (opts.centerAll) {
365								$gmap.fitBounds(bounds);
366							}
367						}
368						
369					});
370				}
371				
372				for ( i in opts.directions ) {
373					calcRoute( opts.directions[i].start.location, opts.directions[i].waypoints, opts.directions[i].end.location, opts.directions[i].travelMode, opts.directions[i].lineColor );
374				}				
375			}
376			
377			/* Polylines */
378			if ( opts.polyline ) {
379				
380				// Loop through marker array
381				var polylineMarkers = new Array();
382						
383						
384				$(this).bind('gMap.polyline', function(e, lat, lng, markerId) {
385					
386					// add marker coords
387					polylineMarkers[markerId] = new google.maps.LatLng(lat, lng);
388					
389					if ( opts.markers.length == polylineMarkers.length ) {
390						
391						for (var i = 0; i < opts.polylines.length; i++)
392						{
393							var markers = new Array();
394							
395							for (var p = 0; p < opts.polylines[i].objects.length; p++)
396							{
397								markers.push(
398									polylineMarkers[ opts.polylines[i].objects[p] ]
399								);
400							}	
401							
402							// add polyline
403							var path = new google.maps.Polyline({
404								path: markers,
405								geodesic: true,
406								strokeColor: opts.polylines[i].color,
407								strokeOpacity: 1.0,
408								strokeWeight: 5
409							});
410							
411							path.setMap($gmap);
412						}
413					}
414				});
415			}
416			
417			if ( opts.zoom ) {
418				$gmap.setZoom(opts.zoom);
419			}
420				
421			var marker;
422			var self = this;
423			
424			
425			var geocode_callback = function(marker, markerId) {
426				return function(gresult, status) {
427					// Create marker
428					if(gresult && gresult.length > 0)
429					{
430						$(self).trigger(
431							'gMap.addMarker',
432							[gresult[0].geometry.location.lat(), gresult[0].geometry.location.lng(), marker.html, marker.icon, marker.popup, marker.url, markerId]
433						);
434						
435						if ( opts.polyline ) {
436							$(self).trigger(
437								'gMap.polyline',
438								[gresult[0].geometry.location.lat(), gresult[0].geometry.location.lng(), markerId]
439							);
440						}
441					}
442				};
443			};
444			
445			
446			for (var j = 0; j < opts.markers.length; j++)
447			{
448				// Get the options from current marker
449				marker = opts.markers[j];
450				
451        
452				// Check if address is available
453		        if ( typeof (marker) != 'undefined' ) {
454				if (marker.address)
455				{
456					// Check for reference to the marker's address
457					if (marker.html === '_address') {
458						marker.html = marker.address;
459					}
460		
461					// Get the point for given address
462					$geocoder.geocode({
463						address: marker.address
464					}, geocode_callback(marker, j));
465				}
466				else{
467		  					$(this).trigger('gMap.addMarker', [marker.latitude, marker.longitude, marker.html, marker.icon, marker.popup, marker.url, j]);
468					
469					if ( opts.polyline ) {
470						$(this).trigger('gMap.polyline', [marker.latitude, marker.longitude, j]);
471					}
472				}
473			}
474			}
475			
476			
477			
478		});
479
480	};
481
482	// Default settings
483	$.fn.gMap.defaults = {
484		address: '',
485		latitude: 0,
486		longitude: 0,
487		zoom: 1,
488		markers: [],
489		controls: [],
490		scrollwheel: false,
491		doubleclickzoom: true,
492		maptype: 'ROADMAP',
493		html_prepend: '<div class="gmap_marker">',
494		html_append: '</div>',
495		icon: {
496			image: "//www.google.com/mapfiles/marker.png",
497			shadow: "//www.google.com/mapfiles/shadow50.png",
498			iconsize: [20, 34],
499			shadowsize: [37, 34],
500			iconanchor: [9, 34],
501			shadowanchor: [6, 34]
502		},
503		polyline: true,
504		polylines: [],
505		centerAll: false
506	};
507
508})(jQuery);
509
510var map_1 = null;
511var chart_1 = null;
512var marker_1 = null;
513
514var geocoderService_1 = null;
515var elevationService_1 = null;
516var directionsService_1 = null;
517
518var mousemarker_1 = null;
519var markers_1 = [];
520var polyline_1 = null;
521var elevations_1 = null;
522var lastmarker_1 = null;
523
524var SAMPLES = 256;
525
526function addressKeyHandler(e) {
527	addAddress();
528	
529	return false;
530}
531
532function initialize() {
533	var myLatlng = new google.maps.LatLng(53, 19);
534	var myOptions = {
535		zoom: 3,
536		center: myLatlng,
537		mapTypeId: google.maps.MapTypeId.HYBRID
538	}
539
540	map_1 = new google.maps.Map(document.getElementById("map_canvas_1"), myOptions);
541	
542	var geocoder = new google.maps.Geocoder();
543	
544	// address here is global
545	geocoder.geocode( { 'address': address}, function(results, status) {
546		if (status == google.maps.GeocoderStatus.OK) {
547			map_1.setCenter(results[0].geometry.location);
548			map_1.fitBounds(results[0].geometry.bounds);
549		}
550	});	
551	
552	geocoderService_1 = new google.maps.Geocoder();
553	elevationService_1 = new google.maps.ElevationService();
554	directionsService_1 = new google.maps.DirectionsService();
555	
556	addAddress();
557}
558
559function addMarker(latlng) {
560	var marker_1 = new google.maps.Marker({
561		position: latlng,
562		map: map_1,
563		draggable: true,
564		animation: google.maps.Animation.DROP
565	});
566	
567	marker_1.addListener('drag', function() {
568		var coords = marker_1.getPosition();
569	
570		$("#coord_1").val(coords.lat());
571		$("#coord_2").val(coords.lng());
572	});
573
574	markers_1.push(marker_1);
575	
576	return false;
577}
578
579
580function addAddress() {
581	var address_1_obj = document.getElementById('address_1');
582	var address_1 = address_1_obj.value;
583	var coord_1 = $("#coord_1").val();
584	var coord_2 = $("#coord_2").val();
585	
586	if ( !address_1 && coord_1 && coord_2 ) {
587		clearAllMarkers();
588		
589		var latlng = new google.maps.LatLng(parseFloat(coord_1), parseFloat(coord_2));
590		
591		addMarker(latlng, true);
592	}
593	else if (address_1) {
594		geocoderService_1.geocode({ 'address': address_1 }, function(results, status) {
595		
596			if (status == google.maps.GeocoderStatus.OK) {
597				var latlng = results[0].geometry.location;
598				
599				clearAllMarkers();
600				
601				addMarker(latlng, true);
602		
603				var coords = markers_1[0].getPosition();
604				
605				$("#coord_1").val(coords.lat());
606				$("#coord_2").val(coords.lng());
607				
608				map_1.fitBounds(results[0].geometry.viewport);
609				
610				address_1_obj.focus();
611				address_1_obj.blur();
612			} else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
613				alert("Address not found.");
614			} else {
615				alert("Address not found.");
616			}
617			
618		});
619	}
620}	
621
622function clearAllMarkers() {
623	for (var i in markers_1) {
624		markers_1[i].setMap(null);
625	}
626
627	markers_1 = [];
628}

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.