-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.gMaps.min.js
12 lines (12 loc) · 8.04 KB
/
jquery.gMaps.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*!
* gMaps
* http://gmaps.monkeecreate.com
*
* Interactive & Static Google Maps jQuery Plugin
*
* Developed by John Hoover <http://defvayne23.com>
* Another project from monkeeCreate <http://monkeecreate.com>
*
* Version 3.2.0- Last updated: April 20, 2014
*/
!function(e){jQuery.fn.gMap=function(o){var t,i,s,a="http://maps.google.com/maps/api/staticmap?",n=function(e,o){geocoder.geocode({address:e},function(e,i){i===google.maps.GeocoderStatus.OK?o(e):i===google.maps.GeocoderStatus.ERROR?l.error(t,"There was a problem contacting the Google servers."):i===google.maps.GeocoderStatus.INVALID_REQUEST?l.error(t,"This GeocoderRequest was invalid."):i===google.maps.GeocoderStatus.OVER_QUERY_LIMIT?l.error(t,"The webpage has gone over the requests limit in too short a period of time."):i===google.maps.GeocoderStatus.REQUEST_DENIED?l.error(t,"The webpage is not allowed to use the geocoder."):i===google.maps.GeocoderStatus.UNKNOWN_ERROR?l.error(t,"A geocoding request could not be processed due to a server error. The request may succeed if you try again."):i===google.maps.GeocoderStatus.ZERO_RESULTS&&l.error(t,"No results were found for given address.")})},l=e.extend(!0,{map:"interactive",center:"",visible:[],zoom:1,scroll:!0,type:"roadmap",style:{width:"auto",height:"auto",cursor:""},markers:[],polylines:[],polygons:[],circles:[],overlay:[],click:function(){},error:function(){},bounds:!1,streetview:!0,format:null,mobile:"false",sensor:"false",title:"Google Maps",scale:null},o),c={position:"",label:"",content:"",icon:{type:"simple",size:"mid",color:"red",image:"",origin:[],anchor:[]},shadow:{type:"simple",size:"mid",color:"red",image:"",origin:[],anchor:[]},draggable:!1,dragend:function(){}},g={points:[],stroke:{color:"ff0000",opacity:1,weight:1}},p={points:[],stroke:{color:"ff0000",opacity:1,weight:1},fill:{color:"ff0000",opacity:1}},h={center:[],radius:1,measure:"m",detail:8,stroke:{color:"ff0000",opacity:1,weight:1},fill:{color:"ff0000",opacity:1}};return this.each(function(){t=this,"auto"===l.style.width?l.style.width=e(t).width():e(t).width(l.style.width),"auto"===l.style.height?l.style.height=e(t).height():e(t).height(l.style.height),"static"===l.map?(a+="size="+l.style.width+"x"+l.style.height,null!==l.format&&(a+="&format="+l.format),null!==l.scale&&(a+="&scale="+l.scale),""!==l.center&&(a+="¢er="+escape(l.center)),""!==l.zoom&&(a+="&zoom="+l.zoom),urlVisible=[],e(l.visible).each(function(e,o){urlVisible.push(o instanceof Array?o[0]+","+o[1]:escape(o.address))}),urlVisible.length>0&&(a+="&visible="+urlVisible.join("|")),a+="&type="+l.type,a+="&mobile="+l.mobile,a+="&sensor="+l.sensor):(map_options={mapTypeId:l.type,streetViewControl:l.streetview,scrollwheel:l.scroll},""!==l.style.cursor&&i.setOptions({draggableCursor:l.style.cursor}),i=new google.maps.Map(t,map_options),geocoder=new google.maps.Geocoder,infoWindow=new google.maps.InfoWindow,s=new google.maps.LatLngBounds(0,0),""!==l.zoom&&i.setZoom(l.zoom),l.center instanceof Array?i.setCenter(new google.maps.LatLng(l.center[0],l.center[1])):""!==l.center&&n(l.center,function(e){i.setCenter(e[0].geometry.location),s.extend(e[0].geometry.location),l.bounds===!0&&i.fitBounds(s)}),google.maps.event.addListener(i,"click",l.click),google.maps.event.addListener(i,"click",function(){infoWindow.close()})),e(l.markers).each(function(o,t){var r=e.extend(!0,{},c,t),g="";"static"===l.map?(g+="size:"+r.icon.size,g+="|color:"+r.icon.color,""!==r.label&&(g+="|label:"+r.label),""!==r.icon.image&&(g+="|icon:"+escape(r.icon.image)),g+=r.position instanceof Array?"|"+r.position[0]+","+r.position[1]:"|"+escape(r.position),a+="&markers="+g):(g=new google.maps.Marker({map:i,title:r.label}),r.position instanceof Array?(point=new google.maps.LatLng(r.position[0],r.position[1]),g.setPosition(point),s.extend(point)):n(r.position,function(e){g.setPosition(e[0].geometry.location),s.extend(e[0].geometry.location),l.bounds===!0&&i.fitBounds(s)}),""!==r.icon.image&&g.setIcon("complex"===r.icon.type?new google.maps.MarkerImage(r.icon.image,new google.maps.Size(r.icon.size[0],r.icon.size[1]),new google.maps.Point(r.icon.origin[0],r.icon.origin[1]),new google.maps.Point(r.icon.anchor[0],r.icon.anchor[1])):r.icon.image),""!==r.shadow.image&&g.setShadow(new google.maps.MarkerImage(r.shadow.image,new google.maps.Size(r.shadow.size[0],r.shadow.size[1]),new google.maps.Point(r.shadow.origin[0],r.shadow.origin[1]),new google.maps.Point(r.shadow.anchor[0],r.shadow.anchor[1]))),void 0!==r.click&&google.maps.event.addListener(g,"click",r.click),r.draggable===!0&&(g.setDraggable(!0),google.maps.event.addListener(g,"dragend",r.dragend)),google.maps.event.addListener(g,"click",function(){infoWindow.close(),infoWindow.setOptions({content:r.content}),""!==r.content&&infoWindow.open(i,g)}))}),e(l.polylines).each(function(o,t){var r=e.extend(!0,{},g,t),n="";if("static"===l.map){strokeHex=Math.floor(255*r.stroke.opacity).toString(16),1===strokeHex.length&&(strokeHex=0+strokeHex),n+="color:0x"+r.stroke.color+strokeHex,n+="|weight:"+r.stroke.weight;var c=new google.maps.MVCArray;e(r.points).each(function(e,o){c.push(new google.maps.LatLng(o[0],o[1]))}),n+="|enc:"+google.maps.geometry.encoding.encodePath(c),a+="&path="+n}else{var p=new google.maps.MVCArray;n=new google.maps.Polyline({map:i,path:p,strokeColor:"#"+r.stroke.color,strokeOpacity:r.stroke.opacity,strokeWeight:r.stroke.weight}),e(r.points).each(function(e,o){path=n.getPath(),o=new google.maps.LatLng(o[0],o[1]),path.insertAt(p,o),s.extend(o)})}}),e(l.polygons).each(function(o,t){var r=e.extend(!0,{},p,t),n="";if("static"===l.map){strokeHex=Math.floor(255*r.stroke.opacity).toString(16),1===strokeHex.length&&(strokeHex=0+strokeHex),fillHex=Math.floor(255*r.fill.opacity).toString(16),1===fillHex.length&&(fillHex=0+fillHex),n+="color:0x"+r.stroke.color+strokeHex,n+="|weight:"+r.stroke.weight,n+="|fillcolor:0x"+r.fill.color+fillHex;var c=new google.maps.MVCArray;e(r.points).each(function(e,o){c.push(new google.maps.LatLng(o[0],o[1])),r.points.length-1===e&&c.push(new google.maps.LatLng(r.points[0][0],r.points[0][1]))}),n+="|enc:"+google.maps.geometry.encoding.encodePath(c),a+="&path="+n}else{var g=new google.maps.MVCArray;n=new google.maps.Polygon({map:i,path:g,strokeColor:"#"+r.stroke.color,strokeOpacity:r.stroke.opacity,strokeWeight:r.stroke.weight,fillColor:"#"+r.fill.color,fillOpacity:r.fill.opacity}),e(r.points).each(function(e,o){path=n.getPath(),o=new google.maps.LatLng(o[0],o[1]),path.insertAt(g,o),s.extend(o)})}}),e(l.circles.reverse()).each(function(o,t){var n=e.extend(!0,{},h,t),c="";if("static"===l.map){switch(n.measure){case"m":n.radius=n.radius/1e3;break;case"mi":n.radius=n.radius/.62137}strokeHex=Math.floor(255*n.stroke.opacity).toString(16),1===strokeHex.length&&(strokeHex=0+strokeHex),fillHex=Math.floor(255*n.fill.opacity).toString(16),1===fillHex.length&&(fillHex=0+fillHex),c+="color:0x"+n.stroke.color+strokeHex,c+="|weight:"+n.stroke.weight,c+="|fillcolor:0x"+n.fill.color+fillHex,r=6371,pi=Math.PI,circle_lat=n.center[0]*pi/180,circle_lng=n.center[1]*pi/180,circle_radius=n.radius/r,circle_points=new google.maps.MVCArray;for(var g=0;360>=g;g+=n.detail)brng=g*pi/180,pLat=Math.asin(Math.sin(circle_lat)*Math.cos(circle_radius)+Math.cos(circle_lat)*Math.sin(circle_radius)*Math.cos(brng)),pLng=180*(circle_lng+Math.atan2(Math.sin(brng)*Math.sin(circle_radius)*Math.cos(circle_lat),Math.cos(circle_radius)-Math.sin(circle_lat)*Math.sin(pLat)))/pi,pLat=180*pLat/pi,circle_points.push(new google.maps.LatLng(pLat,pLng));c+="|enc:"+google.maps.geometry.encoding.encodePath(circle_points),console.log(c),a+="&path="+c}else{switch(n.measure){case"km":n.radius=1e3*n.radius;break;case"mi":n.radius=n.radius/62137e-8}c=new google.maps.Circle({map:i,center:new google.maps.LatLng(n.center[0],n.center[1]),radius:n.radius,strokeColor:"#"+n.stroke.color,strokeOpacity:n.stroke.opacity,strokeWeight:n.stroke.weight,fillColor:"#"+n.fill.color,fillOpacity:n.fill.opacity}),s.union(c.getBounds())}}),"static"===l.map?a.length>2048?l.error(t,"URL for image exceeded max length of 2048 characters."):e(t).html('<img src="'+a+'" width="'+l.style.width+'" height="'+l.style.height+'" alt="'+l.title+'">'):l.bounds===!0&&i.fitBounds(s)}),this}}(jQuery);