Simple Map - Version 0.6.1

Version Description

Download this release

Release Info

Developer miyauchi
Plugin Icon wp plugin Simple Map
Version 0.6.1
Comparing to
See all releases

Version 0.6.1

Files changed (6) hide show
  1. js/gmaps.js +8 -0
  2. js/gmaps.src.js +1919 -0
  3. js/simplemap.js +1 -0
  4. js/simplemap.src.js +80 -0
  5. readme.txt +65 -0
  6. simple-map.php +153 -0
js/gmaps.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * GMaps.js v0.3.3
3
+ * http://hpneo.github.com/gmaps/
4
+ *
5
+ * Copyright 2012, Gustavo Leon
6
+ * Released under the MIT License.
7
+ */
8
+ if(window.google&&window.google.maps){var GMaps=(function(c){var d=document;var b=function(g,e){var f;if("jQuery" in c&&e){f=$("#"+g.replace("#",""),e)[0]}else{f=d.getElementById(g.replace("#",""))}return f};var a=function(k){var x=this;var m=["bounds_changed","center_changed","click","dblclick","drag","dragend","dragstart","idle","maptypeid_changed","projection_changed","resize","tilesloaded","zoom_changed"];var q=["mousemove","mouseout","mouseover"];window.context_menu={};if(typeof(k.el)==="string"||typeof(k.div)==="string"){this.el=b(k.el||k.div,k.context)}else{this.el=k.el||k.div}if(typeof(this.el)==="undefined"||this.el===null){throw"No element defined."}this.el.style.width=k.width||this.el.scrollWidth||this.el.offsetWidth;this.el.style.height=k.height||this.el.scrollHeight||this.el.offsetHeight;this.controls=[];this.overlays=[];this.layers=[];this.singleLayers={};this.markers=[];this.polylines=[];this.routes=[];this.polygons=[];this.infoWindow=null;this.overlay_el=null;this.zoom=k.zoom||15;this.registered_events={};var z=k.markerClusterer;var C;if(k.mapType){C=google.maps.MapTypeId[k.mapType.toUpperCase()]}else{C=google.maps.MapTypeId.ROADMAP}var w=new google.maps.LatLng(k.lat,k.lng);delete k.el;delete k.lat;delete k.lng;delete k.mapType;delete k.width;delete k.height;delete k.markerClusterer;var f=k.zoomControlOpt||{style:"DEFAULT",position:"TOP_LEFT"};var I=k.zoomControl||true,A=f.style||"DEFAULT",g=f.position||"TOP_LEFT",s=k.panControl||true,o=k.mapTypeControl||true,r=k.scaleControl||true,p=k.streetViewControl||true,l=l||true;var y={};var u={zoom:this.zoom,center:w,mapTypeId:C};var e={panControl:s,zoomControl:I,zoomControlOptions:{style:google.maps.ZoomControlStyle[A],position:google.maps.ControlPosition[g]},mapTypeControl:o,scaleControl:r,streetViewControl:p,overviewMapControl:l};if(k.disableDefaultUI!=true){u=extend_object(u,e)}y=extend_object(u,k);for(var B=0;B<m.length;B++){delete y[m[B]]}for(var B=0;B<q.length;B++){delete y[q[B]]}this.map=new google.maps.Map(this.el,y);if(z){this.markerClusterer=z.apply(this,[this.map])}var F=function(J){var K=0;var i=0;if(J.offsetParent){do{K+=J.offsetLeft;i+=J.offsetTop}while(J=J.offsetParent)}return[K,i]};var t=function(N,S){var R="";var W=window.context_menu[N];for(var O in W){if(W.hasOwnProperty(O)){var Q=W[O];R+='<li><a id="'+N+"_"+O+'" href="#">'+Q.title+"</a></li>"}}if(!b("gmaps_context_menu")){return}var T=b("gmaps_context_menu");T.innerHTML=R;var J=T.getElementsByTagName("a");var V=J.length;for(var O=0;O<V;O++){var L=J[O];var M=function(i){i.preventDefault();W[this.id.replace(N+"_","")].action.apply(x,[S]);x.hideContextMenu()};google.maps.event.clearListeners(L,"click");google.maps.event.addDomListenerOnce(L,"click",M,false)}var P=F.apply(this,[x.el]);var K=P[0]+S.pixel.x-15;var U=P[1]+S.pixel.y-15;T.style.left=K+"px";T.style.top=U+"px";T.style.display="block"};var G=function(K,J){if(K==="marker"){J.pixel={};var i=new google.maps.OverlayView();i.setMap(x.map);i.draw=function(){var M=i.getProjection();var L=J.marker.getPosition();J.pixel=M.fromLatLngToContainerPixel(L);t(K,J)}}else{t(K,J)}};this.setContextMenu=function(J){window.context_menu[J.control]={};for(var L in J.options){if(J.options.hasOwnProperty(L)){var M=J.options[L];window.context_menu[J.control][M.name]={title:M.title,action:M.action}}}var K=d.createElement("ul");K.id="gmaps_context_menu";K.style.display="none";K.style.position="absolute";K.style.minWidth="100px";K.style.background="white";K.style.listStyle="none";K.style.padding="8px";K.style.boxShadow="2px 2px 6px #ccc";d.body.appendChild(K);var N=b("gmaps_context_menu");google.maps.event.addDomListener(N,"mouseout",function(i){if(!i.relatedTarget||!this.contains(i.relatedTarget)){window.setTimeout(function(){N.style.display="none"},400)}},false)};this.hideContextMenu=function(){var i=b("gmaps_context_menu");if(i){i.style.display="none"}};var v=function(J,i){google.maps.event.addListener(J,i,function(K){if(K==undefined){K=this}k[i].apply(this,[K]);x.hideContextMenu()})};for(var E=0;E<m.length;E++){var H=m[E];if(H in k){v(this.map,H)}}for(var E=0;E<q.length;E++){var H=q[E];if(H in k){v(this.map,H)}}google.maps.event.addListener(this.map,"rightclick",function(i){if(k.rightclick){k.rightclick.apply(this,[i])}if(window.context_menu.map!=undefined){G("map",i)}});this.refresh=function(){google.maps.event.trigger(this.map,"resize")};this.fitZoom=function(){var L=[];var J=this.markers.length;for(var K=0;K<J;K++){L.push(this.markers[K].getPosition())}this.fitLatLngBounds(L)};this.fitLatLngBounds=function(M){var L=M.length;var K=new google.maps.LatLngBounds();for(var J=0;J<L;J++){K.extend(M[J])}this.map.fitBounds(K)};this.setCenter=function(J,i,K){this.map.panTo(new google.maps.LatLng(J,i));if(K){K()}};this.getElement=function(){return this.el};this.zoomIn=function(i){i=i||1;this.zoom=this.map.getZoom()+i;this.map.setZoom(this.zoom)};this.zoomOut=function(i){i=i||1;this.zoom=this.map.getZoom()-i;this.map.setZoom(this.zoom)};var j=[];for(var h in this.map){if(typeof(this.map[h])=="function"&&!this[h]){j.push(h)}}for(var B=0;B<j.length;B++){(function(i,K,J){i[J]=function(){return K[J].apply(K,arguments)}})(this,this.map,j[B])}this.createControl=function(i){var L=d.createElement("div");L.style.cursor="pointer";L.style.fontFamily="Arial, sans-serif";L.style.fontSize="13px";L.style.boxShadow="rgba(0, 0, 0, 0.398438) 0px 2px 4px";for(var J in i.style){L.style[J]=i.style[J]}if(i.id){L.id=i.id}if(i.classes){L.className=i.classes}if(i.content){L.innerHTML=i.content}for(var K in i.events){(function(N,M){google.maps.event.addDomListener(N,M,function(){i.events[M].apply(this,[this])})})(L,K)}L.index=1;return L};this.addControl=function(J){var i=google.maps.ControlPosition[J.position.toUpperCase()];delete J.position;var K=this.createControl(J);this.controls.push(K);this.map.controls[i].push(K);return K};this.createMarker=function(T){if((T.hasOwnProperty("lat")&&T.hasOwnProperty("lng"))||T.position){var S=this;var J=T.details;var N=T.fences;var P=T.outside;var M={position:new google.maps.LatLng(T.lat,T.lng),map:null};delete T.lat;delete T.lng;delete T.fences;delete T.outside;var K=extend_object(M,T);var O=new google.maps.Marker(K);O.fences=N;if(T.infoWindow){O.infoWindow=new google.maps.InfoWindow(T.infoWindow);var i=["closeclick","content_changed","domready","position_changed","zindex_changed"];for(var Q=0;Q<i.length;Q++){(function(V,U){if(T.infoWindow[U]){google.maps.event.addListener(V,U,function(W){T.infoWindow[U].apply(this,[W])})}})(O.infoWindow,i[Q])}}var R=["animation_changed","clickable_changed","cursor_changed","draggable_changed","flat_changed","icon_changed","position_changed","shadow_changed","shape_changed","title_changed","visible_changed","zindex_changed"];var L=["dblclick","drag","dragend","dragstart","mousedown","mouseout","mouseover","mouseup"];for(var Q=0;Q<R.length;Q++){(function(V,U){if(T[U]){google.maps.event.addListener(V,U,function(){T[U].apply(this,[this])})}})(O,R[Q])}for(var Q=0;Q<L.length;Q++){(function(W,V,U){if(T[U]){google.maps.event.addListener(V,U,function(X){if(!X.pixel){X.pixel=W.getProjection().fromLatLngToPoint(X.latLng)}T[U].apply(this,[X])})}})(this.map,O,L[Q])}google.maps.event.addListener(O,"click",function(){this.details=J;if(T.click){T.click.apply(this,[this])}if(O.infoWindow){S.hideInfoWindows();O.infoWindow.open(S.map,O)}});google.maps.event.addListener(O,"rightclick",function(U){U.marker=this;if(T.rightclick){T.rightclick.apply(this,[U])}if(window.context_menu.marker!=undefined){G("marker",U)}});if(O.fences){google.maps.event.addListener(O,"dragend",function(){S.checkMarkerGeofence(O,function(U,V){P(U,V)})})}return O}else{throw"No latitude or longitude defined."}};this.addMarker=function(J){var i;if(J.hasOwnProperty("gm_accessors_")){i=J}else{if((J.hasOwnProperty("lat")&&J.hasOwnProperty("lng"))||J.position){i=this.createMarker(J)}else{throw"No latitude or longitude defined."}}i.setMap(this.map);if(this.markerClusterer){this.markerClusterer.addMarker(i)}this.markers.push(i);a.fire("marker_added",i,this);return i};this.addMarkers=function(L){for(var K=0,J;J=L[K];K++){this.addMarker(J)}return this.markers};this.hideInfoWindows=function(){for(var K=0,J;J=this.markers[K];K++){if(J.infoWindow){J.infoWindow.close()}}};this.removeMarker=function(J){for(var K=0;K<this.markers.length;K++){if(this.markers[K]===J){this.markers[K].setMap(null);this.markers.splice(K,1);a.fire("marker_removed",J,this);break}}return J};this.removeMarkers=function(L){var L=(L||this.markers);for(var K=0;K<this.markers.length;K++){if(this.markers[K]===L[K]){this.markers[K].setMap(null)}}var J=[];for(var K=0;K<this.markers.length;K++){if(this.markers[K].getMap()!=null){J.push(this.markers[K])}}this.markers=J};this.drawOverlay=function(J){var i=new google.maps.OverlayView();i.setMap(x.map);var K=true;if(J.auto_show!=null){K=J.auto_show}i.onAdd=function(){var O=d.createElement("div");O.style.borderStyle="none";O.style.borderWidth="0px";O.style.position="absolute";O.style.zIndex=100;O.innerHTML=J.content;i.el=O;var N=this.getPanes();if(!J.layer){J.layer="overlayLayer"}var L=N[J.layer];L.appendChild(O);var M=["contextmenu","DOMMouseScroll","dblclick","mousedown"];for(var P=0;P<M.length;P++){(function(R,Q){google.maps.event.addDomListener(R,Q,function(S){if(navigator.userAgent.toLowerCase().indexOf("msie")!=-1&&document.all){S.cancelBubble=true;S.returnValue=false}else{S.stopPropagation()}})})(O,M[P])}google.maps.event.trigger(this,"ready")};i.draw=function(){var L=this.getProjection();var N=L.fromLatLngToDivPixel(new google.maps.LatLng(J.lat,J.lng));J.horizontalOffset=J.horizontalOffset||0;J.verticalOffset=J.verticalOffset||0;var O=i.el;var P=O.children[0];var M=P.clientHeight;var Q=P.clientWidth;switch(J.verticalAlign){case"top":O.style.top=(N.y-M+J.verticalOffset)+"px";break;default:case"middle":O.style.top=(N.y-(M/2)+J.verticalOffset)+"px";break;case"bottom":O.style.top=(N.y+J.verticalOffset)+"px";break}switch(J.horizontalAlign){case"left":O.style.left=(N.x-Q+J.horizontalOffset)+"px";break;default:case"center":O.style.left=(N.x-(Q/2)+J.horizontalOffset)+"px";break;case"right":O.style.left=(N.x+J.horizontalOffset)+"px";break}O.style.display=K?"block":"none";if(!K){J.show.apply(this,[O])}};i.onRemove=function(){var L=i.el;if(J.remove){J.remove.apply(this,[L])}else{i.el.parentNode.removeChild(i.el);i.el=null}};x.overlays.push(i);return i};this.removeOverlay=function(J){for(var K=0;K<this.overlays.length;K++){if(this.overlays[K]===J){this.overlays[K].setMap(null);this.overlays.splice(K,1);break}}};this.removeOverlays=function(){for(var J=0,K;K=x.overlays[J];J++){K.setMap(null)}x.overlays=[]};this.drawPolyline=function(R){var Q=[];var O=R.path;if(O.length){if(O[0][0]===undefined){Q=O}else{for(var K=0,J;J=O[K];K++){Q.push(new google.maps.LatLng(J[0],J[1]))}}}var L={map:this.map,path:Q,strokeColor:R.strokeColor,strokeOpacity:R.strokeOpacity,strokeWeight:R.strokeWeight,geodesic:R.geodesic,clickable:true,editable:false,visible:true};if(R.hasOwnProperty("clickable")){L.clickable=R.clickable}if(R.hasOwnProperty("editable")){L.editable=R.editable}if(R.hasOwnProperty("icons")){L.icons=R.icons}if(R.hasOwnProperty("zIndex")){L.zIndex=R.zIndex}var N=new google.maps.Polyline(L);var P=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"];for(var M=0;M<P.length;M++){(function(S,i){if(R[i]){google.maps.event.addListener(S,i,function(T){R[i].apply(this,[T])})}})(N,P[M])}this.polylines.push(N);a.fire("polyline_added",N,this);return N};this.removePolyline=function(J){for(var K=0;K<this.polylines.length;K++){if(this.polylines[K]===J){this.polylines[K].setMap(null);this.polylines.splice(K,1);a.fire("polyline_removed",J,this);break}}};this.removePolylines=function(){for(var J=0,K;K=x.polylines[J];J++){K.setMap(null)}x.polylines=[]};this.drawCircle=function(i){i=extend_object({map:this.map,center:new google.maps.LatLng(i.lat,i.lng)},i);delete i.lat;delete i.lng;var J=new google.maps.Circle(i);var L=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"];for(var K=0;K<L.length;K++){(function(N,M){if(i[M]){google.maps.event.addListener(N,M,function(O){i[M].apply(this,[O])})}})(J,L[K])}this.polygons.push(J);return J};this.drawRectangle=function(i){i=extend_object({map:this.map},i);var L=new google.maps.LatLngBounds(new google.maps.LatLng(i.bounds[0][0],i.bounds[0][1]),new google.maps.LatLng(i.bounds[1][0],i.bounds[1][1]));i.bounds=L;var J=new google.maps.Rectangle(i);var M=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"];for(var K=0;K<M.length;K++){(function(O,N){if(i[N]){google.maps.event.addListener(O,N,function(P){i[N].apply(this,[P])})}})(J,M[K])}this.polygons.push(J);return J};this.drawPolygon=function(i){var L=false;if(i.hasOwnProperty("useGeoJSON")){L=i.useGeoJSON}delete i.useGeoJSON;i=extend_object({map:this.map},i);if(L==false){i.paths=[i.paths.slice(0)]}if(i.paths.length>0){if(i.paths[0].length>0){i.paths=array_flat(array_map(i.paths,arrayToLatLng,L))}}var J=new google.maps.Polygon(i);var M=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"];for(var K=0;K<M.length;K++){(function(O,N){if(i[N]){google.maps.event.addListener(O,N,function(P){i[N].apply(this,[P])})}})(J,M[K])}this.polygons.push(J);a.fire("polygon_added",J,this);return J};this.removePolygon=function(K){for(var J=0;J<this.polygons.length;J++){if(this.polygons[J]===K){this.polygons[J].setMap(null);this.polygons.splice(J,1);a.fire("polygon_removed",K,this);break}}};this.removePolygons=function(){for(var J=0,K;K=x.polygons[J];J++){K.setMap(null)}x.polygons=[]};this.getFromFusionTables=function(J){var L=J.events;delete J.events;var i=J;var K=new google.maps.FusionTablesLayer(i);for(var M in L){(function(O,N){google.maps.event.addListener(O,N,function(P){L[N].apply(this,[P])})})(K,M)}this.layers.push(K);return K};this.loadFromFusionTables=function(i){var J=this.getFromFusionTables(i);J.setMap(this.map);return J};this.getFromKML=function(J){var i=J.url;var L=J.events;delete J.url;delete J.events;var N=J;var K=new google.maps.KmlLayer(i,N);for(var M in L){(function(P,O){google.maps.event.addListener(P,O,function(Q){L[O].apply(this,[Q])})})(K,M)}this.layers.push(K);return K};this.loadFromKML=function(i){var J=this.getFromKML(i);J.setMap(this.map);return J};var D,n;this.getRoutes=function(M){switch(M.travelMode){case"bicycling":D=google.maps.TravelMode.BICYCLING;break;case"transit":D=google.maps.TravelMode.TRANSIT;break;case"driving":D=google.maps.TravelMode.DRIVING;break;default:D=google.maps.TravelMode.WALKING;break}if(M.unitSystem==="imperial"){n=google.maps.UnitSystem.IMPERIAL}else{n=google.maps.UnitSystem.METRIC}var L={avoidHighways:false,avoidTolls:false,optimizeWaypoints:false,waypoints:[]};var K=extend_object(L,M);K.origin=/string/.test(typeof M.origin)?M.origin:new google.maps.LatLng(M.origin[0],M.origin[1]);K.destination=/string/.test(typeof M.destination)?M.destination:new google.maps.LatLng(M.destination[0],M.destination[1]);K.travelMode=D;K.unitSystem=n;delete K.callback;var J=this;var i=new google.maps.DirectionsService();i.route(K,function(N,O){if(O===google.maps.DirectionsStatus.OK){for(var P in N.routes){if(N.routes.hasOwnProperty(P)){J.routes.push(N.routes[P])}}}if(M.callback){M.callback(J.routes)}})};this.removeRoutes=function(){this.routes=[]};this.getElevations=function(J){J=extend_object({locations:[],path:false,samples:256},J);if(J.locations.length>0){if(J.locations[0].length>0){J.locations=array_flat(array_map([J.locations],arrayToLatLng,false))}}var L=J.callback;delete J.callback;var i=new google.maps.ElevationService();if(!J.path){delete J.path;delete J.samples;i.getElevationForLocations(J,function(M,N){if(L&&typeof(L)==="function"){L(M,N)}})}else{var K={path:J.locations,samples:J.samples};i.getElevationAlongPath(K,function(M,N){if(L&&typeof(L)==="function"){L(M,N)}})}};this.cleanRoute=this.removePolylines;this.drawRoute=function(J){var i=this;this.getRoutes({origin:J.origin,destination:J.destination,travelMode:J.travelMode,waypoints:J.waypoints,unitSystem:J.unitSystem,callback:function(K){if(K.length>0){i.drawPolyline({path:K[K.length-1].overview_path,strokeColor:J.strokeColor,strokeOpacity:J.strokeOpacity,strokeWeight:J.strokeWeight});if(J.callback){J.callback(K[K.length-1])}}}})};this.travelRoute=function(K){if(K.origin&&K.destination){this.getRoutes({origin:K.origin,destination:K.destination,travelMode:K.travelMode,waypoints:K.waypoints,callback:function(R){if(R.length>0&&K.start){K.start(R[R.length-1])}if(R.length>0&&K.step){var O=R[R.length-1];if(O.legs.length>0){var N=O.legs[0].steps;for(var P=0,Q;Q=N[P];P++){Q.step_number=P;K.step(Q,(O.legs[0].steps.length-1))}}}if(R.length>0&&K.end){K.end(R[R.length-1])}}})}else{if(K.route){if(K.route.legs.length>0){var J=K.route.legs[0].steps;for(var L=0,M;M=J[L];L++){M.step_number=L;K.step(M)}}}}};this.drawSteppedRoute=function(K){if(K.origin&&K.destination){this.getRoutes({origin:K.origin,destination:K.destination,travelMode:K.travelMode,waypoints:K.waypoints,callback:function(R){if(R.length>0&&K.start){K.start(R[R.length-1])}if(R.length>0&&K.step){var O=R[R.length-1];if(O.legs.length>0){var N=O.legs[0].steps;for(var P=0,Q;Q=N[P];P++){Q.step_number=P;x.drawPolyline({path:Q.path,strokeColor:K.strokeColor,strokeOpacity:K.strokeOpacity,strokeWeight:K.strokeWeight});K.step(Q,(O.legs[0].steps.length-1))}}}if(R.length>0&&K.end){K.end(R[R.length-1])}}})}else{if(K.route){if(K.route.legs.length>0){var J=K.route.legs[0].steps;for(var L=0,M;M=J[L];L++){M.step_number=L;x.drawPolyline({path:M.path,strokeColor:K.strokeColor,strokeOpacity:K.strokeOpacity,strokeWeight:K.strokeWeight});K.step(M)}}}}};this.checkGeofence=function(J,i,K){return K.containsLatLng(new google.maps.LatLng(J,i))};this.checkMarkerGeofence=function(J,L){if(J.fences){for(var K=0,M;M=J.fences[K];K++){var N=J.getPosition();if(!x.checkGeofence(N.lat(),N.lng(),M)){L(J,M)}}}};this.addLayer=function(K,J){J=J||{};var L;switch(K){case"weather":this.singleLayers.weather=L=new google.maps.weather.WeatherLayer();break;case"clouds":this.singleLayers.clouds=L=new google.maps.weather.CloudLayer();break;case"traffic":this.singleLayers.traffic=L=new google.maps.TrafficLayer();break;case"transit":this.singleLayers.transit=L=new google.maps.TransitLayer();break;case"bicycling":this.singleLayers.bicycling=L=new google.maps.BicyclingLayer();break;case"panoramio":this.singleLayers.panoramio=L=new google.maps.panoramio.PanoramioLayer();L.setTag(J.filter);delete J.filter;if(J.click){google.maps.event.addListener(L,"click",function(N){J.click(N);delete J.click})}break;case"places":this.singleLayers.places=L=new google.maps.places.PlacesService(this.map);if(J.search||J.nearbySearch){var i={bounds:J.bounds||null,keyword:J.keyword||null,location:J.location||null,name:J.name||null,radius:J.radius||null,rankBy:J.rankBy||null,types:J.types||null};if(J.search){L.search(i,J.search)}if(J.nearbySearch){L.nearbySearch(i,J.nearbySearch)}}if(J.textSearch){var M={bounds:J.bounds||null,location:J.location||null,query:J.query||null,radius:J.radius||null};L.textSearch(M,J.textSearch)}break}if(L!==undefined){if(typeof L.setOptions=="function"){L.setOptions(J)}if(typeof L.setMap=="function"){L.setMap(this.map)}return L}};this.removeLayer=function(K){if(typeof(K)=="string"&&this.singleLayers[K]!==undefined){this.singleLayers[K].setMap(null);delete this.singleLayers[K]}else{for(var J=0;J<this.layers.length;J++){if(this.layers[J]===K){this.layers[J].setMap(null);this.layers.splice(J,1);break}}}};this.toImage=function(K){var K=K||{};var M={};M.size=K.size||[this.el.clientWidth,this.el.clientHeight];M.lat=this.getCenter().lat();M.lng=this.getCenter().lng();if(this.markers.length>0){M.markers=[];for(var L=0;L<this.markers.length;L++){M.markers.push({lat:this.markers[L].getPosition().lat(),lng:this.markers[L].getPosition().lng()})}}if(this.polylines.length>0){var J=this.polylines[0];M.polyline={};M.polyline["path"]=google.maps.geometry.encoding.encodePath(J.getPath());M.polyline["strokeColor"]=J.strokeColor;M.polyline["strokeOpacity"]=J.strokeOpacity;M.polyline["strokeWeight"]=J.strokeWeight}return a.staticMapURL(M)};this.addMapType=function(i,J){if(J.hasOwnProperty("getTileUrl")&&typeof(J.getTileUrl)=="function"){J.tileSize=J.tileSize||new google.maps.Size(256,256);var K=new google.maps.ImageMapType(J);this.map.mapTypes.set(i,K)}else{throw"'getTileUrl' function required."}};this.addOverlayMapType=function(i){if(i.hasOwnProperty("getTile")&&typeof(i.getTile)=="function"){var J=i.index;delete i.index;this.map.overlayMapTypes.insertAt(J,i)}else{throw"'getTile' function required."}};this.removeOverlayMapType=function(i){this.map.overlayMapTypes.removeAt(i)};this.addStyle=function(J){var i=new google.maps.StyledMapType(J.styles,J.styledMapName);this.map.mapTypes.set(J.mapTypeId,i)};this.setStyle=function(i){this.map.setMapTypeId(i)};this.createPanorama=function(i){if(!i.hasOwnProperty("lat")||!i.hasOwnProperty("lng")){i.lat=this.getCenter().lat();i.lng=this.getCenter().lng()}this.panorama=a.createPanorama(i);this.map.setStreetView(this.panorama);return this.panorama};this.on=function(J,i){return a.on(J,this,i)};this.off=function(i){a.off(i,this)}};a.createPanorama=function(f){var j=b(f.el,f.context);f.position=new google.maps.LatLng(f.lat,f.lng);delete f.el;delete f.context;delete f.lat;delete f.lng;var k=["closeclick","links_changed","pano_changed","position_changed","pov_changed","resize","visible_changed"];var e=extend_object({visible:true},f);for(var h=0;h<k.length;h++){delete e[k[h]]}var g=new google.maps.StreetViewPanorama(j,e);for(var h=0;h<k.length;h++){(function(l,i){if(f[i]){google.maps.event.addListener(l,i,function(){f[i].apply(this)})}})(g,k[h])}return g};a.Route=function(e){this.map=e.map;this.route=e.route;this.step_count=0;this.steps=this.route.legs[0].steps;this.steps_length=this.steps.length;this.polyline=this.map.drawPolyline({path:new google.maps.MVCArray(),strokeColor:e.strokeColor,strokeOpacity:e.strokeOpacity,strokeWeight:e.strokeWeight}).getPath();this.back=function(){if(this.step_count>0){this.step_count--;var g=this.route.legs[0].steps[this.step_count].path;for(var f in g){if(g.hasOwnProperty(f)){this.polyline.pop()}}}};this.forward=function(){if(this.step_count<this.steps_length){var g=this.route.legs[0].steps[this.step_count].path;for(var f in g){if(g.hasOwnProperty(f)){this.polyline.push(g[f])}}this.step_count++}}};a.geolocate=function(e){var f=e.always||e.complete;if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function(g){e.success(g);if(f){f()}},function(g){e.error(g);if(f){f()}},e.options)}else{e.not_supported();if(f){f()}}};a.geocode=function(e){this.geocoder=new google.maps.Geocoder();var f=e.callback;if(e.hasOwnProperty("lat")&&e.hasOwnProperty("lng")){e.latLng=new google.maps.LatLng(e.lat,e.lng)}delete e.lat;delete e.lng;delete e.callback;this.geocoder.geocode(e,function(h,g){f(h,g)})};a.staticMapURL=function(f){var k=[];var x;var g="http://maps.googleapis.com/maps/api/staticmap";if(f.url){g=f.url;delete f.url}g+="?";var v=f.markers;delete f.markers;if(!v&&f.marker){v=[f.marker];delete f.marker}var q=f.polyline;delete f.polyline;if(f.center){k.push("center="+f.center);delete f.center}else{if(f.address){k.push("center="+f.address);delete f.address}else{if(f.lat){k.push(["center=",f.lat,",",f.lng].join(""));delete f.lat;delete f.lng}else{if(f.visible){var e=encodeURI(f.visible.join("|"));k.push("visible="+e)}}}}var o=f.size;if(o){if(o.join){o=o.join("x")}delete f.size}else{o="630x300"}k.push("size="+o);if(!f.zoom){f.zoom=15}var w=f.hasOwnProperty("sensor")?!!f.sensor:true;delete f.sensor;k.push("sensor="+w);for(var l in f){if(f.hasOwnProperty(l)){k.push(l+"="+f[l])}}if(v){var m,n;for(var t=0;x=v[t];t++){m=[];if(x.size&&x.size!=="normal"){m.push("size:"+x.size)}else{if(x.icon){m.push("icon:"+encodeURI(x.icon))}}if(x.color){m.push("color:"+x.color.replace("#","0x"))}if(x.label){m.push("label:"+x.label[0].toUpperCase())}n=(x.address?x.address:x.lat+","+x.lng);if(m.length||t===0){m.push(n);m=m.join("|");k.push("markers="+encodeURI(m))}else{m=k.pop()+encodeURI("|"+n);k.push(m)}}}function u(i,j){if(i[0]==="#"){i=i.replace("#","0x");if(j){j=parseFloat(j);j=Math.min(1,Math.max(j,0));if(j===0){return"0x00000000"}j=(j*255).toString(16);if(j.length===1){j+=j}i=i.slice(0,8)+j}}return i}if(q){x=q;q=[];if(x.strokeWeight){q.push("weight:"+parseInt(x.strokeWeight,10))}if(x.strokeColor){var r=u(x.strokeColor,x.strokeOpacity);q.push("color:"+r)}if(x.fillColor){var y=u(x.fillColor,x.fillOpacity);q.push("fillcolor:"+y)}var p=x.path;if(p.join){for(var s=0,h;h=p[s];s++){q.push(h.join(","))}}else{q.push("enc:"+p)}q=q.join("|");k.push("path="+encodeURI(q))}k=k.join("&");return g+k};a.custom_events=["marker_added","marker_removed","polyline_added","polyline_removed","polygon_added","polygon_removed","geolocated","geolocation_failed"];a.on=function(h,e,g){if(a.custom_events.indexOf(h)==-1){return google.maps.event.addListener(e,h,g)}else{var f={handler:g,eventName:h};e.registered_events[h]=e.registered_events[h]||[];e.registered_events[h].push(f);return f}};a.off=function(f,e){if(a.custom_events.indexOf(f)==-1){google.maps.event.clearListeners(e,f)}else{e.registered_events[f]=[]}};a.fire=function(j,e,h){if(a.custom_events.indexOf(j)==-1){google.maps.event.trigger(e,j,Array.prototype.slice.apply(arguments).slice(2))}else{if(j in h.registered_events){var g=h.registered_events[j];for(var f=0;f<g.length;f++){(function(l,k,i){l.apply(k,[i])})(g[f]["handler"],h,e)}}}};if(!google.maps.Polygon.prototype.getBounds){google.maps.Polygon.prototype.getBounds=function(g){var f=new google.maps.LatLngBounds();var k=this.getPaths();var j;for(var h=0;h<k.getLength();h++){j=k.getAt(h);for(var e=0;e<j.getLength();e++){f.extend(j.getAt(e))}}return f}}if(!google.maps.Polygon.prototype.containsLatLng){google.maps.Polygon.prototype.containsLatLng=function(k){var e=this.getBounds();if(e!==null&&!e.contains(k)){return false}var g=false;var f=this.getPaths().getLength();for(var h=0;h<f;h++){var r=this.getPaths().getAt(h);var n=r.getLength();var l=n-1;for(var m=0;m<n;m++){var q=r.getAt(m);var o=r.getAt(l);if(q.lng()<k.lng()&&o.lng()>=k.lng()||o.lng()<k.lng()&&q.lng()>=k.lng()){if(q.lat()+(k.lng()-q.lng())/(o.lng()-q.lng())*(o.lat()-q.lat())<k.lat()){g=!g}}l=m}}return g}}google.maps.LatLngBounds.prototype.containsLatLng=function(e){return this.contains(e)};google.maps.Marker.prototype.setFences=function(e){this.fences=e};google.maps.Marker.prototype.addFence=function(e){this.fences.push(e)};return a}(this));var coordsToLatLngs=function(b,c){var d=b[0];var a=b[1];if(c){d=b[1];a=b[0]}return new google.maps.LatLng(d,a)};var arrayToLatLng=function(b,c){for(var a=0;a<b.length;a++){if(b[a].length>0&&typeof(b[a][0])!="number"){b[a]=arrayToLatLng(b[a],c)}else{b[a]=coordsToLatLngs(b[a],c)}}return b};var extend_object=function(b,c){if(b===c){return b}for(var a in c){b[a]=c[a]}return b};var replace_object=function(c,b){if(c===b){return c}for(var a in b){if(c[a]!=undefined){c[a]=b[a]}}return c};var array_map=function(f,e){var b=Array.prototype.slice.call(arguments,2);if(Array.prototype.map&&f.map===Array.prototype.map){return Array.prototype.map.call(f,function(g){callback_params=b;callback_params.splice(0,0,g);return e.apply(this,callback_params)})}else{var d=[];var a=f.length;for(var c=0;c<a;c++){callback_params=b;callback_params=callback_params.splice(0,0,f[c]);d.push(e.apply(this,callback_params))}return d}};var array_flat=function(b){new_array=[];for(var a=0;a<b.length;a++){new_array=new_array.concat(b[a])}return new_array}}else{throw"Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true."};
js/gmaps.src.js ADDED
@@ -0,0 +1,1919 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * GMaps.js v0.3.3
3
+ * http://hpneo.github.com/gmaps/
4
+ *
5
+ * Copyright 2012, Gustavo Leon
6
+ * Released under the MIT License.
7
+ */
8
+
9
+ if(window.google && window.google.maps){
10
+
11
+ var GMaps = (function(global) {
12
+ "use strict";
13
+
14
+ var doc = document;
15
+ var getElementById = function(id, context) {
16
+ var ele
17
+ if('jQuery' in global && context){
18
+ ele = $("#"+id.replace('#', ''), context)[0]
19
+ } else {
20
+ ele = doc.getElementById(id.replace('#', ''));
21
+ };
22
+ return ele;
23
+ };
24
+
25
+ var GMaps = function(options) {
26
+ var self = this;
27
+
28
+ var events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'];
29
+ var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'];
30
+
31
+ window.context_menu = {};
32
+
33
+ if (typeof(options.el) === 'string' || typeof(options.div) === 'string') {
34
+ this.el = getElementById(options.el || options.div, options.context);
35
+ } else {
36
+ this.el = options.el || options.div;
37
+ };
38
+
39
+ if (typeof(this.el) === 'undefined' || this.el === null) {
40
+ throw 'No element defined.';
41
+ }
42
+
43
+ this.el.style.width = options.width || this.el.scrollWidth || this.el.offsetWidth;
44
+ this.el.style.height = options.height || this.el.scrollHeight || this.el.offsetHeight;
45
+
46
+ this.controls = [];
47
+ this.overlays = [];
48
+ this.layers = []; // array with kml and ft layers, can be as many
49
+ this.singleLayers = {}; // object with the other layers, only one per layer
50
+ this.markers = [];
51
+ this.polylines = [];
52
+ this.routes = [];
53
+ this.polygons = [];
54
+ this.infoWindow = null;
55
+ this.overlay_el = null;
56
+ this.zoom = options.zoom || 15;
57
+ this.registered_events = {};
58
+
59
+ var markerClusterer = options.markerClusterer;
60
+
61
+ //'Hybrid', 'Roadmap', 'Satellite' or 'Terrain'
62
+ var mapType;
63
+
64
+ if (options.mapType) {
65
+ mapType = google.maps.MapTypeId[options.mapType.toUpperCase()];
66
+ }
67
+ else {
68
+ mapType = google.maps.MapTypeId.ROADMAP;
69
+ }
70
+
71
+ var map_center = new google.maps.LatLng(options.lat, options.lng);
72
+
73
+ delete options.el;
74
+ delete options.lat;
75
+ delete options.lng;
76
+ delete options.mapType;
77
+ delete options.width;
78
+ delete options.height;
79
+ delete options.markerClusterer;
80
+
81
+ var zoomControlOpt = options.zoomControlOpt || {
82
+ style: 'DEFAULT',
83
+ position: 'TOP_LEFT'
84
+ };
85
+
86
+ var zoomControl = options.zoomControl || true,
87
+ zoomControlStyle = zoomControlOpt.style || 'DEFAULT',
88
+ zoomControlPosition = zoomControlOpt.position || 'TOP_LEFT',
89
+ panControl = options.panControl || true,
90
+ mapTypeControl = options.mapTypeControl || true,
91
+ scaleControl = options.scaleControl || true,
92
+ streetViewControl = options.streetViewControl || true,
93
+ overviewMapControl = overviewMapControl || true;
94
+
95
+ var map_options = {};
96
+
97
+ var map_base_options = {
98
+ zoom: this.zoom,
99
+ center: map_center,
100
+ mapTypeId: mapType
101
+ };
102
+
103
+ var map_controls_options = {
104
+ panControl: panControl,
105
+ zoomControl: zoomControl,
106
+ zoomControlOptions: {
107
+ style: google.maps.ZoomControlStyle[zoomControlStyle], // DEFAULT LARGE SMALL
108
+ position: google.maps.ControlPosition[zoomControlPosition]
109
+ },
110
+ mapTypeControl: mapTypeControl,
111
+ scaleControl: scaleControl,
112
+ streetViewControl: streetViewControl,
113
+ overviewMapControl: overviewMapControl
114
+ }
115
+
116
+ if(options.disableDefaultUI != true)
117
+ map_base_options = extend_object(map_base_options, map_controls_options);
118
+
119
+ map_options = extend_object(map_base_options, options);
120
+
121
+ for(var i = 0; i < events_that_hide_context_menu.length; i++) {
122
+ delete map_options[events_that_hide_context_menu[i]];
123
+ }
124
+
125
+ for(var i = 0; i < events_that_doesnt_hide_context_menu.length; i++) {
126
+ delete map_options[events_that_doesnt_hide_context_menu[i]];
127
+ }
128
+
129
+ this.map = new google.maps.Map(this.el, map_options);
130
+
131
+ if(markerClusterer) {
132
+ this.markerClusterer = markerClusterer.apply(this, [this.map]);
133
+ }
134
+
135
+ // finds absolute position of an element
136
+ var findAbsolutePosition = function(obj) {
137
+ var curleft = 0;
138
+ var curtop = 0;
139
+ if (obj.offsetParent) {
140
+ do {
141
+ curleft += obj.offsetLeft;
142
+ curtop += obj.offsetTop;
143
+ } while (obj = obj.offsetParent);
144
+ }
145
+ return [curleft,curtop];
146
+ //returns an array
147
+ }
148
+
149
+
150
+ // Context menus
151
+ var buildContextMenuHTML = function(control, e) {
152
+ var html = '';
153
+ var options = window.context_menu[control];
154
+ for (var i in options){
155
+ if (options.hasOwnProperty(i)){
156
+ var option = options[i];
157
+ html += '<li><a id="' + control + '_' + i + '" href="#">' +
158
+ option.title + '</a></li>';
159
+ }
160
+ }
161
+
162
+ if(!getElementById('gmaps_context_menu')) return;
163
+
164
+ var context_menu_element = getElementById('gmaps_context_menu');
165
+ context_menu_element.innerHTML = html;
166
+
167
+ var context_menu_items = context_menu_element.getElementsByTagName('a');
168
+
169
+ var context_menu_items_count = context_menu_items.length;
170
+
171
+ for(var i = 0; i < context_menu_items_count; i++){
172
+ var context_menu_item = context_menu_items[i];
173
+
174
+ var assign_menu_item_action = function(ev){
175
+ ev.preventDefault();
176
+
177
+ options[this.id.replace(control + '_', '')].action.apply(self, [e]);
178
+ self.hideContextMenu();
179
+ };
180
+
181
+ google.maps.event.clearListeners(context_menu_item, 'click');
182
+ google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
183
+ }
184
+
185
+ var position = findAbsolutePosition.apply(this, [self.el]);
186
+ var left = position[0] + e.pixel.x - 15;
187
+ var top = position[1] + e.pixel.y- 15;
188
+
189
+ context_menu_element.style.left = left + "px";
190
+ context_menu_element.style.top = top + "px";
191
+
192
+ context_menu_element.style.display = 'block';
193
+ };
194
+
195
+ var buildContextMenu = function(control, e) {
196
+ if (control === 'marker') {
197
+ e.pixel = {};
198
+ var overlay = new google.maps.OverlayView();
199
+ overlay.setMap(self.map);
200
+ overlay.draw = function() {
201
+ var projection = overlay.getProjection();
202
+ var position = e.marker.getPosition();
203
+ e.pixel = projection.fromLatLngToContainerPixel(position);
204
+
205
+ buildContextMenuHTML(control, e);
206
+ };
207
+ }
208
+ else {
209
+ buildContextMenuHTML(control, e);
210
+ }
211
+ };
212
+
213
+ this.setContextMenu = function(options) {
214
+ window.context_menu[options.control] = {};
215
+
216
+ for (var i in options.options){
217
+ if (options.options.hasOwnProperty(i)){
218
+ var option = options.options[i];
219
+ window.context_menu[options.control][option.name] = {
220
+ title: option.title,
221
+ action: option.action
222
+ };
223
+ }
224
+ }
225
+
226
+ var ul = doc.createElement('ul');
227
+
228
+ ul.id = 'gmaps_context_menu';
229
+ ul.style.display = 'none';
230
+ ul.style.position = 'absolute';
231
+ ul.style.minWidth = '100px';
232
+ ul.style.background = 'white';
233
+ ul.style.listStyle = 'none';
234
+ ul.style.padding = '8px';
235
+ ul.style.boxShadow = '2px 2px 6px #ccc';
236
+
237
+ doc.body.appendChild(ul);
238
+
239
+ var context_menu_element = getElementById('gmaps_context_menu');
240
+
241
+ google.maps.event.addDomListener(context_menu_element, 'mouseout', function(ev) {
242
+ if(!ev.relatedTarget || !this.contains(ev.relatedTarget)){
243
+ window.setTimeout(function(){
244
+ context_menu_element.style.display = 'none';
245
+ }, 400);
246
+ }
247
+ }, false);
248
+ };
249
+
250
+ this.hideContextMenu = function() {
251
+ var context_menu_element = getElementById('gmaps_context_menu');
252
+ if(context_menu_element)
253
+ context_menu_element.style.display = 'none';
254
+ };
255
+
256
+ //Events
257
+
258
+ var setupListener = function(object, name) {
259
+ google.maps.event.addListener(object, name, function(e){
260
+ if(e == undefined) {
261
+ e = this;
262
+ }
263
+
264
+ options[name].apply(this, [e]);
265
+
266
+ self.hideContextMenu();
267
+ });
268
+ }
269
+
270
+ for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
271
+ var name = events_that_hide_context_menu[ev];
272
+
273
+ if (name in options) {
274
+ setupListener(this.map, name);
275
+ }
276
+ }
277
+
278
+ for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
279
+ var name = events_that_doesnt_hide_context_menu[ev];
280
+
281
+ if (name in options) {
282
+ setupListener(this.map, name);
283
+ }
284
+ }
285
+
286
+ google.maps.event.addListener(this.map, 'rightclick', function(e) {
287
+ if (options.rightclick) {
288
+ options.rightclick.apply(this, [e]);
289
+ }
290
+
291
+ if(window.context_menu['map'] != undefined) {
292
+ buildContextMenu('map', e);
293
+ }
294
+ });
295
+
296
+ this.refresh = function() {
297
+ google.maps.event.trigger(this.map, 'resize');
298
+ };
299
+
300
+ this.fitZoom = function() {
301
+ var latLngs = [];
302
+ var markers_length = this.markers.length;
303
+
304
+ for(var i=0; i < markers_length; i++) {
305
+ latLngs.push(this.markers[i].getPosition());
306
+ }
307
+
308
+ this.fitLatLngBounds(latLngs);
309
+ };
310
+
311
+ this.fitLatLngBounds = function(latLngs) {
312
+ var total = latLngs.length;
313
+ var bounds = new google.maps.LatLngBounds();
314
+
315
+ for(var i=0; i < total; i++) {
316
+ bounds.extend(latLngs[i]);
317
+ }
318
+
319
+ this.map.fitBounds(bounds);
320
+ };
321
+
322
+ // Map methods
323
+ this.setCenter = function(lat, lng, callback) {
324
+ this.map.panTo(new google.maps.LatLng(lat, lng));
325
+ if (callback) {
326
+ callback();
327
+ }
328
+ };
329
+
330
+ this.getElement = function() {
331
+ return this.el;
332
+ };
333
+
334
+ this.zoomIn = function(value) {
335
+ value = value || 1;
336
+ this.zoom = this.map.getZoom() + value;
337
+ this.map.setZoom(this.zoom);
338
+ };
339
+
340
+ this.zoomOut = function(value) {
341
+ value = value || 1;
342
+ this.zoom = this.map.getZoom() - value;
343
+ this.map.setZoom(this.zoom);
344
+ };
345
+
346
+ var native_methods = [];
347
+
348
+ for(var method in this.map){
349
+ if(typeof(this.map[method]) == 'function' && !this[method]){
350
+ native_methods.push(method);
351
+ }
352
+ }
353
+
354
+ for(var i=0; i < native_methods.length; i++){
355
+ (function(gmaps, scope, method_name) {
356
+ gmaps[method_name] = function(){
357
+ return scope[method_name].apply(scope, arguments);
358
+ };
359
+ })(this, this.map, native_methods[i]);
360
+ }
361
+
362
+ this.createControl = function(options) {
363
+ var control = doc.createElement('div');
364
+
365
+ control.style.cursor = 'pointer';
366
+ control.style.fontFamily = 'Arial, sans-serif';
367
+ control.style.fontSize = '13px';
368
+ control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
369
+
370
+ for(var option in options.style)
371
+ control.style[option] = options.style[option];
372
+
373
+ if(options.id) {
374
+ control.id = options.id;
375
+ }
376
+
377
+ if(options.classes) {
378
+ control.className = options.classes;
379
+ }
380
+
381
+ if(options.content) {
382
+ control.innerHTML = options.content;
383
+ }
384
+
385
+ for (var ev in options.events) {
386
+ (function(object, name) {
387
+ google.maps.event.addDomListener(object, name, function(){
388
+ options.events[name].apply(this, [this]);
389
+ });
390
+ })(control, ev);
391
+ }
392
+
393
+ control.index = 1;
394
+
395
+ return control;
396
+ };
397
+
398
+ this.addControl = function(options) {
399
+ var position = google.maps.ControlPosition[options.position.toUpperCase()];
400
+
401
+ delete options.position;
402
+
403
+ var control = this.createControl(options);
404
+ this.controls.push(control);
405
+ this.map.controls[position].push(control);
406
+
407
+ return control;
408
+ };
409
+
410
+ // Markers
411
+ this.createMarker = function(options) {
412
+ if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) {
413
+ var self = this;
414
+ var details = options.details;
415
+ var fences = options.fences;
416
+ var outside = options.outside;
417
+
418
+ var base_options = {
419
+ position: new google.maps.LatLng(options.lat, options.lng),
420
+ map: null
421
+ };
422
+
423
+ delete options.lat;
424
+ delete options.lng;
425
+ delete options.fences;
426
+ delete options.outside;
427
+
428
+ var marker_options = extend_object(base_options, options);
429
+
430
+ var marker = new google.maps.Marker(marker_options);
431
+
432
+ marker.fences = fences;
433
+
434
+ if (options.infoWindow) {
435
+ marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
436
+
437
+ var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
438
+
439
+ for (var ev = 0; ev < info_window_events.length; ev++) {
440
+ (function(object, name) {
441
+ if (options.infoWindow[name]) {
442
+ google.maps.event.addListener(object, name, function(e){
443
+ options.infoWindow[name].apply(this, [e]);
444
+ });
445
+ }
446
+ })(marker.infoWindow, info_window_events[ev]);
447
+ }
448
+ }
449
+
450
+ var marker_events = ['animation_changed', 'clickable_changed', 'cursor_changed', 'draggable_changed', 'flat_changed', 'icon_changed', 'position_changed', 'shadow_changed', 'shape_changed', 'title_changed', 'visible_changed', 'zindex_changed'];
451
+
452
+ var marker_events_with_mouse = ['dblclick', 'drag', 'dragend', 'dragstart', 'mousedown', 'mouseout', 'mouseover', 'mouseup'];
453
+
454
+ for (var ev = 0; ev < marker_events.length; ev++) {
455
+ (function(object, name) {
456
+ if (options[name]) {
457
+ google.maps.event.addListener(object, name, function(){
458
+ options[name].apply(this, [this]);
459
+ });
460
+ }
461
+ })(marker, marker_events[ev]);
462
+ }
463
+
464
+ for (var ev = 0; ev < marker_events_with_mouse.length; ev++) {
465
+ (function(map, object, name) {
466
+ if (options[name]) {
467
+ google.maps.event.addListener(object, name, function(me){
468
+ if(!me.pixel){
469
+ me.pixel = map.getProjection().fromLatLngToPoint(me.latLng)
470
+ }
471
+
472
+ options[name].apply(this, [me]);
473
+ });
474
+ }
475
+ })(this.map, marker, marker_events_with_mouse[ev]);
476
+ }
477
+
478
+ google.maps.event.addListener(marker, 'click', function() {
479
+ this.details = details;
480
+
481
+ if (options.click) {
482
+ options.click.apply(this, [this]);
483
+ }
484
+
485
+ if (marker.infoWindow) {
486
+ self.hideInfoWindows();
487
+ marker.infoWindow.open(self.map, marker);
488
+ }
489
+ });
490
+
491
+ google.maps.event.addListener(marker, 'rightclick', function(e) {
492
+ e.marker = this;
493
+
494
+ if (options.rightclick) {
495
+ options.rightclick.apply(this, [e]);
496
+ }
497
+
498
+ if (window.context_menu['marker'] != undefined) {
499
+ buildContextMenu('marker', e);
500
+ }
501
+ });
502
+
503
+ if (marker.fences) {
504
+ google.maps.event.addListener(marker, 'dragend', function() {
505
+ self.checkMarkerGeofence(marker, function(m, f) {
506
+ outside(m, f);
507
+ });
508
+ });
509
+ }
510
+
511
+ return marker;
512
+ }
513
+ else {
514
+ throw 'No latitude or longitude defined.';
515
+ }
516
+ };
517
+
518
+ this.addMarker = function(options) {
519
+ var marker;
520
+ if(options.hasOwnProperty('gm_accessors_')) {
521
+ // Native google.maps.Marker object
522
+ marker = options;
523
+ }
524
+ else {
525
+ if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) {
526
+ marker = this.createMarker(options);
527
+ }
528
+ else {
529
+ throw 'No latitude or longitude defined.';
530
+ }
531
+ }
532
+
533
+ marker.setMap(this.map);
534
+
535
+ if(this.markerClusterer) {
536
+ this.markerClusterer.addMarker(marker);
537
+ }
538
+
539
+ this.markers.push(marker);
540
+
541
+ GMaps.fire('marker_added', marker, this);
542
+
543
+ return marker;
544
+ };
545
+
546
+ this.addMarkers = function(array) {
547
+ for (var i=0, marker; marker=array[i]; i++) {
548
+ this.addMarker(marker);
549
+ }
550
+ return this.markers;
551
+ };
552
+
553
+ this.hideInfoWindows = function() {
554
+ for (var i=0, marker; marker=this.markers[i]; i++){
555
+ if (marker.infoWindow){
556
+ marker.infoWindow.close();
557
+ }
558
+ }
559
+ };
560
+
561
+ this.removeMarker = function(marker) {
562
+ for(var i = 0; i < this.markers.length; i++) {
563
+ if(this.markers[i] === marker) {
564
+ this.markers[i].setMap(null);
565
+ this.markers.splice(i, 1);
566
+
567
+ GMaps.fire('marker_removed', marker, this);
568
+
569
+ break;
570
+ }
571
+ }
572
+
573
+ return marker;
574
+ };
575
+
576
+ this.removeMarkers = function(collection) {
577
+ var collection = (collection || this.markers);
578
+
579
+ for(var i=0;i < this.markers.length; i++){
580
+ if(this.markers[i] === collection[i])
581
+ this.markers[i].setMap(null);
582
+ }
583
+
584
+ var new_markers = [];
585
+
586
+ for(var i=0;i < this.markers.length; i++){
587
+ if(this.markers[i].getMap() != null)
588
+ new_markers.push(this.markers[i]);
589
+ }
590
+
591
+ this.markers = new_markers;
592
+ };
593
+
594
+ // Overlays
595
+
596
+ this.drawOverlay = function(options) {
597
+ var overlay = new google.maps.OverlayView();
598
+ overlay.setMap(self.map);
599
+
600
+ var auto_show = true;
601
+
602
+ if(options.auto_show != null)
603
+ auto_show = options.auto_show;
604
+
605
+ overlay.onAdd = function() {
606
+ var el = doc.createElement('div');
607
+ el.style.borderStyle = "none";
608
+ el.style.borderWidth = "0px";
609
+ el.style.position = "absolute";
610
+ el.style.zIndex = 100;
611
+ el.innerHTML = options.content;
612
+
613
+ overlay.el = el;
614
+
615
+ var panes = this.getPanes();
616
+ if (!options.layer) {
617
+ options.layer = 'overlayLayer';
618
+ }
619
+ var overlayLayer = panes[options.layer];
620
+ overlayLayer.appendChild(el);
621
+
622
+ var stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown'];
623
+
624
+ for (var ev = 0; ev < stop_overlay_events.length; ev++) {
625
+ (function(object, name) {
626
+ google.maps.event.addDomListener(object, name, function(e){
627
+ if(navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) {
628
+ e.cancelBubble = true;
629
+ e.returnValue = false;
630
+ }
631
+ else {
632
+ e.stopPropagation();
633
+ }
634
+ });
635
+ })(el, stop_overlay_events[ev]);
636
+ }
637
+
638
+ google.maps.event.trigger(this, 'ready');
639
+ };
640
+
641
+ overlay.draw = function() {
642
+ var projection = this.getProjection();
643
+ var pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
644
+
645
+ options.horizontalOffset = options.horizontalOffset || 0;
646
+ options.verticalOffset = options.verticalOffset || 0;
647
+
648
+ var el = overlay.el;
649
+ var content = el.children[0];
650
+
651
+ var content_height = content.clientHeight;
652
+ var content_width = content.clientWidth;
653
+
654
+ switch (options.verticalAlign) {
655
+ case 'top':
656
+ el.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
657
+ break;
658
+ default:
659
+ case 'middle':
660
+ el.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
661
+ break;
662
+ case 'bottom':
663
+ el.style.top = (pixel.y + options.verticalOffset) + 'px';
664
+ break;
665
+ }
666
+
667
+ switch (options.horizontalAlign) {
668
+ case 'left':
669
+ el.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
670
+ break;
671
+ default:
672
+ case 'center':
673
+ el.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
674
+ break;
675
+ case 'right':
676
+ el.style.left = (pixel.x + options.horizontalOffset) + 'px';
677
+ break;
678
+ }
679
+
680
+ el.style.display = auto_show ? 'block' : 'none';
681
+
682
+ if(!auto_show){
683
+ options.show.apply(this, [el]);
684
+ }
685
+ };
686
+
687
+ overlay.onRemove = function() {
688
+ var el = overlay.el;
689
+
690
+ if(options.remove){
691
+ options.remove.apply(this, [el]);
692
+ }
693
+ else {
694
+ overlay.el.parentNode.removeChild(overlay.el);
695
+ overlay.el = null;
696
+ }
697
+ };
698
+
699
+ self.overlays.push(overlay);
700
+ return overlay;
701
+ };
702
+
703
+ this.removeOverlay = function(overlay) {
704
+ for(var i = 0; i < this.overlays.length; i++) {
705
+ if(this.overlays[i] === overlay) {
706
+ this.overlays[i].setMap(null);
707
+ this.overlays.splice(i, 1);
708
+
709
+ break;
710
+ }
711
+ }
712
+ };
713
+
714
+ this.removeOverlays = function() {
715
+ for (var i=0, item; item=self.overlays[i]; i++){
716
+ item.setMap(null);
717
+ }
718
+ self.overlays = [];
719
+ };
720
+
721
+ // Geometry
722
+
723
+ this.drawPolyline = function(options) {
724
+ var path = [];
725
+ var points = options.path;
726
+
727
+ if (points.length){
728
+ if (points[0][0] === undefined){
729
+ path = points;
730
+ }
731
+ else {
732
+ for (var i=0, latlng; latlng=points[i]; i++){
733
+ path.push(new google.maps.LatLng(latlng[0], latlng[1]));
734
+ }
735
+ }
736
+ }
737
+
738
+ var polyline_options = {
739
+ map: this.map,
740
+ path: path,
741
+ strokeColor: options.strokeColor,
742
+ strokeOpacity: options.strokeOpacity,
743
+ strokeWeight: options.strokeWeight,
744
+ geodesic: options.geodesic,
745
+ clickable: true,
746
+ editable: false,
747
+ visible: true
748
+ };
749
+
750
+ if(options.hasOwnProperty("clickable"))
751
+ polyline_options.clickable = options.clickable;
752
+
753
+ if(options.hasOwnProperty("editable"))
754
+ polyline_options.editable = options.editable;
755
+
756
+ if(options.hasOwnProperty("icons"))
757
+ polyline_options.icons = options.icons;
758
+
759
+ if(options.hasOwnProperty("zIndex"))
760
+ polyline_options.zIndex = options.zIndex;
761
+
762
+ var polyline = new google.maps.Polyline(polyline_options);
763
+
764
+ var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
765
+
766
+ for (var ev = 0; ev < polyline_events.length; ev++) {
767
+ (function(object, name) {
768
+ if (options[name]) {
769
+ google.maps.event.addListener(object, name, function(e){
770
+ options[name].apply(this, [e]);
771
+ });
772
+ }
773
+ })(polyline, polyline_events[ev]);
774
+ }
775
+
776
+ this.polylines.push(polyline);
777
+
778
+ GMaps.fire('polyline_added', polyline, this);
779
+
780
+ return polyline;
781
+ };
782
+
783
+ this.removePolyline = function(polyline) {
784
+ for(var i = 0; i < this.polylines.length; i++) {
785
+ if(this.polylines[i] === polyline) {
786
+ this.polylines[i].setMap(null);
787
+ this.polylines.splice(i, 1);
788
+
789
+ GMaps.fire('polyline_removed', polyline, this);
790
+
791
+ break;
792
+ }
793
+ }
794
+ };
795
+
796
+ this.removePolylines = function() {
797
+ for (var i=0, item; item=self.polylines[i]; i++){
798
+ item.setMap(null);
799
+ }
800
+ self.polylines = [];
801
+ };
802
+
803
+ this.drawCircle = function(options) {
804
+ options = extend_object({
805
+ map: this.map,
806
+ center: new google.maps.LatLng(options.lat, options.lng)
807
+ }, options);
808
+
809
+ delete options.lat;
810
+ delete options.lng;
811
+ var polygon = new google.maps.Circle(options);
812
+
813
+ var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
814
+
815
+ for (var ev = 0; ev < polygon_events.length; ev++) {
816
+ (function(object, name) {
817
+ if (options[name]) {
818
+ google.maps.event.addListener(object, name, function(e){
819
+ options[name].apply(this, [e]);
820
+ });
821
+ }
822
+ })(polygon, polygon_events[ev]);
823
+ }
824
+
825
+ this.polygons.push(polygon);
826
+
827
+ return polygon;
828
+ };
829
+
830
+ this.drawRectangle = function(options) {
831
+ options = extend_object({
832
+ map: this.map
833
+ }, options);
834
+
835
+ var latLngBounds = new google.maps.LatLngBounds(
836
+ new google.maps.LatLng(options.bounds[0][0], options.bounds[0][1]),
837
+ new google.maps.LatLng(options.bounds[1][0], options.bounds[1][1])
838
+ );
839
+
840
+ options.bounds = latLngBounds;
841
+
842
+ var polygon = new google.maps.Rectangle(options);
843
+
844
+ var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
845
+
846
+ for (var ev = 0; ev < polygon_events.length; ev++) {
847
+ (function(object, name) {
848
+ if (options[name]) {
849
+ google.maps.event.addListener(object, name, function(e){
850
+ options[name].apply(this, [e]);
851
+ });
852
+ }
853
+ })(polygon, polygon_events[ev]);
854
+ }
855
+
856
+ this.polygons.push(polygon);
857
+
858
+ return polygon;
859
+ };
860
+
861
+ this.drawPolygon = function(options) {
862
+ var useGeoJSON = false;
863
+ if(options.hasOwnProperty("useGeoJSON"))
864
+ useGeoJSON = options.useGeoJSON;
865
+
866
+ delete options.useGeoJSON;
867
+
868
+ options = extend_object({
869
+ map: this.map
870
+ }, options);
871
+
872
+ if(useGeoJSON == false)
873
+ options.paths = [options.paths.slice(0)];
874
+
875
+ if(options.paths.length > 0) {
876
+ if(options.paths[0].length > 0) {
877
+ options.paths = array_flat(array_map(options.paths, arrayToLatLng, useGeoJSON));
878
+ }
879
+ }
880
+
881
+ var polygon = new google.maps.Polygon(options);
882
+
883
+ var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
884
+
885
+ for (var ev = 0; ev < polygon_events.length; ev++) {
886
+ (function(object, name) {
887
+ if (options[name]) {
888
+ google.maps.event.addListener(object, name, function(e){
889
+ options[name].apply(this, [e]);
890
+ });
891
+ }
892
+ })(polygon, polygon_events[ev]);
893
+ }
894
+
895
+ this.polygons.push(polygon);
896
+
897
+ GMaps.fire('polygon_added', polygon, this);
898
+
899
+ return polygon;
900
+ };
901
+
902
+ this.removePolygon = function(polygon) {
903
+ for(var i = 0; i < this.polygons.length; i++) {
904
+ if(this.polygons[i] === polygon) {
905
+ this.polygons[i].setMap(null);
906
+ this.polygons.splice(i, 1);
907
+
908
+ GMaps.fire('polygon_removed', polygon, this);
909
+
910
+ break;
911
+ }
912
+ }
913
+ };
914
+
915
+ this.removePolygons = function() {
916
+ for (var i=0, item; item=self.polygons[i]; i++){
917
+ item.setMap(null);
918
+ }
919
+ self.polygons = [];
920
+ };
921
+
922
+ // Fusion Tables
923
+
924
+ this.getFromFusionTables = function(options) {
925
+ var events = options.events;
926
+
927
+ delete options.events;
928
+
929
+ var fusion_tables_options = options;
930
+
931
+ var layer = new google.maps.FusionTablesLayer(fusion_tables_options);
932
+
933
+ for (var ev in events) {
934
+ (function(object, name) {
935
+ google.maps.event.addListener(object, name, function(e){
936
+ events[name].apply(this, [e]);
937
+ });
938
+ })(layer, ev);
939
+ }
940
+
941
+ this.layers.push(layer);
942
+
943
+ return layer;
944
+ };
945
+
946
+ this.loadFromFusionTables = function(options) {
947
+ var layer = this.getFromFusionTables(options);
948
+ layer.setMap(this.map);
949
+
950
+ return layer;
951
+ };
952
+
953
+ // KML
954
+
955
+ this.getFromKML = function(options) {
956
+ var url = options.url;
957
+ var events = options.events;
958
+
959
+ delete options.url;
960
+ delete options.events;
961
+
962
+ var kml_options = options;
963
+
964
+ var layer = new google.maps.KmlLayer(url, kml_options);
965
+
966
+ for (var ev in events) {
967
+ (function(object, name) {
968
+ google.maps.event.addListener(object, name, function(e){
969
+ events[name].apply(this, [e]);
970
+ });
971
+ })(layer, ev);
972
+ }
973
+
974
+ this.layers.push(layer);
975
+
976
+ return layer;
977
+ };
978
+
979
+ this.loadFromKML = function(options) {
980
+ var layer = this.getFromKML(options);
981
+ layer.setMap(this.map);
982
+
983
+ return layer;
984
+ };
985
+
986
+ // Routes
987
+
988
+ var travelMode, unitSystem;
989
+ this.getRoutes = function(options) {
990
+ switch (options.travelMode) {
991
+ case 'bicycling':
992
+ travelMode = google.maps.TravelMode.BICYCLING;
993
+ break;
994
+ case 'transit':
995
+ travelMode = google.maps.TravelMode.TRANSIT;
996
+ break;
997
+ case 'driving':
998
+ travelMode = google.maps.TravelMode.DRIVING;
999
+ break;
1000
+ // case 'walking':
1001
+ default:
1002
+ travelMode = google.maps.TravelMode.WALKING;
1003
+ break;
1004
+ }
1005
+
1006
+ if (options.unitSystem === 'imperial') {
1007
+ unitSystem = google.maps.UnitSystem.IMPERIAL;
1008
+ }
1009
+ else {
1010
+ unitSystem = google.maps.UnitSystem.METRIC;
1011
+ }
1012
+
1013
+ var base_options = {
1014
+ avoidHighways: false,
1015
+ avoidTolls: false,
1016
+ optimizeWaypoints: false,
1017
+ waypoints: []
1018
+ };
1019
+
1020
+ var request_options = extend_object(base_options, options);
1021
+
1022
+ request_options.origin = /string/.test(typeof options.origin) ? options.origin : new google.maps.LatLng(options.origin[0], options.origin[1]);
1023
+ request_options.destination = /string/.test(typeof options.destination) ? options.destination : new google.maps.LatLng(options.destination[0], options.destination[1]);
1024
+ request_options.travelMode = travelMode;
1025
+ request_options.unitSystem = unitSystem;
1026
+
1027
+ delete request_options.callback;
1028
+
1029
+ var self = this;
1030
+ var service = new google.maps.DirectionsService();
1031
+
1032
+ service.route(request_options, function(result, status) {
1033
+ if (status === google.maps.DirectionsStatus.OK) {
1034
+ for (var r in result.routes) {
1035
+ if (result.routes.hasOwnProperty(r)) {
1036
+ self.routes.push(result.routes[r]);
1037
+ }
1038
+ }
1039
+ }
1040
+ if (options.callback) {
1041
+ options.callback(self.routes);
1042
+ }
1043
+ });
1044
+ };
1045
+
1046
+ this.removeRoutes = function() {
1047
+ this.routes = [];
1048
+ };
1049
+
1050
+ this.getElevations = function(options) {
1051
+ options = extend_object({
1052
+ locations: [],
1053
+ path : false,
1054
+ samples : 256
1055
+ }, options);
1056
+
1057
+ if(options.locations.length > 0) {
1058
+ if(options.locations[0].length > 0) {
1059
+ options.locations = array_flat(array_map([options.locations], arrayToLatLng, false));
1060
+ }
1061
+ }
1062
+
1063
+ var callback = options.callback;
1064
+ delete options.callback;
1065
+
1066
+ var service = new google.maps.ElevationService();
1067
+
1068
+ //location request
1069
+ if (!options.path) {
1070
+ delete options.path;
1071
+ delete options.samples;
1072
+ service.getElevationForLocations(options, function(result, status){
1073
+ if (callback && typeof(callback) === "function") {
1074
+ callback(result, status);
1075
+ }
1076
+ });
1077
+ //path request
1078
+ } else {
1079
+ var pathRequest = {
1080
+ path : options.locations,
1081
+ samples : options.samples
1082
+ };
1083
+
1084
+ service.getElevationAlongPath(pathRequest, function(result, status){
1085
+ if (callback && typeof(callback) === "function") {
1086
+ callback(result, status);
1087
+ }
1088
+ });
1089
+ }
1090
+ };
1091
+
1092
+ // Alias for the method "drawRoute"
1093
+ this.cleanRoute = this.removePolylines;
1094
+
1095
+ this.drawRoute = function(options) {
1096
+ var self = this;
1097
+ this.getRoutes({
1098
+ origin: options.origin,
1099
+ destination: options.destination,
1100
+ travelMode: options.travelMode,
1101
+ waypoints: options.waypoints,
1102
+ unitSystem: options.unitSystem,
1103
+ callback: function(e) {
1104
+ if (e.length > 0) {
1105
+ self.drawPolyline({
1106
+ path: e[e.length - 1].overview_path,
1107
+ strokeColor: options.strokeColor,
1108
+ strokeOpacity: options.strokeOpacity,
1109
+ strokeWeight: options.strokeWeight
1110
+ });
1111
+ if (options.callback) {
1112
+ options.callback(e[e.length - 1]);
1113
+ }
1114
+ }
1115
+ }
1116
+ });
1117
+ };
1118
+
1119
+ this.travelRoute = function(options) {
1120
+ if (options.origin && options.destination) {
1121
+ this.getRoutes({
1122
+ origin: options.origin,
1123
+ destination: options.destination,
1124
+ travelMode: options.travelMode,
1125
+ waypoints : options.waypoints,
1126
+ callback: function(e) {
1127
+ //start callback
1128
+ if (e.length > 0 && options.start) {
1129
+ options.start(e[e.length - 1]);
1130
+ }
1131
+
1132
+ //step callback
1133
+ if (e.length > 0 && options.step) {
1134
+ var route = e[e.length - 1];
1135
+ if (route.legs.length > 0) {
1136
+ var steps = route.legs[0].steps;
1137
+ for (var i=0, step; step=steps[i]; i++) {
1138
+ step.step_number = i;
1139
+ options.step(step, (route.legs[0].steps.length - 1));
1140
+ }
1141
+ }
1142
+ }
1143
+
1144
+ //end callback
1145
+ if (e.length > 0 && options.end) {
1146
+ options.end(e[e.length - 1]);
1147
+ }
1148
+ }
1149
+ });
1150
+ }
1151
+ else if (options.route) {
1152
+ if (options.route.legs.length > 0) {
1153
+ var steps = options.route.legs[0].steps;
1154
+ for (var i=0, step; step=steps[i]; i++) {
1155
+ step.step_number = i;
1156
+ options.step(step);
1157
+ }
1158
+ }
1159
+ }
1160
+ };
1161
+
1162
+ this.drawSteppedRoute = function(options) {
1163
+ if (options.origin && options.destination) {
1164
+ this.getRoutes({
1165
+ origin: options.origin,
1166
+ destination: options.destination,
1167
+ travelMode: options.travelMode,
1168
+ waypoints : options.waypoints,
1169
+ callback: function(e) {
1170
+ //start callback
1171
+ if (e.length > 0 && options.start) {
1172
+ options.start(e[e.length - 1]);
1173
+ }
1174
+
1175
+ //step callback
1176
+ if (e.length > 0 && options.step) {
1177
+ var route = e[e.length - 1];
1178
+ if (route.legs.length > 0) {
1179
+ var steps = route.legs[0].steps;
1180
+ for (var i=0, step; step=steps[i]; i++) {
1181
+ step.step_number = i;
1182
+ self.drawPolyline({
1183
+ path: step.path,
1184
+ strokeColor: options.strokeColor,
1185
+ strokeOpacity: options.strokeOpacity,
1186
+ strokeWeight: options.strokeWeight
1187
+ });
1188
+ options.step(step, (route.legs[0].steps.length - 1));
1189
+ }
1190
+ }
1191
+ }
1192
+
1193
+ //end callback
1194
+ if (e.length > 0 && options.end) {
1195
+ options.end(e[e.length - 1]);
1196
+ }
1197
+ }
1198
+ });
1199
+ }
1200
+ else if (options.route) {
1201
+ if (options.route.legs.length > 0) {
1202
+ var steps = options.route.legs[0].steps;
1203
+ for (var i=0, step; step=steps[i]; i++) {
1204
+ step.step_number = i;
1205
+ self.drawPolyline({
1206
+ path: step.path,
1207
+ strokeColor: options.strokeColor,
1208
+ strokeOpacity: options.strokeOpacity,
1209
+ strokeWeight: options.strokeWeight
1210
+ });
1211
+ options.step(step);
1212
+ }
1213
+ }
1214
+ }
1215
+ };
1216
+
1217
+ // Geofence
1218
+
1219
+ this.checkGeofence = function(lat, lng, fence) {
1220
+ return fence.containsLatLng(new google.maps.LatLng(lat, lng));
1221
+ };
1222
+
1223
+ this.checkMarkerGeofence = function(marker, outside_callback) {
1224
+ if (marker.fences) {
1225
+ for (var i=0, fence; fence=marker.fences[i]; i++) {
1226
+ var pos = marker.getPosition();
1227
+ if (!self.checkGeofence(pos.lat(), pos.lng(), fence)) {
1228
+ outside_callback(marker, fence);
1229
+ }
1230
+ }
1231
+ }
1232
+ };
1233
+
1234
+ // Layers
1235
+
1236
+ this.addLayer = function(layerName, options) {
1237
+ //var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places'];
1238
+ options = options || {};
1239
+ var layer;
1240
+
1241
+ switch(layerName) {
1242
+ case 'weather': this.singleLayers.weather = layer = new google.maps.weather.WeatherLayer();
1243
+ break;
1244
+ case 'clouds': this.singleLayers.clouds = layer = new google.maps.weather.CloudLayer();
1245
+ break;
1246
+ case 'traffic': this.singleLayers.traffic = layer = new google.maps.TrafficLayer();
1247
+ break;
1248
+ case 'transit': this.singleLayers.transit = layer = new google.maps.TransitLayer();
1249
+ break;
1250
+ case 'bicycling': this.singleLayers.bicycling = layer = new google.maps.BicyclingLayer();
1251
+ break;
1252
+ case 'panoramio':
1253
+ this.singleLayers.panoramio = layer = new google.maps.panoramio.PanoramioLayer();
1254
+ layer.setTag(options.filter);
1255
+ delete options.filter;
1256
+
1257
+ //click event
1258
+ if(options.click) {
1259
+ google.maps.event.addListener(layer, 'click', function(event) {
1260
+ options.click(event);
1261
+ delete options.click;
1262
+ });
1263
+ }
1264
+ break;
1265
+ case 'places':
1266
+ this.singleLayers.places = layer = new google.maps.places.PlacesService(this.map);
1267
+
1268
+ //search and nearbySearch callback, Both are the same
1269
+ if(options.search || options.nearbySearch) {
1270
+ var placeSearchRequest = {
1271
+ bounds : options.bounds || null,
1272
+ keyword : options.keyword || null,
1273
+ location : options.location || null,
1274
+ name : options.name || null,
1275
+ radius : options.radius || null,
1276
+ rankBy : options.rankBy || null,
1277
+ types : options.types || null
1278
+ };
1279
+
1280
+ if(options.search) {
1281
+ layer.search(placeSearchRequest, options.search);
1282
+ }
1283
+
1284
+ if(options.nearbySearch) {
1285
+ layer.nearbySearch(placeSearchRequest, options.nearbySearch);
1286
+ }
1287
+ }
1288
+
1289
+ //textSearch callback
1290
+ if(options.textSearch) {
1291
+ var textSearchRequest = {
1292
+ bounds : options.bounds || null,
1293
+ location : options.location || null,
1294
+ query : options.query || null,
1295
+ radius : options.radius || null
1296
+ };
1297
+
1298
+ layer.textSearch(textSearchRequest, options.textSearch);
1299
+ }
1300
+ break;
1301
+ }
1302
+
1303
+ if(layer !== undefined) {
1304
+ if(typeof layer.setOptions == 'function') {
1305
+ layer.setOptions(options);
1306
+ }
1307
+ if(typeof layer.setMap == 'function') {
1308
+ layer.setMap(this.map);
1309
+ }
1310
+
1311
+ return layer;
1312
+ }
1313
+ };
1314
+
1315
+ this.removeLayer = function(layer) {
1316
+ if(typeof(layer) == "string" && this.singleLayers[layer] !== undefined) {
1317
+ this.singleLayers[layer].setMap(null);
1318
+ delete this.singleLayers[layer];
1319
+ }
1320
+ else {
1321
+ for(var i = 0; i < this.layers.length; i++) {
1322
+ if(this.layers[i] === layer) {
1323
+ this.layers[i].setMap(null);
1324
+ this.layers.splice(i, 1);
1325
+
1326
+ break;
1327
+ }
1328
+ }
1329
+ }
1330
+ };
1331
+
1332
+ // Static Maps
1333
+
1334
+ this.toImage = function(options) {
1335
+ var options = options || {};
1336
+ var static_map_options = {};
1337
+ static_map_options['size'] = options['size'] || [this.el.clientWidth, this.el.clientHeight];
1338
+ static_map_options['lat'] = this.getCenter().lat();
1339
+ static_map_options['lng'] = this.getCenter().lng();
1340
+
1341
+ if(this.markers.length > 0) {
1342
+ static_map_options['markers'] = [];
1343
+ for(var i=0; i < this.markers.length; i++) {
1344
+ static_map_options['markers'].push({
1345
+ lat: this.markers[i].getPosition().lat(),
1346
+ lng: this.markers[i].getPosition().lng()
1347
+ });
1348
+ }
1349
+ }
1350
+
1351
+ if(this.polylines.length > 0) {
1352
+ var polyline = this.polylines[0];
1353
+ static_map_options['polyline'] = {};
1354
+ static_map_options['polyline']['path'] = google.maps.geometry.encoding.encodePath(polyline.getPath());
1355
+ static_map_options['polyline']['strokeColor'] = polyline.strokeColor
1356
+ static_map_options['polyline']['strokeOpacity'] = polyline.strokeOpacity
1357
+ static_map_options['polyline']['strokeWeight'] = polyline.strokeWeight
1358
+ }
1359
+
1360
+ return GMaps.staticMapURL(static_map_options);
1361
+ };
1362
+
1363
+ // Map Types
1364
+
1365
+ this.addMapType = function(mapTypeId, options) {
1366
+ if(options.hasOwnProperty("getTileUrl") && typeof(options["getTileUrl"]) == "function") {
1367
+ options.tileSize = options.tileSize || new google.maps.Size(256, 256);
1368
+
1369
+ var mapType = new google.maps.ImageMapType(options);
1370
+
1371
+ this.map.mapTypes.set(mapTypeId, mapType);
1372
+ }
1373
+ else {
1374
+ throw "'getTileUrl' function required.";
1375
+ }
1376
+ };
1377
+
1378
+ this.addOverlayMapType = function(options) {
1379
+ if(options.hasOwnProperty("getTile") && typeof(options["getTile"]) == "function") {
1380
+ var overlayMapTypeIndex = options.index;
1381
+
1382
+ delete options.index;
1383
+
1384
+ this.map.overlayMapTypes.insertAt(overlayMapTypeIndex, options);
1385
+ }
1386
+ else {
1387
+ throw "'getTile' function required.";
1388
+ }
1389
+ };
1390
+
1391
+ this.removeOverlayMapType = function(overlayMapTypeIndex) {
1392
+ this.map.overlayMapTypes.removeAt(overlayMapTypeIndex);
1393
+ };
1394
+
1395
+ // Styles
1396
+
1397
+ this.addStyle = function(options) {
1398
+ var styledMapType = new google.maps.StyledMapType(options.styles, options.styledMapName);
1399
+
1400
+ this.map.mapTypes.set(options.mapTypeId, styledMapType);
1401
+ };
1402
+
1403
+ this.setStyle = function(mapTypeId) {
1404
+ this.map.setMapTypeId(mapTypeId);
1405
+ };
1406
+
1407
+ // StreetView
1408
+
1409
+ this.createPanorama = function(streetview_options) {
1410
+ if (!streetview_options.hasOwnProperty('lat') || !streetview_options.hasOwnProperty('lng')) {
1411
+ streetview_options.lat = this.getCenter().lat();
1412
+ streetview_options.lng = this.getCenter().lng();
1413
+ }
1414
+
1415
+ this.panorama = GMaps.createPanorama(streetview_options);
1416
+
1417
+ this.map.setStreetView(this.panorama);
1418
+
1419
+ return this.panorama;
1420
+ };
1421
+
1422
+ // Events
1423
+
1424
+ this.on = function(event_name, handler) {
1425
+ return GMaps.on(event_name, this, handler);
1426
+ };
1427
+
1428
+ this.off = function(event_name) {
1429
+ GMaps.off(event_name, this);
1430
+ };
1431
+ };
1432
+
1433
+ GMaps.createPanorama = function(options) {
1434
+ var el = getElementById(options.el, options.context);
1435
+
1436
+ options.position = new google.maps.LatLng(options.lat, options.lng);
1437
+
1438
+ delete options.el;
1439
+ delete options.context;
1440
+ delete options.lat;
1441
+ delete options.lng;
1442
+
1443
+ var streetview_events = ['closeclick', 'links_changed', 'pano_changed', 'position_changed', 'pov_changed', 'resize', 'visible_changed'];
1444
+
1445
+ var streetview_options = extend_object({visible : true}, options);
1446
+
1447
+ for(var i = 0; i < streetview_events.length; i++) {
1448
+ delete streetview_options[streetview_events[i]];
1449
+ }
1450
+
1451
+ var panorama = new google.maps.StreetViewPanorama(el, streetview_options);
1452
+
1453
+ for(var i = 0; i < streetview_events.length; i++) {
1454
+ (function(object, name) {
1455
+ if (options[name]) {
1456
+ google.maps.event.addListener(object, name, function(){
1457
+ options[name].apply(this);
1458
+ });
1459
+ }
1460
+ })(panorama, streetview_events[i]);
1461
+ }
1462
+
1463
+ return panorama;
1464
+ };
1465
+
1466
+ GMaps.Route = function(options) {
1467
+ this.map = options.map;
1468
+ this.route = options.route;
1469
+ this.step_count = 0;
1470
+ this.steps = this.route.legs[0].steps;
1471
+ this.steps_length = this.steps.length;
1472
+
1473
+ this.polyline = this.map.drawPolyline({
1474
+ path: new google.maps.MVCArray(),
1475
+ strokeColor: options.strokeColor,
1476
+ strokeOpacity: options.strokeOpacity,
1477
+ strokeWeight: options.strokeWeight
1478
+ }).getPath();
1479
+
1480
+ this.back = function() {
1481
+ if (this.step_count > 0) {
1482
+ this.step_count--;
1483
+ var path = this.route.legs[0].steps[this.step_count].path;
1484
+ for (var p in path){
1485
+ if (path.hasOwnProperty(p)){
1486
+ this.polyline.pop();
1487
+ }
1488
+ }
1489
+ }
1490
+ };
1491
+
1492
+ this.forward = function() {
1493
+ if (this.step_count < this.steps_length) {
1494
+ var path = this.route.legs[0].steps[this.step_count].path;
1495
+ for (var p in path){
1496
+ if (path.hasOwnProperty(p)){
1497
+ this.polyline.push(path[p]);
1498
+ }
1499
+ }
1500
+ this.step_count++;
1501
+ }
1502
+ };
1503
+ };
1504
+
1505
+ // Geolocation (Modern browsers only)
1506
+
1507
+ GMaps.geolocate = function(options) {
1508
+ var complete_callback = options.always || options.complete;
1509
+
1510
+ if (navigator.geolocation) {
1511
+ navigator.geolocation.getCurrentPosition(function(position) {
1512
+ options.success(position);
1513
+
1514
+ if (complete_callback) {
1515
+ complete_callback();
1516
+ }
1517
+ }, function(error) {
1518
+ options.error(error);
1519
+
1520
+ if (complete_callback) {
1521
+ complete_callback();
1522
+ }
1523
+ }, options.options);
1524
+ }
1525
+ else {
1526
+ options.not_supported();
1527
+
1528
+ if (complete_callback) {
1529
+ complete_callback();
1530
+ }
1531
+ }
1532
+ };
1533
+
1534
+ // Geocoding
1535
+
1536
+ GMaps.geocode = function(options) {
1537
+ this.geocoder = new google.maps.Geocoder();
1538
+ var callback = options.callback;
1539
+ if (options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) {
1540
+ options.latLng = new google.maps.LatLng(options.lat, options.lng);
1541
+ }
1542
+
1543
+ delete options.lat;
1544
+ delete options.lng;
1545
+ delete options.callback;
1546
+ this.geocoder.geocode(options, function(results, status) {
1547
+ callback(results, status);
1548
+ });
1549
+ };
1550
+
1551
+ // Static maps
1552
+
1553
+ GMaps.staticMapURL = function(options){
1554
+ var parameters = [];
1555
+ var data;
1556
+
1557
+ var static_root = 'http://maps.googleapis.com/maps/api/staticmap';
1558
+ if (options.url){
1559
+ static_root = options.url;
1560
+ delete options.url;
1561
+ }
1562
+ static_root += '?';
1563
+
1564
+ var markers = options.markers;
1565
+ delete options.markers;
1566
+ if (!markers && options.marker){
1567
+ markers = [options.marker];
1568
+ delete options.marker;
1569
+ }
1570
+
1571
+ var polyline = options.polyline;
1572
+ delete options.polyline;
1573
+
1574
+ /** Map options **/
1575
+ if (options.center){
1576
+ parameters.push('center=' + options.center);
1577
+ delete options.center;
1578
+ }
1579
+ else if (options.address){
1580
+ parameters.push('center=' + options.address);
1581
+ delete options.address;
1582
+ }
1583
+ else if (options.lat){
1584
+ parameters.push(['center=', options.lat, ',', options.lng].join(''));
1585
+ delete options.lat;
1586
+ delete options.lng;
1587
+ }
1588
+ else if (options.visible){
1589
+ var visible = encodeURI(options.visible.join('|'));
1590
+ parameters.push('visible=' + visible);
1591
+ }
1592
+
1593
+ var size = options.size;
1594
+ if (size){
1595
+ if (size.join){
1596
+ size = size.join('x');
1597
+ }
1598
+ delete options.size;
1599
+ }
1600
+ else {
1601
+ size = '630x300';
1602
+ }
1603
+ parameters.push('size=' + size);
1604
+
1605
+ if (!options.zoom){
1606
+ options.zoom = 15;
1607
+ }
1608
+
1609
+ var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
1610
+ delete options.sensor;
1611
+ parameters.push('sensor=' + sensor);
1612
+
1613
+ for (var param in options){
1614
+ if (options.hasOwnProperty(param)){
1615
+ parameters.push(param + '=' + options[param]);
1616
+ }
1617
+ }
1618
+
1619
+ /** Markers **/
1620
+ if (markers){
1621
+ var marker, loc;
1622
+
1623
+ for (var i=0; data=markers[i]; i++){
1624
+ marker = [];
1625
+
1626
+ if (data.size && data.size !== 'normal'){
1627
+ marker.push('size:' + data.size);
1628
+ }
1629
+ else if (data.icon){
1630
+ marker.push('icon:' + encodeURI(data.icon));
1631
+ }
1632
+
1633
+ if (data.color){
1634
+ marker.push('color:' + data.color.replace('#', '0x'));
1635
+ }
1636
+
1637
+ if (data.label){
1638
+ marker.push('label:' + data.label[0].toUpperCase());
1639
+ }
1640
+
1641
+ loc = (data.address ? data.address : data.lat + ',' + data.lng);
1642
+
1643
+ if (marker.length || i === 0){
1644
+ marker.push(loc);
1645
+ marker = marker.join('|');
1646
+ parameters.push('markers=' + encodeURI(marker));
1647
+ }
1648
+ // New marker without styles
1649
+ else {
1650
+ marker = parameters.pop() + encodeURI('|' + loc);
1651
+ parameters.push(marker);
1652
+ }
1653
+ }
1654
+ }
1655
+
1656
+ /** Polylines **/
1657
+ function parseColor(color, opacity){
1658
+ if (color[0] === '#'){
1659
+ color = color.replace('#', '0x');
1660
+
1661
+ if (opacity){
1662
+ opacity = parseFloat(opacity);
1663
+ opacity = Math.min(1, Math.max(opacity, 0));
1664
+ if (opacity === 0){
1665
+ return '0x00000000';
1666
+ }
1667
+ opacity = (opacity * 255).toString(16);
1668
+ if (opacity.length === 1){
1669
+ opacity += opacity;
1670
+ }
1671
+
1672
+ color = color.slice(0,8) + opacity;
1673
+ }
1674
+ }
1675
+ return color;
1676
+ }
1677
+
1678
+ if (polyline){
1679
+ data = polyline;
1680
+ polyline = [];
1681
+
1682
+ if (data.strokeWeight){
1683
+ polyline.push('weight:' + parseInt(data.strokeWeight, 10));
1684
+ }
1685
+
1686
+ if (data.strokeColor){
1687
+ var color = parseColor(data.strokeColor, data.strokeOpacity);
1688
+ polyline.push('color:' + color);
1689
+ }
1690
+
1691
+ if (data.fillColor){
1692
+ var fillcolor = parseColor(data.fillColor, data.fillOpacity);
1693
+ polyline.push('fillcolor:' + fillcolor);
1694
+ }
1695
+
1696
+ var path = data.path;
1697
+ if (path.join){
1698
+ for (var j=0, pos; pos=path[j]; j++){
1699
+ polyline.push(pos.join(','));
1700
+ }
1701
+ }
1702
+ else {
1703
+ polyline.push('enc:' + path);
1704
+ }
1705
+
1706
+ polyline = polyline.join('|');
1707
+ parameters.push('path=' + encodeURI(polyline));
1708
+ }
1709
+
1710
+ parameters = parameters.join('&');
1711
+ return static_root + parameters;
1712
+ };
1713
+
1714
+ // Events
1715
+
1716
+ GMaps.custom_events = ['marker_added', 'marker_removed', 'polyline_added', 'polyline_removed', 'polygon_added', 'polygon_removed', 'geolocated', 'geolocation_failed'];
1717
+
1718
+ GMaps.on = function(event_name, object, handler) {
1719
+ if (GMaps.custom_events.indexOf(event_name) == -1) {
1720
+ return google.maps.event.addListener(object, event_name, handler);
1721
+ }
1722
+ else {
1723
+ var registered_event = {
1724
+ handler : handler,
1725
+ eventName : event_name
1726
+ };
1727
+
1728
+ object.registered_events[event_name] = object.registered_events[event_name] || [];
1729
+ object.registered_events[event_name].push(registered_event);
1730
+
1731
+ return registered_event;
1732
+ }
1733
+ };
1734
+
1735
+ GMaps.off = function(event_name, object) {
1736
+ if (GMaps.custom_events.indexOf(event_name) == -1) {
1737
+ google.maps.event.clearListeners(object, event_name);
1738
+ }
1739
+ else {
1740
+ object.registered_events[event_name] = [];
1741
+ }
1742
+ };
1743
+
1744
+ GMaps.fire = function(event_name, object, scope) {
1745
+ if (GMaps.custom_events.indexOf(event_name) == -1) {
1746
+ google.maps.event.trigger(object, event_name, Array.prototype.slice.apply(arguments).slice(2));
1747
+ }
1748
+ else {
1749
+ if(event_name in scope.registered_events) {
1750
+ var firing_events = scope.registered_events[event_name];
1751
+
1752
+ for(var i = 0; i < firing_events.length; i++) {
1753
+ (function(handler, scope, object) {
1754
+ handler.apply(scope, [object]);
1755
+ })(firing_events[i]['handler'], scope, object);
1756
+ }
1757
+ }
1758
+ }
1759
+ };
1760
+
1761
+ //==========================
1762
+ // Polygon containsLatLng
1763
+ // https://github.com/tparkin/Google-Maps-Point-in-Polygon
1764
+ // Poygon getBounds extension - google-maps-extensions
1765
+ // http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
1766
+ if (!google.maps.Polygon.prototype.getBounds) {
1767
+ google.maps.Polygon.prototype.getBounds = function(latLng) {
1768
+ var bounds = new google.maps.LatLngBounds();
1769
+ var paths = this.getPaths();
1770
+ var path;
1771
+
1772
+ for (var p = 0; p < paths.getLength(); p++) {
1773
+ path = paths.getAt(p);
1774
+ for (var i = 0; i < path.getLength(); i++) {
1775
+ bounds.extend(path.getAt(i));
1776
+ }
1777
+ }
1778
+
1779
+ return bounds;
1780
+ };
1781
+ }
1782
+
1783
+ if (!google.maps.Polygon.prototype.containsLatLng) {
1784
+ // Polygon containsLatLng - method to determine if a latLng is within a polygon
1785
+ google.maps.Polygon.prototype.containsLatLng = function(latLng) {
1786
+ // Exclude points outside of bounds as there is no way they are in the poly
1787
+ var bounds = this.getBounds();
1788
+
1789
+ if (bounds !== null && !bounds.contains(latLng)) {
1790
+ return false;
1791
+ }
1792
+
1793
+ // Raycast point in polygon method
1794
+ var inPoly = false;
1795
+
1796
+ var numPaths = this.getPaths().getLength();
1797
+ for (var p = 0; p < numPaths; p++) {
1798
+ var path = this.getPaths().getAt(p);
1799
+ var numPoints = path.getLength();
1800
+ var j = numPoints - 1;
1801
+
1802
+ for (var i = 0; i < numPoints; i++) {
1803
+ var vertex1 = path.getAt(i);
1804
+ var vertex2 = path.getAt(j);
1805
+
1806
+ if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
1807
+ if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
1808
+ inPoly = !inPoly;
1809
+ }
1810
+ }
1811
+
1812
+ j = i;
1813
+ }
1814
+ }
1815
+
1816
+ return inPoly;
1817
+ };
1818
+ }
1819
+
1820
+ google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
1821
+ return this.contains(latLng);
1822
+ };
1823
+
1824
+ google.maps.Marker.prototype.setFences = function(fences) {
1825
+ this.fences = fences;
1826
+ };
1827
+
1828
+ google.maps.Marker.prototype.addFence = function(fence) {
1829
+ this.fences.push(fence);
1830
+ };
1831
+
1832
+ return GMaps;
1833
+ }(this));
1834
+
1835
+ var coordsToLatLngs = function(coords, useGeoJSON) {
1836
+ var first_coord = coords[0];
1837
+ var second_coord = coords[1];
1838
+
1839
+ if(useGeoJSON) {
1840
+ first_coord = coords[1];
1841
+ second_coord = coords[0];
1842
+ }
1843
+
1844
+ return new google.maps.LatLng(first_coord, second_coord);
1845
+ };
1846
+
1847
+ var arrayToLatLng = function(coords, useGeoJSON) {
1848
+ for(var i=0; i < coords.length; i++) {
1849
+ if(coords[i].length > 0 && typeof(coords[i][0]) != "number") {
1850
+ coords[i] = arrayToLatLng(coords[i], useGeoJSON);
1851
+ }
1852
+ else {
1853
+ coords[i] = coordsToLatLngs(coords[i], useGeoJSON);
1854
+ }
1855
+ }
1856
+
1857
+ return coords;
1858
+ };
1859
+
1860
+ var extend_object = function(obj, new_obj) {
1861
+ if(obj === new_obj) return obj;
1862
+
1863
+ for(var name in new_obj) {
1864
+ obj[name] = new_obj[name];
1865
+ }
1866
+
1867
+ return obj;
1868
+ };
1869
+
1870
+ var replace_object = function(obj, replace) {
1871
+ if(obj === replace) return obj;
1872
+
1873
+ for(var name in replace) {
1874
+ if(obj[name] != undefined)
1875
+ obj[name] = replace[name];
1876
+ }
1877
+
1878
+ return obj;
1879
+ };
1880
+
1881
+ var array_map = function(array, callback) {
1882
+ var original_callback_params = Array.prototype.slice.call(arguments, 2);
1883
+
1884
+ if (Array.prototype.map && array.map === Array.prototype.map) {
1885
+ return Array.prototype.map.call(array, function(item) {
1886
+ callback_params = original_callback_params;
1887
+ callback_params.splice(0, 0, item);
1888
+
1889
+ return callback.apply(this, callback_params);
1890
+ });
1891
+ }
1892
+ else {
1893
+ var array_return = [];
1894
+ var array_length = array.length;
1895
+
1896
+ for(var i = 0; i < array_length; i++) {
1897
+ callback_params = original_callback_params;
1898
+ callback_params = callback_params.splice(0, 0, array[i]);
1899
+ array_return.push(callback.apply(this, callback_params));
1900
+ }
1901
+
1902
+ return array_return;
1903
+ }
1904
+ };
1905
+
1906
+ var array_flat = function(array) {
1907
+ new_array = [];
1908
+
1909
+ for(var i=0; i < array.length; i++) {
1910
+ new_array = new_array.concat(array[i]);
1911
+ }
1912
+
1913
+ return new_array;
1914
+ };
1915
+ }
1916
+
1917
+ else {
1918
+ throw 'Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.'
1919
+ }
js/simplemap.js ADDED
@@ -0,0 +1 @@
 
1
+ (function(a){var b=function(c,e,d){this.base_url="https://maps.google.com/maps?";this.display(c,e,d)};b.prototype.display=function(g,j,h){var d=a(g).attr("data-breakpoint");if(d>640){d=640}if(a("html").width()>d){var i=new GMaps({div:g,lat:j.lat(),lng:j.lng(),mapTypeControl:false,zoom:parseFloat(h),streetViewControl:false,scrollwheel:false,mapTypeId:google.maps.MapTypeId.ROADMAP});i.addMarker({lat:j.lat(),lng:j.lng()})}else{var f=GMaps.staticMapURL({center:j.lat()+","+j.lng(),zoom:h,size:d+"x"+a(g).height(),markers:[{lat:j.lat(),lng:j.lng()}],sensor:"false"});var e=a("<img />");a(e).attr("src",f);a(e).attr("alt",a(g).text());var c=a("<a />");a(c).attr("href",this.base_url+"q="+j.lat()+","+j.lng()+"&z="+h+"&hl=ja");a(c).html(e);a(g).html(c);a(g).addClass("staticmap")}};a(".simplemap").each(function(){var d=a("div",this).get(0);var e=16;if(parseFloat(a(d).attr("data-zoom"))){e=a(d).attr("data-zoom")}if(a(d).text().length){GMaps.geocode({address:a(d).text(),callback:function(i,h){if(h=="OK"){var j=i[0].geometry.location;new b(d,j,e)}}})}else{if(a(d).attr("data-lat")&&a(d).attr("data-lng")){var f=a(d).attr("data-lat");var c=a(d).attr("data-lng");var g=new google.maps.LatLng(f,c);new b(d,g,e)}}})})(jQuery);
js/simplemap.src.js ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($){
2
+
3
+ var SimpleMap = function(element, pos, zoom) {
4
+ this.base_url = 'https://maps.google.com/maps?';
5
+ this.display(element, pos, zoom);
6
+ }
7
+
8
+ SimpleMap.prototype.display = function(element, pos, zoom) {
9
+ var breakpoint = $(element).attr('data-breakpoint');
10
+ if (breakpoint > 640) {
11
+ breakpoint = 640;
12
+ }
13
+ if ($('html').width() > breakpoint) {
14
+ var map = new GMaps({
15
+ div: element,
16
+ lat: pos.lat(),
17
+ lng: pos.lng(),
18
+ mapTypeControl: false,
19
+ zoom: parseFloat(zoom),
20
+ streetViewControl: false,
21
+ scrollwheel: false,
22
+ mapTypeId: google.maps.MapTypeId.ROADMAP
23
+ });
24
+ map.addMarker({
25
+ lat: pos.lat(),
26
+ lng: pos.lng()
27
+ });
28
+ } else {
29
+ var url = GMaps.staticMapURL({
30
+ center: pos.lat()+','+pos.lng(),
31
+ zoom: zoom,
32
+ size: breakpoint+'x'+$(element).height(),
33
+ markers: [
34
+ {lat: pos.lat(), lng: pos.lng()}
35
+ ],
36
+ sensor: 'false'
37
+ });
38
+ var img = $('<img />');
39
+ $(img).attr('src', url);
40
+ $(img).attr('alt', $(element).text());
41
+ var a = $('<a />');
42
+ $(a).attr(
43
+ 'href',
44
+ this.base_url+'q='+pos.lat()+','+pos.lng()+'&z='+zoom+'&hl=ja'
45
+ );
46
+ $(a).html(img);
47
+ $(element).html(a);
48
+ $(element).addClass('staticmap');
49
+ }
50
+ }
51
+
52
+ $('.simplemap').each(function(){
53
+ var element = $('div', this).get(0);
54
+ var zoom = 16;
55
+ if (parseFloat($(element).attr('data-zoom'))) {
56
+ zoom = $(element).attr('data-zoom');
57
+ }
58
+ if ($(element).text().length) {
59
+ GMaps.geocode({
60
+ address: $(element).text(),
61
+ callback: function(results, status) {
62
+ if (status == 'OK') {
63
+ var pos = results[0].geometry.location;
64
+ new SimpleMap(element, pos, zoom);
65
+ }
66
+ }
67
+ });
68
+ } else if ($(element).attr('data-lat') && $(element).attr('data-lng')) {
69
+ var lat = $(element).attr('data-lat');
70
+ var lng = $(element).attr('data-lng');
71
+ var pos = new google.maps.LatLng(
72
+ lat,
73
+ lng
74
+ );
75
+ new SimpleMap(element, pos, zoom);
76
+ }
77
+ });
78
+
79
+ })(jQuery);
80
+
readme.txt ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Simple Map ===
2
+ Contributors: miyauchi
3
+ Donate link: http://wpist.me/
4
+ Tags: widget
5
+ Requires at least: 3.3
6
+ Tested up to: 3.5
7
+ Stable tag: 0.6.1
8
+
9
+ Easy way to embed google map.
10
+
11
+ == Description ==
12
+
13
+ Easy way to embed google map.
14
+ This plugin allow you convert address to google maps like below.
15
+
16
+ [map addr="San Francisco, California"]
17
+
18
+ Another way, you can embed Google Map with url only like oEmbed.
19
+
20
+ [This plugin maintained on GitHub.](https://github.com/miya0001/simple-map)
21
+
22
+ = Some features: =
23
+
24
+ * Allow you to embed google map based on shortcode.
25
+ * Points can be added using address or lat/ong.
26
+ * Display static map for iPhone automatically.
27
+ * oEmbed Support.
28
+
29
+ = Translators =
30
+
31
+ * Japanese(ja) - [Takayuki Miyauchi](http://firegoby.jp/)
32
+
33
+ Please contact to me.
34
+
35
+ * http://wpist.me/ (en)
36
+ * http://firegoby.jp/ (ja)
37
+ * @miya0001 on twitter.
38
+ * https://github.com/miya0001/simple-map
39
+
40
+ = Contributors =
41
+
42
+ * [Takayuki Miyauchi](http://firegoby.jp/)
43
+
44
+ == Installation ==
45
+
46
+ * A plug-in installation screen is displayed on the WordPress admin panel.
47
+ * It installs it in `wp-content/plugins`.
48
+ * The plug-in is made effective.
49
+
50
+ == Changelog ==
51
+
52
+ = 0.6.0 =
53
+ * oEmbed Support
54
+
55
+ = 0.1.0 =
56
+ * The first release.
57
+
58
+ == Credits ==
59
+
60
+ This plug-in is not guaranteed though the user of WordPress can freely use this plug-in free of charge regardless of the purpose.
61
+ The author must acknowledge the thing that the operation guarantee and the support in this plug-in use are not done at all beforehand.
62
+
63
+ == Contact ==
64
+
65
+ twitter @miya0001
simple-map.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Simple Map
4
+ Author: Takayuki Miyauchi
5
+ Plugin URI: http://wpist.me/
6
+ Description: Insert google map convert from address.
7
+ Version: 0.6.1
8
+ Author URI: http://wpist.me/
9
+ Domain Path: /languages
10
+ Text Domain: simplemap
11
+ */
12
+
13
+ new SimpleMap();
14
+
15
+ class SimpleMap{
16
+
17
+ private $class_name = 'simplemap';
18
+ private $width = '100%';
19
+ private $height = '200px';
20
+ private $zoom = 16;
21
+ private $breakpoint = 480;
22
+ private $max_breakpoint = 640;
23
+
24
+ function __construct()
25
+ {
26
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
27
+ }
28
+
29
+ public function plugins_loaded()
30
+ {
31
+ add_action('wp_head', array($this, 'wp_head'));
32
+ add_shortcode('map', array($this, 'shortcode'));
33
+
34
+ wp_embed_register_handler(
35
+ 'google-map',
36
+ '#(https://maps.google.co.jp/maps(/ms)?\?.+)#i',
37
+ array(&$this, 'oembed_handler')
38
+ );
39
+ }
40
+
41
+ public function oembed_handler($match)
42
+ {
43
+ return sprintf('[map url="%s"]', esc_url($match[0]));
44
+ }
45
+
46
+ public function wp_head()
47
+ {
48
+ echo "<style>.simplemap img{max-width:none !important;padding:0 !important;margin:0 !important;}.staticmap,.staticmap img{max-width:100% !important;height:auto !important;}</style>\n";
49
+ }
50
+
51
+ public function wp_enqueue_scripts()
52
+ {
53
+ wp_register_script(
54
+ 'google-maps-api',
55
+ 'http://maps.google.com/maps/api/js?sensor=false',
56
+ false,
57
+ null,
58
+ true
59
+ );
60
+
61
+ wp_register_script(
62
+ 'gmaps.js',
63
+ plugins_url('js/gmaps.js' , __FILE__),
64
+ array('jquery', 'google-maps-api'),
65
+ '0.1.12.1',
66
+ true
67
+ );
68
+
69
+ wp_register_script(
70
+ 'simplemap',
71
+ apply_filters(
72
+ "simplemap_script",
73
+ plugins_url('js/simplemap.js' , __FILE__)
74
+ ),
75
+ array('gmaps.js'),
76
+ filemtime(dirname(__FILE__).'/js/simplemap.js'),
77
+ true
78
+ );
79
+ wp_enqueue_script('simplemap');
80
+ }
81
+
82
+ public function shortcode($p, $content = null)
83
+ {
84
+ add_action("wp_footer", array(&$this, "wp_enqueue_scripts"));
85
+
86
+ if (isset($p['width']) && preg_match("/^[0-9]+(%|px)$/", $p['width'])) {
87
+ $w = $p['width'];
88
+ } else {
89
+ $w = apply_filters("simplemap_default_width", $this->width);
90
+ }
91
+ if (isset($p['height']) && preg_match("/^[0-9]+(%|px)$/", $p['height'])) {
92
+ $h = $p['height'];
93
+ } else {
94
+ $h = apply_filters("simplemap_default_height", $this->height);
95
+ }
96
+ if (isset($p['zoom']) && $p['zoom']) {
97
+ $zoom = $p['zoom'];
98
+ } else {
99
+ $zoom = apply_filters('simplemap_default_zoom', $this->zoom);
100
+ }
101
+ if (isset($p['breakpoint']) && intval($p['breakpoint'])) {
102
+ if (intval($p['breakpoint']) > $this->max_breakpoint) {
103
+ $breakpoint = $this->max_breakpoint;
104
+ } else {
105
+ $breakpoint = intval($p['breakpoint']);
106
+ }
107
+ } else {
108
+ $breakpoint = apply_filters(
109
+ 'simplemap_default_breakpoint',
110
+ $this->breakpoint
111
+ );
112
+ }
113
+ $addr = '';
114
+ $lat = '';
115
+ $lng = '';
116
+
117
+ if (isset($p['url']) && $p['url']) {
118
+ $iframe = '<iframe width="%s" height="%s" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="%s"></iframe>';
119
+
120
+ return sprintf(
121
+ $iframe,
122
+ $w,
123
+ $h,
124
+ esc_url($p['url'].'&output=embed')
125
+ );
126
+ } elseif (isset($p['addr']) && $p['addr']) {
127
+ $addr = esc_html($p['addr']);
128
+ } elseif ($content) {
129
+ $addr = do_shortcode($content);
130
+ } elseif (isset($p['lat']) && preg_match("/^\-?[0-9\.]+$/", $p['lat'])
131
+ && isset($p['lng']) && preg_match("/^\-?[0-9\.]+$/", $p['lng'])){
132
+ $lat = $p['lat'];
133
+ $lng = $p['lng'];
134
+ } else {
135
+ return;
136
+ }
137
+ return sprintf(
138
+ '<div class="%s"><div data-breakpoint="%s" data-lat="%s" data-lng="%s" data-zoom="%s" style="width:%s;height:%s;">%s</div></div>',
139
+ apply_filters("simplemap_class_name", $this->class_name),
140
+ $breakpoint,
141
+ $lat,
142
+ $lng,
143
+ $zoom,
144
+ $w,
145
+ $h,
146
+ $addr
147
+ );
148
+ }
149
+
150
+ }
151
+
152
+
153
+ // EOF