forked from fridek/gmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.gmap.min.js
20 lines (20 loc) · 5.92 KB
/
jquery.gmap.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* jQuery gMap v3
*
* @url http://www.smashinglabs.pl/gmap
* @author Sebastian Poreba <[email protected]>
* @version 3.1.0
* @date 23.04.2011
*/
(function(f){var d=google.maps,j=new d.Geocoder,b={},m=0,h={init:function(a){b=f.extend({},f.fn.gMap.defaults,a);for(var c in f.fn.gMap.defaults.icon)b.icon[c]||(b.icon[c]=f.fn.gMap.defaults.icon[c]);return this.each(function(){var a=f(this),c=h._getMapCenter.apply(a,[]),g={zoom:b.zoom,center:c,mapTypeControl:b.mapTypeControl,zoomControl:b.zoomControl,panControl:b.panControl,scaleControl:b.scaleControl,streetViewControl:b.streetViewControl,mapTypeId:b.maptype,scrollwheel:b.scrollwheel,maxZoom:b.maxZoom,
minZoom:b.minZoom};b.log&&console.log("map center is:");b.log&&console.log(c);c=new d.Map(this,g);a.data("$gmap",c);a.data("gmap",{opts:b,gmap:c,markers:[],infoWindow:null});if(b.controls.length!==0)for(g=0;g<b.controls.length;g+=1)c.controls[b.controls[g].pos].push(b.controls[g].div);if(b.markers.length!==0)for(g=0;g<b.markers.length;g+=1)h.addMarker.apply(a,[b.markers[g]]);h._onComplete.apply(a,[])})},_onComplete:function(){var a=this.data("gmap"),b=this;if(m!==0)window.setTimeout(function(){h._onComplete.apply(b,
[])},1E3);else a.opts.onComplete()},_setMapCenter:function(a){b.log&&console.log("delayed setMapCenter called");var c=this.data("gmap");if(c.gmap!==void 0)c.gmap.setCenter(a);else{var d=this;window.setTimeout(function(){h._setMapCenter.apply(d,[a])},500)}},_getMapCenter:function(){var a,c=this;if(b.latitude&&b.longitude)return a=new d.LatLng(b.latitude,b.longitude);else a=new d.LatLng(0,0);if(b.address)return j.geocode({address:b.address},function(a,d){d===google.maps.GeocoderStatus.OK?h._setMapCenter.apply(c,
[a[0].geometry.location]):b.log&&console.log("Geocode was not successful for the following reason: "+d)}),a;if(f.isArray(b.markers)&&b.markers.length>0){for(var e=null,i=0;i<b.markers.length;i+=1){if(b.markers[i].latitude&&b.markers[i].longitude){e=b.markers[i];break}b.markers[i].address&&(e=b.markers[i])}if(e===null)return a;if(e.latitude&&e.longitude)return new d.LatLng(e.latitude,e.longitude);e.address&&j.geocode({address:e.address},function(a,d){d===google.maps.GeocoderStatus.OK?h._setMapCenter.apply(c,
[a[0].geometry.location]):b.log&&console.log("Geocode was not successful for the following reason: "+d)})}return a},processMarker:function(a,c,e,i){var g=this.data("gmap"),h=g.gmap;i===void 0&&(i=new d.LatLng(a.latitude,a.longitude));if(!c)var f={image:b.icon.image,iconSize:new d.Size(b.icon.iconsize[0],b.icon.iconsize[1]),iconAnchor:new d.Point(b.icon.iconanchor[0],b.icon.iconanchor[1]),infoWindowAnchor:new d.Size(b.icon.infowindowanchor[0],b.icon.infowindowanchor[1])},c=new d.MarkerImage(f.image,
f.iconSize,null,f.iconAnchor);e||(new d.Size(b.icon.shadowsize[0],b.icon.shadowsize[1]),f&&f.iconAnchor||new d.Point(b.icon.iconanchor[0],b.icon.iconanchor[1]));var k=new d.Marker({position:i,icon:c,title:a.title,map:h});k.setShadow(e);g.markers.push(k);var l;a.html&&(c={content:b.html_prepend+a.html+b.html_append,pixelOffset:a.infoWindowAnchor},b.log&&console.log("setup popup with data"),b.log&&console.log(c),l=new d.InfoWindow(c),d.event.addListener(k,"click",function(){b.log&&console.log("opening popup "+
a.html);b.singleInfoWindow&&g.infoWindow&&g.infoWindow.close();l.open(h,k);g.infoWindow=l}));a.html&&a.popup&&(b.log&&console.log("opening popup "+a.html),l.open(h,k))},_geocodeMarker:function(a,c,e){m+=1;var f=this;j.geocode({address:a.address},function(g,j){m-=1;j===d.GeocoderStatus.OK?h.processMarker.apply(f,[a,c,e,g[0].geometry.location]):b.log&&console.log("Geocode was not successful for the following reason: "+j)})},addMarker:function(a){b.log&&console.log("putting marker at "+a.latitude+", "+
a.longitude+" with address "+a.address+" and html "+a.html);var c={image:b.icon.image,iconSize:new d.Size(b.icon.iconsize[0],b.icon.iconsize[1]),iconAnchor:new d.Point(b.icon.iconanchor[0],b.icon.iconanchor[1]),infoWindowAnchor:new d.Size(b.icon.infowindowanchor[0],b.icon.infowindowanchor[1])},e={image:b.icon.shadow,iconSize:new d.Size(b.icon.shadowsize[0],b.icon.shadowsize[1]),anchor:c.iconAnchor};a.infoWindowAnchor=c.infoWindowAnchor;if(a.icon){if(a.icon.image)c.image=a.icon.image;if(a.icon.iconsize)c.iconSize=
new d.Size(a.icon.iconsize[0],a.icon.iconsize[1]);if(a.icon.iconanchor)c.iconAnchor=new d.Point(a.icon.iconanchor[0],a.icon.iconanchor[1]);if(a.icon.infowindowanchor)c.infoWindowAnchor=new d.Size(a.icon.infowindowanchor[0],a.icon.infowindowanchor[1]);if(a.icon.shadow)e.image=a.icon.shadow;if(a.icon.shadowsize)e.iconSize=new d.Size(a.icon.shadowsize[0],a.icon.shadowsize[1])}c=new d.MarkerImage(c.image,c.iconSize,null,c.iconAnchor);e=new d.MarkerImage(e.image,e.iconSize,null,e.anchor);if(a.address){if(a.html===
"_address")a.html=a.address;if(a.title=="_address")a.title=a.address;b.log&&console.log("geocoding marker: "+a.address);h._geocodeMarker.apply(this,[a,c,e])}else{if(a.html==="_latlng")a.html=a.latitude+", "+a.longitude;if(a.title=="_latlng")a.title=a.latitude+", "+a.longitude;var f=new d.LatLng(a.latitude,a.longitude);h.processMarker.apply(this,[a,c,e,f])}},removeAllMarkers:function(){var a=this.data("gmap").markers,b;for(b=0;b<a.length;b+=1)a[b].setMap(null)}};f.fn.gMap=function(a){if(h[a])return h[a].apply(this,
Array.prototype.slice.call(arguments,1));else if(typeof a==="object"||!a)return h.init.apply(this,arguments);else f.error("Method "+a+" does not exist on jQuery.gmap")};f.fn.gMap.defaults={log:!1,address:"",latitude:null,longitude:null,zoom:3,maxZoom:null,minZoom:null,markers:[],controls:{},scrollwheel:!0,maptype:google.maps.MapTypeId.ROADMAP,mapTypeControl:!0,zoomControl:!0,panControl:!1,scaleControl:!1,streetViewControl:!0,singleInfoWindow:!0,html_prepend:'<div class="gmap_marker">',html_append:"</div>",
icon:{image:"http://www.google.com/mapfiles/marker.png",iconsize:[20,34],iconanchor:[9,34],infowindowanchor:[9,2],shadow:"http://www.google.com/mapfiles/shadow50.png",shadowsize:[37,34]},onComplete:function(){}}})(jQuery);