Version Description
Download this release
Release Info
Developer | miyauchi |
Plugin | Simple Map |
Version | 0.4.0 |
Comparing to | |
See all releases |
Version 0.4.0
- js/gmaps.js +8 -0
- js/gmaps.src.js +1225 -0
- js/simplemap.js +1 -0
- js/simplemap.src.js +80 -0
- readme.txt +59 -0
- simple-map.php +127 -0
js/gmaps.js
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* GMaps.js 0.1.12.1
|
3 |
+
* http://hpneo.github.com/gmaps/
|
4 |
+
*
|
5 |
+
* Copyright 2012, Gustavo Leon
|
6 |
+
* Released under the MIT License.
|
7 |
+
*/
|
8 |
+
var GMaps=(function(b){var a=function(m){var l=this;var j="position:absolute;display:none;min-width:100px;background:white;list-style:none;padding:8px;box-shadow:2px 2px 6px #ccc";window.context_menu={};this.div=b(m.div)[0];this.controls=[];this.overlays=[];this.layers=[];this.markers=[];this.polylines=[];this.routes=[];this.polygons=[];this.infoWindow=null;this.overlay_div=null;this.zoom=m.zoom||15;var g;if(m.mapType){g=google.maps.MapTypeId[m.mapType.toUpperCase()]}else{g=google.maps.MapTypeId.ROADMAP}var d=new google.maps.LatLng(m.lat,m.lng);delete m.lat;delete m.lng;delete m.mapType;var f={zoom:this.zoom,center:d,mapTypeId:g};var k=b.extend(f,m);this.map=new google.maps.Map(this.div,k);var h=function(p,t){var s="";var v=window.context_menu[p];for(var q in v){if(v.hasOwnProperty(q)){var r=v[q];s+='<li><a id="'+p+"_"+q+'" href="#">'+r.title+"</a></li>"}}var o=b("#gmaps_context_menu");o.html(s);o.undelegate();o.delegate("li a","click",function(w){w.preventDefault();v[b(this).attr("id").replace(p+"_","")].action.call(l,t);l.hideContextMenu()});var n=b(l.div).offset().left+t.pixel.x-15;var u=b(l.div).offset().top+t.pixel.y-15;o.css({left:n,top:u}).fadeIn(200)};var i=function(p,o){if(p==="marker"){o.pixel={};var n=new google.maps.OverlayView();n.setMap(l.map);n.draw=function(){var r=n.getProjection();var q=o.marker.getPosition();o.pixel=r.fromLatLngToContainerPixel(q);h(p,o)}}else{h(p,o)}};this.setContextMenu=function(n){window.context_menu[n.control]={};var p='<ul id="gmaps_context_menu" style="'+j+'"></ul>';for(var o in n.options){if(n.options.hasOwnProperty(o)){var q=n.options[o];window.context_menu[n.control][q.name]={title:q.title,action:q.action}}}b("body").append(p);b("#gmaps_context_menu").mouseleave(function(){b(this).delay(100).fadeOut(200)})};this.hideContextMenu=function(){b("#gmaps_context_menu").fadeOut(200)};google.maps.event.addListener(this.map,"bounds_changed",function(n){if(m.bounds_changed){m.bounds_changed(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"center_changed",function(n){if(m.center_changed){m.center_changed(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"click",function(n){if(m.click){m.click(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"dblclick",function(n){if(m.dblclick){m.dblclick(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"drag",function(n){if(m.drag){m.drag(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"dragend",function(n){if(m.dragend){m.dragend(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"dragstart",function(n){if(m.dragstart){m.dragstart(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"idle",function(n){if(m.idle){m.idle(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"maptypeid_changed",function(n){if(m.maptypeid_changed){m.maptypeid_changed(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"mousemove",function(n){if(m.mousemove){m.mousemove(n)}});google.maps.event.addListener(this.map,"mouseout",function(n){if(m.mouseout){m.mouseout(n)}});google.maps.event.addListener(this.map,"mouseover",function(n){if(m.mouseover){m.mouseover(n)}});google.maps.event.addListener(this.map,"projection_changed",function(n){if(m.projection_changed){m.projection_changed(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"resize",function(n){if(m.resize){m.resize(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"rightclick",function(n){if(m.rightclick){m.rightclick(n)}i("map",n)});google.maps.event.addListener(this.map,"tilesloaded",function(n){if(m.tilesloaded){m.tilesloaded(n)}l.hideContextMenu()});google.maps.event.addListener(this.map,"zoom_changed",function(n){if(m.zoom_changed){m.zoom_changed(n)}l.hideContextMenu()});this.setCenter=function(o,n,p){this.map.panTo(new google.maps.LatLng(o,n));if(p){p()}};this.getCenter=function(){return this.map.getCenter()};this.getDiv=function(){return this.div};this.setZoom=function(n){this.map.setZoom(n)};this.zoomIn=function(n){this.map.setZoom(this.map.getZoom()+n)};this.zoomOut=function(n){this.map.setZoom(this.map.getZoom()-n)};this.createControl=function(o){o.style.cursor="pointer";o.style.fontFamily="Arial, sans-serif";o.style.fontSize="13px";o.style.boxShadow="rgba(0, 0, 0, 0.398438) 0px 2px 4px";var n=b("<div></div>");n.css(o.style);n.text(o.text);var q=n[0];for(var p in o.events){google.maps.event.addDomListener(q,p,function(){o.events[p].apply(this,[this])})}q.index=1;return q};this.addControl=function(o){var n=google.maps.ControlPosition[o.position.toUpperCase()];delete o.position;var p=this.createControl(o);this.controls.push(p);this.map.controls[n].push(p);return p};this.createMarker=function(r){if(r.lat&&r.lng){var p=this;var s=r.details;var u=r.fences;var t=r.outside;var q={position:new google.maps.LatLng(r.lat,r.lng),map:null};delete r.lat;delete r.lng;delete r.fences;delete r.outside;var o=b.extend(q,r);var n=new google.maps.Marker(o);n.fences=u;if(r.infoWindow){n.infoWindow=new google.maps.InfoWindow(r.infoWindow);if(r.infoWindow.closeclick){google.maps.event.addListener(n.infoWindow,"closeclick",function(){r.infoWindow.closeclick()})}if(r.infoWindow.content_changed){google.maps.event.addListener(n.infoWindow,"content_changed",function(){r.infoWindow.content_changed()})}if(r.infoWindow.domready){google.maps.event.addListener(n.infoWindow,"domready",function(){r.infoWindow.domready()})}if(r.infoWindow.position_changed){google.maps.event.addListener(n.infoWindow,"position_changed",function(){r.infoWindow.position_changed()})}if(r.infoWindow.zindex_changed){google.maps.event.addListener(n.infoWindow,"zindex_changed",function(){r.infoWindow.zindex_changed()})}}google.maps.event.addListener(n,"click",function(){this.details=s;if(r.click){r.click.apply(this,[this])}if(n.infoWindow){p.hideInfoWindows();n.infoWindow.open(p.map,n)}});if(r.drag){google.maps.event.addListener(n,"drag",function(){r.drag(this)})}if(r.dragend||n.fences){google.maps.event.addListener(n,"dragend",function(){if(r.dragend){r.dragend(this)}if(n.fences){p.checkMarkerGeofence(n,function(v,w){t(v,w)})}})}if(r.dragstart){google.maps.event.addListener(n,"dragstart",function(){r.dragstart(this)})}if(r.mouseout){google.maps.event.addListener(n,"mouseout",function(){r.mouseout(this)})}if(r.mouseover){google.maps.event.addListener(n,"mouseover",function(){r.mouseover(this)})}if(r.mouseup){google.maps.event.addListener(n,"mouseup",function(){r.mouseup(this)})}if(r.position_changed){google.maps.event.addListener(n,"position_changed",function(){r.position_changed(this)})}return n}else{throw"No latitude or longitude defined"}};this.addMarker=function(o){if(o.lat&&o.lng){var n=this.createMarker(o);n.setMap(this.map);this.markers.push(n);return n}else{throw"No latitude or longitude defined"}};this.addMarkers=function(p){for(var o=0,n;n=p[o];o++){this.addMarker(n)}return this.markers};this.hideInfoWindows=function(){for(var o=0,n;n=this.markers[o];o++){if(n.infoWindow){n.infoWindow.close()}}};this.removeMarkers=function(){for(var o=0,n;n=this.markers[o];o++){n.setMap(null)}this.markers=[]};this.drawOverlay=function(o){var n=new google.maps.OverlayView();n.setMap(l.map);n.onAdd=function(){var r=document.createElement("div");r.style.borderStyle="none";r.style.borderWidth="0px";r.style.position="absolute";r.innerHTML=o.content;l.overlay_div=r;var q=this.getPanes();if(!o.layer){o.layer="overlayLayer"}var p=q[o.layer];p.appendChild(r)};n.draw=function(){var p=this.getProjection();var q=p.fromLatLngToDivPixel(new google.maps.LatLng(o.lat,o.lng));o.horizontalOffset=o.horizontalOffset||0;o.verticalOffset=o.verticalOffset||0;var s=l.overlay_div;var r=s.children;switch(o.verticalAlign){case"top":s.style.top=(q.y-b(r).height()+o.verticalOffset)+"px";break;default:case"middle":s.style.top=(q.y-(b(r).height()/2)+o.verticalOffset)+"px";break;case"bottom":s.style.top=(q.y+o.verticalOffset)+"px";break}switch(o.horizontalAlign){case"left":s.style.left=(q.x-b(r).width()+o.horizontalOffset)+"px";break;default:case"center":s.style.left=(q.x-(b(r).width()/2)+o.horizontalOffset)+"px";break;case"right":s.style.left=(q.x+o.horizontalOffset)+"px";break}};n.onRemove=function(){l.overlay_div.parentNode.removeChild(l.overlay_div);l.overlay_div=null};l.overlays.push(n);return n};this.removeOverlay=function(n){n.setMap(null)};this.removeOverlays=function(){for(var n=0,o;o=l.overlays[n];n++){o.setMap(null)}l.overlays=[]};this.drawPolyline=function(o){var r=[];var q=o.path;if(q.length){if(q[0][0]===undefined){r=q}else{for(var p=0,s;s=q[p];p++){r.push(new google.maps.LatLng(s[0],s[1]))}}}var n=new google.maps.Polyline({map:this.map,path:r,strokeColor:o.strokeColor,strokeOpacity:o.strokeOpacity,strokeWeight:o.strokeWeight});if(o.click){google.maps.event.addListener(n,"click",function(t){o.click(t)})}if(o.dblclick){google.maps.event.addListener(n,"dblclick",function(t){o.dblclick(t)})}if(o.mousedown){google.maps.event.addListener(n,"mousedown",function(t){o.mousedown(t)})}if(o.mousemove){google.maps.event.addListener(n,"mousemove",function(t){o.mousemove(t)})}if(o.mouseout){google.maps.event.addListener(n,"mouseout",function(t){o.mouseout(t)})}if(o.mouseover){google.maps.event.addListener(n,"mouseover",function(t){o.mouseover(t)})}if(o.mouseup){google.maps.event.addListener(n,"mouseup",function(t){o.mouseup(t)})}if(o.rightclick){google.maps.event.addListener(n,"rightclick",function(t){o.rightclick(t)})}this.polylines.push(n);return n};this.drawCircle=function(n){n=b.extend({map:this.map,center:new google.maps.LatLng(n.lat,n.lng)},n);delete n.lat;delete n.lng;var o=new google.maps.Circle(n);google.maps.event.addListener(o,"click",function(p){if(n.click){n.click(p)}});google.maps.event.addListener(o,"dblclick",function(p){if(n.dblclick){n.dblclick(p)}});google.maps.event.addListener(o,"mousedown",function(p){if(n.mousedown){n.mousedown(p)}});google.maps.event.addListener(o,"mousemove",function(p){if(n.mousemove){n.mousemove(p)}});google.maps.event.addListener(o,"mouseout",function(p){if(n.mouseout){n.mouseout(p)}});google.maps.event.addListener(o,"mouseover",function(p){if(n.mouseover){n.mouseover(p)}});google.maps.event.addListener(o,"mouseup",function(p){if(n.mouseup){n.mouseup(p)}});google.maps.event.addListener(o,"rightclick",function(p){if(n.rightclick){n.rightclick(p)}});return o};this.drawPolygon=function(n){n=b.extend({map:this.map},n);var o=new google.maps.Polygon(n);google.maps.event.addListener(o,"click",function(p){if(n.click){n.click(p)}});google.maps.event.addListener(o,"dblclick",function(p){if(n.dblclick){n.dblclick(p)}});google.maps.event.addListener(o,"mousedown",function(p){if(n.mousedown){n.mousedown(p)}});google.maps.event.addListener(o,"mousemove",function(p){if(n.mousemove){n.mousemove(p)}});google.maps.event.addListener(o,"mouseout",function(p){if(n.mouseout){n.mouseout(p)}});google.maps.event.addListener(o,"mouseover",function(p){if(n.mouseover){n.mouseover(p)}});google.maps.event.addListener(o,"mouseup",function(p){if(n.mouseup){n.mouseup(p)}});google.maps.event.addListener(o,"rightclick",function(p){if(n.rightclick){n.rightclick(p)}});this.polygons.push(o);return o};this.getFromFusionTables=function(o){var q=o.events;delete o.events;var n=o;var p=new google.maps.FusionTablesLayer(n);for(var r in q){google.maps.event.addListener(p,r,function(s){q[r].apply(this,[s])})}this.layers.push(p);return p};this.loadFromFusionTables=function(n){var o=this.getFromFusionTables(n);o.setMap(this.map);return o};this.getFromKML=function(o){var n=o.url;var q=o.events;delete o.url;delete o.events;var s=o;var p=new google.maps.KmlLayer(n,s);for(var r in q){google.maps.event.addListener(p,r,function(t){q[r].apply(this,[t])})}this.layers.push(p);return p};this.loadFromKML=function(n){var o=this.getFromKML(n);o.setMap(this.map);return o};var c,e;this.getRoutes=function(r){switch(r.travelMode){case"bicycling":c=google.maps.TravelMode.BICYCLING;break;case"driving":c=google.maps.TravelMode.DRIVING;break;default:c=google.maps.TravelMode.WALKING;break}if(r.unitSystem==="imperial"){e=google.maps.UnitSystem.IMPERIAL}else{e=google.maps.UnitSystem.METRIC}var q={avoidHighways:true,avoidTolls:true,optimizeWaypoints:true,waypoints:[]};var p=b.extend(q,r);p.origin=new google.maps.LatLng(r.origin[0],r.origin[1]);p.destination=new google.maps.LatLng(r.destination[0],r.destination[1]);p.travelMode=c;p.unitSystem=e;delete p.callback;var o=this;var n=new google.maps.DirectionsService();n.route(p,function(s,t){if(t===google.maps.DirectionsStatus.OK){for(var u in s.routes){if(s.routes.hasOwnProperty(u)){o.routes.push(s.routes[u])}}}if(r.callback){r.callback(o.routes)}})};this.drawRoute=function(o){var n=this;this.getRoutes({origin:o.origin,destination:o.destination,travelMode:o.travelMode,callback:function(p){if(p.length>0){n.drawPolyline({path:p[p.length-1].overview_path,strokeColor:o.strokeColor,strokeOpacity:o.strokeOpacity,strokeWeight:o.strokeWeight});if(o.callback){o.callback(p[p.length-1])}}}})};this.travelRoute=function(o){if(o.origin&&o.destination){this.getRoutes({origin:o.origin,destination:o.destination,travelMode:o.travelMode,callback:function(v){if(v.length>0&&o.step){var s=v[v.length-1];if(s.legs.length>0){var r=s.legs[0].steps;for(var t=0,u;u=r[t];t++){u.step_number=t;o.step(u)}}}}})}else{if(o.route){if(o.route.legs.length>0){var n=o.route.legs[0].steps;for(var p=0,q;q=n[p];p++){q.step_number=p;o.step(q)}}}}};this.drawSteppedRoute=function(o){if(o.origin&&o.destination){this.getRoutes({origin:o.origin,destination:o.destination,travelMode:o.travelMode,callback:function(v){if(v.length>0&&o.step){var s=v[v.length-1];if(s.legs.length>0){var r=s.legs[0].steps;for(var t=0,u;u=r[t];t++){u.step_number=t;l.drawPolyline({path:u.path,strokeColor:o.strokeColor,strokeOpacity:o.strokeOpacity,strokeWeight:o.strokeWeight});o.step(u)}}}}})}else{if(o.route){if(o.route.legs.length>0){var n=o.route.legs[0].steps;for(var p=0,q;q=n[p];p++){q.step_number=p;l.drawPolyline({path:q.path,strokeColor:o.strokeColor,strokeOpacity:o.strokeOpacity,strokeWeight:o.strokeWeight});o.step(q)}}}}};this.checkGeofence=function(o,n,p){return p.containsLatLng(new google.maps.LatLng(o,n))};this.checkMarkerGeofence=function(n,p){if(n.fences){for(var o=0,q;q=n.fences[o];o++){var r=n.getPosition();if(!l.checkGeofence(r.lat(),r.lng(),q)){p(n,q)}}}}};a.Route=function(c){this.map=c.map;this.route=c.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:c.strokeColor,strokeOpacity:c.strokeOpacity,strokeWeight:c.strokeWeight}).getPath();this.back=function(){if(this.step_count>0){this.step_count--;var e=this.route.legs[0].steps[this.step_count].path;for(var d in e){if(e.hasOwnProperty(d)){this.polyline.pop()}}}};this.forward=function(){if(this.step_count<this.steps_length){var e=this.route.legs[0].steps[this.step_count].path;for(var d in e){if(e.hasOwnProperty(d)){this.polyline.push(e[d])}}this.step_count++}}};a.geolocate=function(c){if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function(d){c.success(d);if(c.always){c.always()}},function(d){c.error(d);if(c.always){c.always()}},c.options)}else{c.not_supported();if(c.always){c.always()}}};a.geocode=function(c){this.geocoder=new google.maps.Geocoder();var d=c.callback;if(c.lat&&c.lng){c.latLng=new google.maps.LatLng(c.lat,c.lng)}delete c.lat;delete c.lng;delete c.callback;this.geocoder.geocode(c,function(f,e){d(f,e)})};a.staticMapURL=function(d){var g=[];var v;var e="http://maps.googleapis.com/maps/api/staticmap";if(d.url){e=d.url;delete d.url}e+="?";var t=d.markers;delete d.markers;if(!t&&d.marker){t=[d.marker];delete d.marker}var o=d.polyline;delete d.polyline;if(d.center){g.push("center="+d.center);delete d.center}else{if(d.address){g.push("center="+d.address);delete d.address}else{if(d.lat){g.push(["center=",d.lat,",",d.lng].join(""));delete d.lat;delete d.lng}else{if(d.visible){var c=encodeURI(d.visible.join("|"));g.push("visible="+c)}}}}var m=d.size;if(m){if(m.join){m=m.join("x")}delete d.size}else{m="630x300"}g.push("size="+m);if(!d.zoom){d.zoom=15}var u=d.hasOwnProperty("sensor")?!!d.sensor:true;delete d.sensor;g.push("sensor="+u);for(var h in d){if(d.hasOwnProperty(h)){g.push(h+"="+d[h])}}if(t){var k,l;for(var r=0;v=t[r];r++){k=[];if(v.size&&v.size!=="normal"){k.push("size:"+v.size)}else{if(v.icon){k.push("icon:"+encodeURI(v.icon))}}if(v.color){k.push("color:"+v.color.replace("#","0x"))}if(v.label){k.push("label:"+v.label[0].toUpperCase())}l=(v.address?v.address:v.lat+","+v.lng);if(k.length||r===0){k.push(l);k=k.join("|");g.push("markers="+encodeURI(k))}else{k=g.pop()+encodeURI("|"+l);g.push(k)}}}function s(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(o){v=o;o=[];if(v.strokeWeight){o.push("weight:"+parseInt(v.strokeWeight,10))}if(v.strokeColor){var p=s(v.strokeColor,v.strokeOpacity);o.push("color:"+p)}if(v.fillColor){var w=s(v.fillColor,v.fillOpacity);o.push("fillcolor:"+w)}var n=v.path;if(n.join){for(var q=0,f;f=n[q];q++){o.push(f.join(","))}}else{o.push("enc:"+n)}o=o.join("|");g.push("path="+encodeURI(o))}g=g.join("&");return e+g};if(!google.maps.Polygon.prototype.getBounds){google.maps.Polygon.prototype.getBounds=function(e){var d=new google.maps.LatLngBounds();var h=this.getPaths();var g;for(var f=0;f<h.getLength();f++){g=h.getAt(f);for(var c=0;c<g.getLength();c++){d.extend(g.getAt(c))}}return d}}google.maps.Polygon.prototype.containsLatLng=function(g){var c=this.getBounds();if(c!==null&&!c.contains(g)){return false}var e=false;var d=this.getPaths().getLength();for(var f=0;f<d;f++){var o=this.getPaths().getAt(f);var l=o.getLength();var h=l-1;for(var k=0;k<l;k++){var n=o.getAt(k);var m=o.getAt(h);if(n.lng()<g.lng()&&m.lng()>=g.lng()||m.lng()<g.lng()&&n.lng()>=g.lng()){if(n.lat()+(g.lng()-n.lng())/(m.lng()-n.lng())*(m.lat()-n.lat())<g.lat()){e=!e}}h=k}}return e};google.maps.LatLngBounds.prototype.containsLatLng=function(c){return this.contains(c)};google.maps.Marker.prototype.setFences=function(c){this.fences=c};google.maps.Marker.prototype.addFence=function(c){this.fences.push(c)};return a}(jQuery));
|
js/gmaps.src.js
ADDED
@@ -0,0 +1,1225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*!
|
2 |
+
* GMaps.js 0.1.12.1
|
3 |
+
* http://hpneo.github.com/gmaps/
|
4 |
+
*
|
5 |
+
* Copyright 2012, Gustavo Leon
|
6 |
+
* Released under the MIT License.
|
7 |
+
*/
|
8 |
+
|
9 |
+
var GMaps = (function($) {
|
10 |
+
"use strict";
|
11 |
+
|
12 |
+
var GMaps = function(options) {
|
13 |
+
var self = this;
|
14 |
+
var context_menu_style = 'position:absolute;display:none;min-width:100px;' +
|
15 |
+
'background:white;list-style:none;padding:8px;box-shadow:2px 2px 6px #ccc';
|
16 |
+
window.context_menu = {};
|
17 |
+
|
18 |
+
this.div = $(options.div)[0];
|
19 |
+
this.controls = [];
|
20 |
+
this.overlays = [];
|
21 |
+
this.layers = [];
|
22 |
+
this.markers = [];
|
23 |
+
this.polylines = [];
|
24 |
+
this.routes = [];
|
25 |
+
this.polygons = [];
|
26 |
+
this.infoWindow = null;
|
27 |
+
this.overlay_div = null;
|
28 |
+
this.zoom = options.zoom || 15;
|
29 |
+
|
30 |
+
//'Hybrid', 'Roadmap', 'Satellite' or 'Terrain'
|
31 |
+
var mapType;
|
32 |
+
|
33 |
+
if (options.mapType) {
|
34 |
+
mapType = google.maps.MapTypeId[options.mapType.toUpperCase()];
|
35 |
+
}
|
36 |
+
else {
|
37 |
+
mapType = google.maps.MapTypeId.ROADMAP;
|
38 |
+
}
|
39 |
+
|
40 |
+
var map_center = new google.maps.LatLng(options.lat, options.lng);
|
41 |
+
|
42 |
+
delete options.lat;
|
43 |
+
delete options.lng;
|
44 |
+
delete options.mapType;
|
45 |
+
|
46 |
+
var map_base_options = {
|
47 |
+
zoom: this.zoom,
|
48 |
+
center: map_center,
|
49 |
+
mapTypeId: mapType
|
50 |
+
};
|
51 |
+
|
52 |
+
var map_options = $.extend(map_base_options, options);
|
53 |
+
|
54 |
+
this.map = new google.maps.Map(this.div, map_options);
|
55 |
+
|
56 |
+
// Context menus
|
57 |
+
var buildContextMenuHTML = function(control, e) {
|
58 |
+
var html = '';
|
59 |
+
var options = window.context_menu[control];
|
60 |
+
for (var i in options){
|
61 |
+
if (options.hasOwnProperty(i)){
|
62 |
+
var option = options[i];
|
63 |
+
html += '<li><a id="' + control + '_' + i + '" href="#">' +
|
64 |
+
option.title + '</a></li>';
|
65 |
+
}
|
66 |
+
}
|
67 |
+
var $context_menu = $('#gmaps_context_menu');
|
68 |
+
$context_menu.html(html);
|
69 |
+
$context_menu.undelegate();
|
70 |
+
$context_menu.delegate('li a', 'click', function(ev) {
|
71 |
+
ev.preventDefault();
|
72 |
+
options[$(this).attr('id').replace(control + '_', '')].action.call(self, e);
|
73 |
+
self.hideContextMenu();
|
74 |
+
});
|
75 |
+
|
76 |
+
var left = $(self.div).offset().left + e.pixel.x - 15;
|
77 |
+
var top = $(self.div).offset().top + e.pixel.y - 15;
|
78 |
+
$context_menu.css({
|
79 |
+
left: left,
|
80 |
+
top: top
|
81 |
+
}).fadeIn(200);
|
82 |
+
};
|
83 |
+
|
84 |
+
var buildContextMenu = function(control, e) {
|
85 |
+
if (control === 'marker') {
|
86 |
+
e.pixel = {};
|
87 |
+
var overlay = new google.maps.OverlayView();
|
88 |
+
overlay.setMap(self.map);
|
89 |
+
overlay.draw = function() {
|
90 |
+
var projection = overlay.getProjection();
|
91 |
+
var position = e.marker.getPosition();
|
92 |
+
e.pixel = projection.fromLatLngToContainerPixel(position);
|
93 |
+
|
94 |
+
buildContextMenuHTML(control, e);
|
95 |
+
};
|
96 |
+
}
|
97 |
+
else {
|
98 |
+
buildContextMenuHTML(control, e);
|
99 |
+
}
|
100 |
+
};
|
101 |
+
|
102 |
+
this.setContextMenu = function(options) {
|
103 |
+
window.context_menu[options.control] = {};
|
104 |
+
var html = '<ul id="gmaps_context_menu" style="' + context_menu_style + '"></ul>';
|
105 |
+
for (var i in options.options){
|
106 |
+
if (options.options.hasOwnProperty(i)){
|
107 |
+
var option = options.options[i];
|
108 |
+
window.context_menu[options.control][option.name] = {
|
109 |
+
title: option.title,
|
110 |
+
action: option.action
|
111 |
+
};
|
112 |
+
}
|
113 |
+
}
|
114 |
+
$('body').append(html);
|
115 |
+
$('#gmaps_context_menu').mouseleave(function() {
|
116 |
+
$(this).delay(100).fadeOut(200);
|
117 |
+
});
|
118 |
+
};
|
119 |
+
|
120 |
+
this.hideContextMenu = function() {
|
121 |
+
$('#gmaps_context_menu').fadeOut(200);
|
122 |
+
};
|
123 |
+
|
124 |
+
//Events
|
125 |
+
google.maps.event.addListener(this.map, 'bounds_changed', function(e) {
|
126 |
+
if (options.bounds_changed) {
|
127 |
+
options.bounds_changed(e);
|
128 |
+
}
|
129 |
+
self.hideContextMenu();
|
130 |
+
});
|
131 |
+
google.maps.event.addListener(this.map, 'center_changed', function(e) {
|
132 |
+
if (options.center_changed) {
|
133 |
+
options.center_changed(e);
|
134 |
+
}
|
135 |
+
self.hideContextMenu();
|
136 |
+
});
|
137 |
+
google.maps.event.addListener(this.map, 'click', function(e) {
|
138 |
+
if (options.click) {
|
139 |
+
options.click(e);
|
140 |
+
}
|
141 |
+
self.hideContextMenu();
|
142 |
+
});
|
143 |
+
google.maps.event.addListener(this.map, 'dblclick', function(e) {
|
144 |
+
if (options.dblclick) {
|
145 |
+
options.dblclick(e);
|
146 |
+
}
|
147 |
+
self.hideContextMenu();
|
148 |
+
});
|
149 |
+
google.maps.event.addListener(this.map, 'drag', function(e) {
|
150 |
+
if (options.drag) {
|
151 |
+
options.drag(e);
|
152 |
+
}
|
153 |
+
self.hideContextMenu();
|
154 |
+
});
|
155 |
+
google.maps.event.addListener(this.map, 'dragend', function(e) {
|
156 |
+
if (options.dragend) {
|
157 |
+
options.dragend(e);
|
158 |
+
}
|
159 |
+
self.hideContextMenu();
|
160 |
+
});
|
161 |
+
google.maps.event.addListener(this.map, 'dragstart', function(e) {
|
162 |
+
if (options.dragstart) {
|
163 |
+
options.dragstart(e);
|
164 |
+
}
|
165 |
+
self.hideContextMenu();
|
166 |
+
});
|
167 |
+
google.maps.event.addListener(this.map, 'idle', function(e) {
|
168 |
+
if (options.idle) {
|
169 |
+
options.idle(e);
|
170 |
+
}
|
171 |
+
self.hideContextMenu();
|
172 |
+
});
|
173 |
+
google.maps.event.addListener(this.map, 'maptypeid_changed', function(e) {
|
174 |
+
if (options.maptypeid_changed) {
|
175 |
+
options.maptypeid_changed(e);
|
176 |
+
}
|
177 |
+
self.hideContextMenu();
|
178 |
+
});
|
179 |
+
google.maps.event.addListener(this.map, 'mousemove', function(e) {
|
180 |
+
if (options.mousemove) {
|
181 |
+
options.mousemove(e);
|
182 |
+
}
|
183 |
+
});
|
184 |
+
google.maps.event.addListener(this.map, 'mouseout', function(e) {
|
185 |
+
if (options.mouseout) {
|
186 |
+
options.mouseout(e);
|
187 |
+
}
|
188 |
+
});
|
189 |
+
google.maps.event.addListener(this.map, 'mouseover', function(e) {
|
190 |
+
if (options.mouseover) {
|
191 |
+
options.mouseover(e);
|
192 |
+
}
|
193 |
+
});
|
194 |
+
google.maps.event.addListener(this.map, 'projection_changed', function(e) {
|
195 |
+
if (options.projection_changed) {
|
196 |
+
options.projection_changed(e);
|
197 |
+
}
|
198 |
+
self.hideContextMenu();
|
199 |
+
});
|
200 |
+
google.maps.event.addListener(this.map, 'resize', function(e) {
|
201 |
+
if (options.resize) {
|
202 |
+
options.resize(e);
|
203 |
+
}
|
204 |
+
self.hideContextMenu();
|
205 |
+
});
|
206 |
+
google.maps.event.addListener(this.map, 'rightclick', function(e) {
|
207 |
+
if (options.rightclick) {
|
208 |
+
options.rightclick(e);
|
209 |
+
}
|
210 |
+
|
211 |
+
buildContextMenu('map', e);
|
212 |
+
});
|
213 |
+
google.maps.event.addListener(this.map, 'tilesloaded', function(e) {
|
214 |
+
if (options.tilesloaded) {
|
215 |
+
options.tilesloaded(e);
|
216 |
+
}
|
217 |
+
self.hideContextMenu();
|
218 |
+
});
|
219 |
+
google.maps.event.addListener(this.map, 'zoom_changed', function(e) {
|
220 |
+
if (options.zoom_changed) {
|
221 |
+
options.zoom_changed(e);
|
222 |
+
}
|
223 |
+
self.hideContextMenu();
|
224 |
+
});
|
225 |
+
|
226 |
+
// Map methods
|
227 |
+
this.setCenter = function(lat, lng, callback) {
|
228 |
+
this.map.panTo(new google.maps.LatLng(lat, lng));
|
229 |
+
if (callback) {
|
230 |
+
callback();
|
231 |
+
}
|
232 |
+
};
|
233 |
+
|
234 |
+
this.getCenter = function() {
|
235 |
+
return this.map.getCenter();
|
236 |
+
};
|
237 |
+
|
238 |
+
this.getDiv = function() {
|
239 |
+
return this.div;
|
240 |
+
};
|
241 |
+
|
242 |
+
this.setZoom = function(value) {
|
243 |
+
this.map.setZoom(value);
|
244 |
+
};
|
245 |
+
|
246 |
+
this.zoomIn = function(value) {
|
247 |
+
this.map.setZoom(this.map.getZoom() + value);
|
248 |
+
};
|
249 |
+
|
250 |
+
this.zoomOut = function(value) {
|
251 |
+
this.map.setZoom(this.map.getZoom() - value);
|
252 |
+
};
|
253 |
+
|
254 |
+
this.createControl = function(options) {
|
255 |
+
options.style.cursor = 'pointer';
|
256 |
+
options.style.fontFamily = 'Arial, sans-serif';
|
257 |
+
options.style.fontSize = '13px';
|
258 |
+
options.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px';
|
259 |
+
|
260 |
+
var controlDiv = $('<div></div>');
|
261 |
+
controlDiv.css(options.style);
|
262 |
+
controlDiv.text(options.text);
|
263 |
+
|
264 |
+
var control = controlDiv[0];
|
265 |
+
|
266 |
+
for(var e in options.events) {
|
267 |
+
google.maps.event.addDomListener(control, e, function() {
|
268 |
+
options.events[e].apply(this, [this]);
|
269 |
+
});
|
270 |
+
}
|
271 |
+
|
272 |
+
control.index = 1;
|
273 |
+
|
274 |
+
return control;
|
275 |
+
};
|
276 |
+
|
277 |
+
this.addControl = function(options) {
|
278 |
+
var position = google.maps.ControlPosition[options.position.toUpperCase()];
|
279 |
+
|
280 |
+
delete options.position;
|
281 |
+
|
282 |
+
var control = this.createControl(options);
|
283 |
+
this.controls.push(control);
|
284 |
+
this.map.controls[position].push(control);
|
285 |
+
|
286 |
+
return control;
|
287 |
+
};
|
288 |
+
|
289 |
+
// Markers
|
290 |
+
this.createMarker = function(options) {
|
291 |
+
if (options.lat && options.lng) {
|
292 |
+
var self = this;
|
293 |
+
var details = options.details;
|
294 |
+
var fences = options.fences;
|
295 |
+
var outside = options.outside;
|
296 |
+
var base_options = {
|
297 |
+
position: new google.maps.LatLng(options.lat, options.lng),
|
298 |
+
map: null
|
299 |
+
};
|
300 |
+
delete options.lat;
|
301 |
+
delete options.lng;
|
302 |
+
delete options.fences;
|
303 |
+
delete options.outside;
|
304 |
+
|
305 |
+
var marker_options = $.extend(base_options, options);
|
306 |
+
|
307 |
+
var marker = new google.maps.Marker(marker_options);
|
308 |
+
|
309 |
+
marker.fences = fences;
|
310 |
+
|
311 |
+
if (options.infoWindow) {
|
312 |
+
marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
|
313 |
+
|
314 |
+
if (options.infoWindow.closeclick) {
|
315 |
+
google.maps.event.addListener(marker.infoWindow, 'closeclick', function() {
|
316 |
+
options.infoWindow.closeclick();
|
317 |
+
});
|
318 |
+
}
|
319 |
+
if (options.infoWindow.content_changed) {
|
320 |
+
google.maps.event.addListener(marker.infoWindow, 'content_changed', function() {
|
321 |
+
options.infoWindow.content_changed();
|
322 |
+
});
|
323 |
+
}
|
324 |
+
if (options.infoWindow.domready) {
|
325 |
+
google.maps.event.addListener(marker.infoWindow, 'domready', function() {
|
326 |
+
options.infoWindow.domready();
|
327 |
+
});
|
328 |
+
}
|
329 |
+
if (options.infoWindow.position_changed) {
|
330 |
+
google.maps.event.addListener(marker.infoWindow, 'position_changed', function() {
|
331 |
+
options.infoWindow.position_changed();
|
332 |
+
});
|
333 |
+
}
|
334 |
+
if (options.infoWindow.zindex_changed) {
|
335 |
+
google.maps.event.addListener(marker.infoWindow, 'zindex_changed', function() {
|
336 |
+
options.infoWindow.zindex_changed();
|
337 |
+
});
|
338 |
+
}
|
339 |
+
}
|
340 |
+
|
341 |
+
google.maps.event.addListener(marker, 'click', function() {
|
342 |
+
this.details = details;
|
343 |
+
|
344 |
+
if (options.click) {
|
345 |
+
options.click.apply(this, [this]);
|
346 |
+
}
|
347 |
+
|
348 |
+
if (marker.infoWindow) {
|
349 |
+
self.hideInfoWindows();
|
350 |
+
marker.infoWindow.open(self.map, marker);
|
351 |
+
}
|
352 |
+
});
|
353 |
+
|
354 |
+
if (options.drag) {
|
355 |
+
google.maps.event.addListener(marker, 'drag', function() {
|
356 |
+
options.drag(this);
|
357 |
+
});
|
358 |
+
}
|
359 |
+
if (options.dragend || marker.fences) {
|
360 |
+
google.maps.event.addListener(marker, 'dragend', function() {
|
361 |
+
if (options.dragend) {
|
362 |
+
options.dragend(this);
|
363 |
+
}
|
364 |
+
if (marker.fences) {
|
365 |
+
self.checkMarkerGeofence(marker, function(m, f) {
|
366 |
+
outside(m, f);
|
367 |
+
});
|
368 |
+
}
|
369 |
+
});
|
370 |
+
}
|
371 |
+
if (options.dragstart) {
|
372 |
+
google.maps.event.addListener(marker, 'dragstart', function() {
|
373 |
+
options.dragstart(this);
|
374 |
+
});
|
375 |
+
}
|
376 |
+
if (options.mouseout) {
|
377 |
+
google.maps.event.addListener(marker, 'mouseout', function() {
|
378 |
+
options.mouseout(this);
|
379 |
+
});
|
380 |
+
}
|
381 |
+
if (options.mouseover) {
|
382 |
+
google.maps.event.addListener(marker, 'mouseover', function() {
|
383 |
+
options.mouseover(this);
|
384 |
+
});
|
385 |
+
}
|
386 |
+
if (options.mouseup) {
|
387 |
+
google.maps.event.addListener(marker, 'mouseup', function() {
|
388 |
+
options.mouseup(this);
|
389 |
+
});
|
390 |
+
}
|
391 |
+
if (options.position_changed) {
|
392 |
+
google.maps.event.addListener(marker, 'position_changed', function() {
|
393 |
+
options.position_changed(this);
|
394 |
+
});
|
395 |
+
}
|
396 |
+
|
397 |
+
return marker;
|
398 |
+
}
|
399 |
+
else {
|
400 |
+
throw 'No latitude or longitude defined';
|
401 |
+
}
|
402 |
+
};
|
403 |
+
|
404 |
+
this.addMarker = function(options) {
|
405 |
+
if (options.lat && options.lng) {
|
406 |
+
var marker = this.createMarker(options);
|
407 |
+
marker.setMap(this.map);
|
408 |
+
this.markers.push(marker);
|
409 |
+
|
410 |
+
return marker;
|
411 |
+
}
|
412 |
+
else {
|
413 |
+
throw 'No latitude or longitude defined';
|
414 |
+
}
|
415 |
+
};
|
416 |
+
|
417 |
+
this.addMarkers = function(array) {
|
418 |
+
for (var i=0, marker; marker=array[i]; i++) {
|
419 |
+
this.addMarker(marker);
|
420 |
+
}
|
421 |
+
return this.markers;
|
422 |
+
};
|
423 |
+
|
424 |
+
this.hideInfoWindows = function() {
|
425 |
+
for (var i=0, marker; marker=this.markers[i]; i++){
|
426 |
+
if (marker.infoWindow){
|
427 |
+
marker.infoWindow.close();
|
428 |
+
}
|
429 |
+
}
|
430 |
+
};
|
431 |
+
|
432 |
+
this.removeMarkers = function() {
|
433 |
+
for (var i=0, marker; marker=this.markers[i]; i++){
|
434 |
+
marker.setMap(null);
|
435 |
+
}
|
436 |
+
this.markers = [];
|
437 |
+
};
|
438 |
+
|
439 |
+
// Overlays
|
440 |
+
this.drawOverlay = function(options) {
|
441 |
+
var overlay = new google.maps.OverlayView();
|
442 |
+
overlay.setMap(self.map);
|
443 |
+
|
444 |
+
overlay.onAdd = function() {
|
445 |
+
var div = document.createElement('div');
|
446 |
+
div.style.borderStyle = "none";
|
447 |
+
div.style.borderWidth = "0px";
|
448 |
+
div.style.position = "absolute";
|
449 |
+
div.innerHTML = options.content;
|
450 |
+
|
451 |
+
self.overlay_div = div;
|
452 |
+
|
453 |
+
var panes = this.getPanes();
|
454 |
+
if (!options.layer) {
|
455 |
+
options.layer = 'overlayLayer';
|
456 |
+
}
|
457 |
+
var overlayLayer = panes[options.layer];
|
458 |
+
overlayLayer.appendChild(div);
|
459 |
+
};
|
460 |
+
|
461 |
+
overlay.draw = function() {
|
462 |
+
var projection = this.getProjection();
|
463 |
+
var pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
|
464 |
+
|
465 |
+
options.horizontalOffset = options.horizontalOffset || 0;
|
466 |
+
options.verticalOffset = options.verticalOffset || 0;
|
467 |
+
|
468 |
+
var div = self.overlay_div;
|
469 |
+
var content = div.children;
|
470 |
+
|
471 |
+
switch (options.verticalAlign) {
|
472 |
+
case 'top':
|
473 |
+
div.style.top = (pixel.y - $(content).height() + options.verticalOffset) + 'px';
|
474 |
+
break;
|
475 |
+
default:
|
476 |
+
case 'middle':
|
477 |
+
div.style.top = (pixel.y - ($(content).height() / 2) + options.verticalOffset) + 'px';
|
478 |
+
break;
|
479 |
+
case 'bottom':
|
480 |
+
div.style.top = (pixel.y + options.verticalOffset) + 'px';
|
481 |
+
break;
|
482 |
+
}
|
483 |
+
|
484 |
+
switch (options.horizontalAlign) {
|
485 |
+
case 'left':
|
486 |
+
div.style.left = (pixel.x - $(content).width() + options.horizontalOffset) + 'px';
|
487 |
+
break;
|
488 |
+
default:
|
489 |
+
case 'center':
|
490 |
+
div.style.left = (pixel.x - ($(content).width() / 2) + options.horizontalOffset) + 'px';
|
491 |
+
break;
|
492 |
+
case 'right':
|
493 |
+
div.style.left = (pixel.x + options.horizontalOffset) + 'px';
|
494 |
+
break;
|
495 |
+
}
|
496 |
+
};
|
497 |
+
|
498 |
+
overlay.onRemove = function() {
|
499 |
+
self.overlay_div.parentNode.removeChild(self.overlay_div);
|
500 |
+
self.overlay_div = null;
|
501 |
+
};
|
502 |
+
self.overlays.push(overlay);
|
503 |
+
return overlay;
|
504 |
+
};
|
505 |
+
|
506 |
+
this.removeOverlay = function(overlay) {
|
507 |
+
overlay.setMap(null);
|
508 |
+
};
|
509 |
+
|
510 |
+
this.removeOverlays = function() {
|
511 |
+
for (var i=0, item; item=self.overlays[i]; i++){
|
512 |
+
item.setMap(null);
|
513 |
+
}
|
514 |
+
self.overlays = [];
|
515 |
+
};
|
516 |
+
|
517 |
+
this.drawPolyline = function(options) {
|
518 |
+
var path = [];
|
519 |
+
var points = options.path;
|
520 |
+
|
521 |
+
if (points.length){
|
522 |
+
if (points[0][0] === undefined){
|
523 |
+
path = points;
|
524 |
+
}
|
525 |
+
else {
|
526 |
+
for (var i=0, latlng; latlng=points[i]; i++){
|
527 |
+
path.push(new google.maps.LatLng(latlng[0], latlng[1]));
|
528 |
+
}
|
529 |
+
}
|
530 |
+
}
|
531 |
+
|
532 |
+
var polyline = new google.maps.Polyline({
|
533 |
+
map: this.map,
|
534 |
+
path: path,
|
535 |
+
strokeColor: options.strokeColor,
|
536 |
+
strokeOpacity: options.strokeOpacity,
|
537 |
+
strokeWeight: options.strokeWeight
|
538 |
+
});
|
539 |
+
|
540 |
+
if (options.click) {
|
541 |
+
google.maps.event.addListener(polyline, 'click', function(e) {
|
542 |
+
options.click(e);
|
543 |
+
});
|
544 |
+
}
|
545 |
+
if (options.dblclick) {
|
546 |
+
google.maps.event.addListener(polyline, 'dblclick', function(e) {
|
547 |
+
options.dblclick(e);
|
548 |
+
});
|
549 |
+
}
|
550 |
+
if (options.mousedown) {
|
551 |
+
google.maps.event.addListener(polyline, 'mousedown', function(e) {
|
552 |
+
options.mousedown(e);
|
553 |
+
});
|
554 |
+
}
|
555 |
+
if (options.mousemove) {
|
556 |
+
google.maps.event.addListener(polyline, 'mousemove', function(e) {
|
557 |
+
options.mousemove(e);
|
558 |
+
});
|
559 |
+
}
|
560 |
+
if (options.mouseout) {
|
561 |
+
google.maps.event.addListener(polyline, 'mouseout', function(e) {
|
562 |
+
options.mouseout(e);
|
563 |
+
});
|
564 |
+
}
|
565 |
+
if (options.mouseover) {
|
566 |
+
google.maps.event.addListener(polyline, 'mouseover', function(e) {
|
567 |
+
options.mouseover(e);
|
568 |
+
});
|
569 |
+
}
|
570 |
+
if (options.mouseup) {
|
571 |
+
google.maps.event.addListener(polyline, 'mouseup', function(e) {
|
572 |
+
options.mouseup(e);
|
573 |
+
});
|
574 |
+
}
|
575 |
+
if (options.rightclick) {
|
576 |
+
google.maps.event.addListener(polyline, 'rightclick', function(e) {
|
577 |
+
options.rightclick(e);
|
578 |
+
});
|
579 |
+
}
|
580 |
+
|
581 |
+
this.polylines.push(polyline);
|
582 |
+
|
583 |
+
return polyline;
|
584 |
+
};
|
585 |
+
|
586 |
+
this.drawCircle = function(options) {
|
587 |
+
options = $.extend({
|
588 |
+
map: this.map,
|
589 |
+
center: new google.maps.LatLng(options.lat, options.lng)
|
590 |
+
}, options);
|
591 |
+
|
592 |
+
delete options.lat;
|
593 |
+
delete options.lng;
|
594 |
+
var polygon = new google.maps.Circle(options);
|
595 |
+
|
596 |
+
google.maps.event.addListener(polygon, 'click', function(e) {
|
597 |
+
if (options.click) {
|
598 |
+
options.click(e);
|
599 |
+
}
|
600 |
+
});
|
601 |
+
google.maps.event.addListener(polygon, 'dblclick', function(e) {
|
602 |
+
if (options.dblclick) {
|
603 |
+
options.dblclick(e);
|
604 |
+
}
|
605 |
+
});
|
606 |
+
google.maps.event.addListener(polygon, 'mousedown', function(e) {
|
607 |
+
if (options.mousedown) {
|
608 |
+
options.mousedown(e);
|
609 |
+
}
|
610 |
+
});
|
611 |
+
google.maps.event.addListener(polygon, 'mousemove', function(e) {
|
612 |
+
if (options.mousemove) {
|
613 |
+
options.mousemove(e);
|
614 |
+
}
|
615 |
+
});
|
616 |
+
google.maps.event.addListener(polygon, 'mouseout', function(e) {
|
617 |
+
if (options.mouseout) {
|
618 |
+
options.mouseout(e);
|
619 |
+
}
|
620 |
+
});
|
621 |
+
google.maps.event.addListener(polygon, 'mouseover', function(e) {
|
622 |
+
if (options.mouseover) {
|
623 |
+
options.mouseover(e);
|
624 |
+
}
|
625 |
+
});
|
626 |
+
google.maps.event.addListener(polygon, 'mouseup', function(e) {
|
627 |
+
if (options.mouseup) {
|
628 |
+
options.mouseup(e);
|
629 |
+
}
|
630 |
+
});
|
631 |
+
google.maps.event.addListener(polygon, 'rightclick', function(e) {
|
632 |
+
if (options.rightclick) {
|
633 |
+
options.rightclick(e);
|
634 |
+
}
|
635 |
+
});
|
636 |
+
|
637 |
+
return polygon;
|
638 |
+
};
|
639 |
+
|
640 |
+
this.drawPolygon = function(options) {
|
641 |
+
options = $.extend({
|
642 |
+
map: this.map
|
643 |
+
}, options);
|
644 |
+
var polygon = new google.maps.Polygon(options);
|
645 |
+
|
646 |
+
google.maps.event.addListener(polygon, 'click', function(e) {
|
647 |
+
if (options.click) {
|
648 |
+
options.click(e);
|
649 |
+
}
|
650 |
+
});
|
651 |
+
google.maps.event.addListener(polygon, 'dblclick', function(e) {
|
652 |
+
if (options.dblclick) {
|
653 |
+
options.dblclick(e);
|
654 |
+
}
|
655 |
+
});
|
656 |
+
google.maps.event.addListener(polygon, 'mousedown', function(e) {
|
657 |
+
if (options.mousedown) {
|
658 |
+
options.mousedown(e);
|
659 |
+
}
|
660 |
+
});
|
661 |
+
google.maps.event.addListener(polygon, 'mousemove', function(e) {
|
662 |
+
if (options.mousemove) {
|
663 |
+
options.mousemove(e);
|
664 |
+
}
|
665 |
+
});
|
666 |
+
google.maps.event.addListener(polygon, 'mouseout', function(e) {
|
667 |
+
if (options.mouseout) {
|
668 |
+
options.mouseout(e);
|
669 |
+
}
|
670 |
+
});
|
671 |
+
google.maps.event.addListener(polygon, 'mouseover', function(e) {
|
672 |
+
if (options.mouseover) {
|
673 |
+
options.mouseover(e);
|
674 |
+
}
|
675 |
+
});
|
676 |
+
google.maps.event.addListener(polygon, 'mouseup', function(e) {
|
677 |
+
if (options.mouseup) {
|
678 |
+
options.mouseup(e);
|
679 |
+
}
|
680 |
+
});
|
681 |
+
google.maps.event.addListener(polygon, 'rightclick', function(e) {
|
682 |
+
if (options.rightclick) {
|
683 |
+
options.rightclick(e);
|
684 |
+
}
|
685 |
+
});
|
686 |
+
|
687 |
+
this.polygons.push(polygon);
|
688 |
+
|
689 |
+
return polygon;
|
690 |
+
};
|
691 |
+
|
692 |
+
this.getFromFusionTables = function(options) {
|
693 |
+
var events = options.events;
|
694 |
+
|
695 |
+
delete options.events;
|
696 |
+
|
697 |
+
var fusion_tables_options = options;
|
698 |
+
|
699 |
+
var layer = new google.maps.FusionTablesLayer(fusion_tables_options);
|
700 |
+
|
701 |
+
for (var e in events) {
|
702 |
+
google.maps.event.addListener(layer, e, function(ev){
|
703 |
+
events[e].apply(this, [ev]);
|
704 |
+
});
|
705 |
+
}
|
706 |
+
|
707 |
+
this.layers.push(layer);
|
708 |
+
|
709 |
+
return layer;
|
710 |
+
};
|
711 |
+
|
712 |
+
this.loadFromFusionTables = function(options) {
|
713 |
+
var layer = this.getFromFusionTables(options);
|
714 |
+
layer.setMap(this.map);
|
715 |
+
|
716 |
+
return layer;
|
717 |
+
};
|
718 |
+
|
719 |
+
this.getFromKML = function(options) {
|
720 |
+
var url = options.url;
|
721 |
+
var events = options.events;
|
722 |
+
|
723 |
+
delete options.url;
|
724 |
+
delete options.events;
|
725 |
+
|
726 |
+
var kml_options = options;
|
727 |
+
|
728 |
+
var layer = new google.maps.KmlLayer(url, kml_options);
|
729 |
+
|
730 |
+
for (var e in events) {
|
731 |
+
google.maps.event.addListener(layer, e, function(ev){
|
732 |
+
events[e].apply(this, [ev]);
|
733 |
+
});
|
734 |
+
}
|
735 |
+
|
736 |
+
this.layers.push(layer);
|
737 |
+
|
738 |
+
return layer;
|
739 |
+
};
|
740 |
+
|
741 |
+
this.loadFromKML = function(options) {
|
742 |
+
var layer = this.getFromKML(options);
|
743 |
+
layer.setMap(this.map);
|
744 |
+
|
745 |
+
return layer;
|
746 |
+
};
|
747 |
+
|
748 |
+
// Services
|
749 |
+
var travelMode, unitSystem;
|
750 |
+
this.getRoutes = function(options) {
|
751 |
+
switch (options.travelMode) {
|
752 |
+
case 'bicycling':
|
753 |
+
travelMode = google.maps.TravelMode.BICYCLING;
|
754 |
+
break;
|
755 |
+
case 'driving':
|
756 |
+
travelMode = google.maps.TravelMode.DRIVING;
|
757 |
+
break;
|
758 |
+
// case 'walking':
|
759 |
+
default:
|
760 |
+
travelMode = google.maps.TravelMode.WALKING;
|
761 |
+
break;
|
762 |
+
}
|
763 |
+
|
764 |
+
if (options.unitSystem === 'imperial') {
|
765 |
+
unitSystem = google.maps.UnitSystem.IMPERIAL;
|
766 |
+
}
|
767 |
+
else {
|
768 |
+
unitSystem = google.maps.UnitSystem.METRIC;
|
769 |
+
}
|
770 |
+
|
771 |
+
var base_options = {
|
772 |
+
avoidHighways: true,
|
773 |
+
avoidTolls: true,
|
774 |
+
optimizeWaypoints: true,
|
775 |
+
waypoints: []
|
776 |
+
};
|
777 |
+
var request_options = $.extend(base_options, options);
|
778 |
+
request_options.origin = new google.maps.LatLng(options.origin[0], options.origin[1]);
|
779 |
+
request_options.destination = new google.maps.LatLng(options.destination[0], options.destination[1]);
|
780 |
+
request_options.travelMode = travelMode;
|
781 |
+
request_options.unitSystem = unitSystem;
|
782 |
+
|
783 |
+
delete request_options.callback;
|
784 |
+
|
785 |
+
var self = this;
|
786 |
+
var service = new google.maps.DirectionsService();
|
787 |
+
|
788 |
+
service.route(request_options, function(result, status) {
|
789 |
+
if (status === google.maps.DirectionsStatus.OK) {
|
790 |
+
for (var r in result.routes) {
|
791 |
+
if (result.routes.hasOwnProperty(r)) {
|
792 |
+
self.routes.push(result.routes[r]);
|
793 |
+
}
|
794 |
+
}
|
795 |
+
}
|
796 |
+
if (options.callback) {
|
797 |
+
options.callback(self.routes);
|
798 |
+
}
|
799 |
+
});
|
800 |
+
};
|
801 |
+
|
802 |
+
this.drawRoute = function(options) {
|
803 |
+
var self = this;
|
804 |
+
this.getRoutes({
|
805 |
+
origin: options.origin,
|
806 |
+
destination: options.destination,
|
807 |
+
travelMode: options.travelMode,
|
808 |
+
callback: function(e) {
|
809 |
+
if (e.length > 0) {
|
810 |
+
self.drawPolyline({
|
811 |
+
path: e[e.length - 1].overview_path,
|
812 |
+
strokeColor: options.strokeColor,
|
813 |
+
strokeOpacity: options.strokeOpacity,
|
814 |
+
strokeWeight: options.strokeWeight
|
815 |
+
});
|
816 |
+
if (options.callback) {
|
817 |
+
options.callback(e[e.length - 1]);
|
818 |
+
}
|
819 |
+
}
|
820 |
+
}
|
821 |
+
});
|
822 |
+
};
|
823 |
+
|
824 |
+
this.travelRoute = function(options) {
|
825 |
+
if (options.origin && options.destination) {
|
826 |
+
this.getRoutes({
|
827 |
+
origin: options.origin,
|
828 |
+
destination: options.destination,
|
829 |
+
travelMode: options.travelMode,
|
830 |
+
callback: function(e) {
|
831 |
+
if (e.length > 0 && options.step) {
|
832 |
+
var route = e[e.length - 1];
|
833 |
+
if (route.legs.length > 0) {
|
834 |
+
var steps = route.legs[0].steps;
|
835 |
+
for (var i=0, step; step=steps[i]; i++) {
|
836 |
+
step.step_number = i;
|
837 |
+
options.step(step);
|
838 |
+
}
|
839 |
+
}
|
840 |
+
}
|
841 |
+
}
|
842 |
+
});
|
843 |
+
}
|
844 |
+
else if (options.route) {
|
845 |
+
if (options.route.legs.length > 0) {
|
846 |
+
var steps = options.route.legs[0].steps;
|
847 |
+
for (var i=0, step; step=steps[i]; i++) {
|
848 |
+
step.step_number = i;
|
849 |
+
options.step(step);
|
850 |
+
}
|
851 |
+
}
|
852 |
+
}
|
853 |
+
};
|
854 |
+
|
855 |
+
this.drawSteppedRoute = function(options) {
|
856 |
+
if (options.origin && options.destination) {
|
857 |
+
this.getRoutes({
|
858 |
+
origin: options.origin,
|
859 |
+
destination: options.destination,
|
860 |
+
travelMode: options.travelMode,
|
861 |
+
callback: function(e) {
|
862 |
+
if (e.length > 0 && options.step) {
|
863 |
+
var route = e[e.length - 1];
|
864 |
+
if (route.legs.length > 0) {
|
865 |
+
var steps = route.legs[0].steps;
|
866 |
+
for (var i=0, step; step=steps[i]; i++) {
|
867 |
+
step.step_number = i;
|
868 |
+
self.drawPolyline({
|
869 |
+
path: step.path,
|
870 |
+
strokeColor: options.strokeColor,
|
871 |
+
strokeOpacity: options.strokeOpacity,
|
872 |
+
strokeWeight: options.strokeWeight
|
873 |
+
});
|
874 |
+
options.step(step);
|
875 |
+
}
|
876 |
+
}
|
877 |
+
}
|
878 |
+
}
|
879 |
+
});
|
880 |
+
}
|
881 |
+
else if (options.route) {
|
882 |
+
if (options.route.legs.length > 0) {
|
883 |
+
var steps = options.route.legs[0].steps;
|
884 |
+
for (var i=0, step; step=steps[i]; i++) {
|
885 |
+
step.step_number = i;
|
886 |
+
self.drawPolyline({
|
887 |
+
path: step.path,
|
888 |
+
strokeColor: options.strokeColor,
|
889 |
+
strokeOpacity: options.strokeOpacity,
|
890 |
+
strokeWeight: options.strokeWeight
|
891 |
+
});
|
892 |
+
options.step(step);
|
893 |
+
}
|
894 |
+
}
|
895 |
+
}
|
896 |
+
};
|
897 |
+
|
898 |
+
// Geofence
|
899 |
+
this.checkGeofence = function(lat, lng, fence) {
|
900 |
+
return fence.containsLatLng(new google.maps.LatLng(lat, lng));
|
901 |
+
};
|
902 |
+
|
903 |
+
this.checkMarkerGeofence = function(marker, outside_callback) {
|
904 |
+
if (marker.fences) {
|
905 |
+
for (var i=0, fence; fence=marker.fences[i]; i++) {
|
906 |
+
var pos = marker.getPosition();
|
907 |
+
if (!self.checkGeofence(pos.lat(), pos.lng(), fence)) {
|
908 |
+
outside_callback(marker, fence);
|
909 |
+
}
|
910 |
+
}
|
911 |
+
}
|
912 |
+
};
|
913 |
+
};
|
914 |
+
|
915 |
+
GMaps.Route = function(options) {
|
916 |
+
this.map = options.map;
|
917 |
+
this.route = options.route;
|
918 |
+
this.step_count = 0;
|
919 |
+
this.steps = this.route.legs[0].steps;
|
920 |
+
this.steps_length = this.steps.length;
|
921 |
+
|
922 |
+
this.polyline = this.map.drawPolyline({
|
923 |
+
path: new google.maps.MVCArray(),
|
924 |
+
strokeColor: options.strokeColor,
|
925 |
+
strokeOpacity: options.strokeOpacity,
|
926 |
+
strokeWeight: options.strokeWeight
|
927 |
+
}).getPath();
|
928 |
+
|
929 |
+
this.back = function() {
|
930 |
+
if (this.step_count > 0) {
|
931 |
+
this.step_count--;
|
932 |
+
var path = this.route.legs[0].steps[this.step_count].path;
|
933 |
+
for (var p in path){
|
934 |
+
if (path.hasOwnProperty(p)){
|
935 |
+
this.polyline.pop();
|
936 |
+
}
|
937 |
+
}
|
938 |
+
}
|
939 |
+
};
|
940 |
+
|
941 |
+
this.forward = function() {
|
942 |
+
if (this.step_count < this.steps_length) {
|
943 |
+
var path = this.route.legs[0].steps[this.step_count].path;
|
944 |
+
for (var p in path){
|
945 |
+
if (path.hasOwnProperty(p)){
|
946 |
+
this.polyline.push(path[p]);
|
947 |
+
}
|
948 |
+
}
|
949 |
+
this.step_count++;
|
950 |
+
}
|
951 |
+
};
|
952 |
+
};
|
953 |
+
|
954 |
+
// Geolocation (Modern browsers only)
|
955 |
+
GMaps.geolocate = function(options) {
|
956 |
+
if (navigator.geolocation) {
|
957 |
+
navigator.geolocation.getCurrentPosition(function(position) {
|
958 |
+
options.success(position);
|
959 |
+
if (options.always) {
|
960 |
+
options.always();
|
961 |
+
}
|
962 |
+
}, function(error) {
|
963 |
+
options.error(error);
|
964 |
+
if (options.always) {
|
965 |
+
options.always();
|
966 |
+
}
|
967 |
+
}, options.options);
|
968 |
+
}
|
969 |
+
else {
|
970 |
+
options.not_supported();
|
971 |
+
if (options.always) {
|
972 |
+
options.always();
|
973 |
+
}
|
974 |
+
}
|
975 |
+
};
|
976 |
+
|
977 |
+
// Geocoding
|
978 |
+
GMaps.geocode = function(options) {
|
979 |
+
this.geocoder = new google.maps.Geocoder();
|
980 |
+
var callback = options.callback;
|
981 |
+
if (options.lat && options.lng) {
|
982 |
+
options.latLng = new google.maps.LatLng(options.lat, options.lng);
|
983 |
+
}
|
984 |
+
|
985 |
+
delete options.lat;
|
986 |
+
delete options.lng;
|
987 |
+
delete options.callback;
|
988 |
+
this.geocoder.geocode(options, function(results, status) {
|
989 |
+
callback(results, status);
|
990 |
+
});
|
991 |
+
};
|
992 |
+
|
993 |
+
// Static maps
|
994 |
+
GMaps.staticMapURL = function(options){
|
995 |
+
var parameters = [];
|
996 |
+
var data;
|
997 |
+
|
998 |
+
var static_root = 'http://maps.googleapis.com/maps/api/staticmap';
|
999 |
+
if (options.url){
|
1000 |
+
static_root = options.url;
|
1001 |
+
delete options.url;
|
1002 |
+
}
|
1003 |
+
static_root += '?';
|
1004 |
+
|
1005 |
+
var markers = options.markers;
|
1006 |
+
delete options.markers;
|
1007 |
+
if (!markers && options.marker){
|
1008 |
+
markers = [options.marker];
|
1009 |
+
delete options.marker;
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
var polyline = options.polyline;
|
1013 |
+
delete options.polyline;
|
1014 |
+
|
1015 |
+
/** Map options **/
|
1016 |
+
if (options.center){
|
1017 |
+
parameters.push('center=' + options.center);
|
1018 |
+
delete options.center;
|
1019 |
+
}
|
1020 |
+
else if (options.address){
|
1021 |
+
parameters.push('center=' + options.address);
|
1022 |
+
delete options.address;
|
1023 |
+
}
|
1024 |
+
else if (options.lat){
|
1025 |
+
parameters.push(['center=', options.lat, ',', options.lng].join(''));
|
1026 |
+
delete options.lat;
|
1027 |
+
delete options.lng;
|
1028 |
+
}
|
1029 |
+
else if (options.visible){
|
1030 |
+
var visible = encodeURI(options.visible.join('|'));
|
1031 |
+
parameters.push('visible=' + visible);
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
var size = options.size;
|
1035 |
+
if (size){
|
1036 |
+
if (size.join){
|
1037 |
+
size = size.join('x');
|
1038 |
+
}
|
1039 |
+
delete options.size;
|
1040 |
+
}
|
1041 |
+
else {
|
1042 |
+
size = '630x300';
|
1043 |
+
}
|
1044 |
+
parameters.push('size=' + size);
|
1045 |
+
|
1046 |
+
if (!options.zoom){
|
1047 |
+
options.zoom = 15;
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
|
1051 |
+
delete options.sensor;
|
1052 |
+
parameters.push('sensor=' + sensor);
|
1053 |
+
|
1054 |
+
for (var param in options){
|
1055 |
+
if (options.hasOwnProperty(param)){
|
1056 |
+
parameters.push(param + '=' + options[param]);
|
1057 |
+
}
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
/** Markers **/
|
1061 |
+
if (markers){
|
1062 |
+
var marker, loc;
|
1063 |
+
|
1064 |
+
for (var i=0; data=markers[i]; i++){
|
1065 |
+
marker = [];
|
1066 |
+
|
1067 |
+
if (data.size && data.size !== 'normal'){
|
1068 |
+
marker.push('size:' + data.size);
|
1069 |
+
}
|
1070 |
+
else if (data.icon){
|
1071 |
+
marker.push('icon:' + encodeURI(data.icon));
|
1072 |
+
}
|
1073 |
+
|
1074 |
+
if (data.color){
|
1075 |
+
marker.push('color:' + data.color.replace('#', '0x'));
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
if (data.label){
|
1079 |
+
marker.push('label:' + data.label[0].toUpperCase());
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
loc = (data.address ? data.address : data.lat + ',' + data.lng);
|
1083 |
+
|
1084 |
+
if (marker.length || i === 0){
|
1085 |
+
marker.push(loc);
|
1086 |
+
marker = marker.join('|');
|
1087 |
+
parameters.push('markers=' + encodeURI(marker));
|
1088 |
+
}
|
1089 |
+
// New marker without styles
|
1090 |
+
else {
|
1091 |
+
marker = parameters.pop() + encodeURI('|' + loc);
|
1092 |
+
parameters.push(marker);
|
1093 |
+
}
|
1094 |
+
}
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
/** Polylines **/
|
1098 |
+
function parseColor(color, opacity){
|
1099 |
+
if (color[0] === '#'){
|
1100 |
+
color = color.replace('#', '0x');
|
1101 |
+
|
1102 |
+
if (opacity){
|
1103 |
+
opacity = parseFloat(opacity);
|
1104 |
+
opacity = Math.min(1, Math.max(opacity, 0));
|
1105 |
+
if (opacity === 0){
|
1106 |
+
return '0x00000000';
|
1107 |
+
}
|
1108 |
+
opacity = (opacity * 255).toString(16);
|
1109 |
+
if (opacity.length === 1){
|
1110 |
+
opacity += opacity;
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
color = color.slice(0,8) + opacity;
|
1114 |
+
}
|
1115 |
+
}
|
1116 |
+
return color;
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
if (polyline){
|
1120 |
+
data = polyline;
|
1121 |
+
polyline = [];
|
1122 |
+
|
1123 |
+
if (data.strokeWeight){
|
1124 |
+
polyline.push('weight:' + parseInt(data.strokeWeight, 10));
|
1125 |
+
}
|
1126 |
+
|
1127 |
+
if (data.strokeColor){
|
1128 |
+
var color = parseColor(data.strokeColor, data.strokeOpacity);
|
1129 |
+
polyline.push('color:' + color);
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
if (data.fillColor){
|
1133 |
+
var fillcolor = parseColor(data.fillColor, data.fillOpacity);
|
1134 |
+
polyline.push('fillcolor:' + fillcolor);
|
1135 |
+
}
|
1136 |
+
|
1137 |
+
var path = data.path;
|
1138 |
+
if (path.join){
|
1139 |
+
for (var j=0, pos; pos=path[j]; j++){
|
1140 |
+
polyline.push(pos.join(','));
|
1141 |
+
}
|
1142 |
+
}
|
1143 |
+
else {
|
1144 |
+
polyline.push('enc:' + path);
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
polyline = polyline.join('|');
|
1148 |
+
parameters.push('path=' + encodeURI(polyline));
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
parameters = parameters.join('&');
|
1152 |
+
return static_root + parameters;
|
1153 |
+
};
|
1154 |
+
|
1155 |
+
//==========================
|
1156 |
+
// Polygon containsLatLng
|
1157 |
+
// https://github.com/tparkin/Google-Maps-Point-in-Polygon
|
1158 |
+
// Poygon getBounds extension - google-maps-extensions
|
1159 |
+
// http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
|
1160 |
+
if (!google.maps.Polygon.prototype.getBounds) {
|
1161 |
+
google.maps.Polygon.prototype.getBounds = function(latLng) {
|
1162 |
+
var bounds = new google.maps.LatLngBounds();
|
1163 |
+
var paths = this.getPaths();
|
1164 |
+
var path;
|
1165 |
+
|
1166 |
+
for (var p = 0; p < paths.getLength(); p++) {
|
1167 |
+
path = paths.getAt(p);
|
1168 |
+
for (var i = 0; i < path.getLength(); i++) {
|
1169 |
+
bounds.extend(path.getAt(i));
|
1170 |
+
}
|
1171 |
+
}
|
1172 |
+
|
1173 |
+
return bounds;
|
1174 |
+
};
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
// Polygon containsLatLng - method to determine if a latLng is within a polygon
|
1178 |
+
google.maps.Polygon.prototype.containsLatLng = function(latLng) {
|
1179 |
+
// Exclude points outside of bounds as there is no way they are in the poly
|
1180 |
+
var bounds = this.getBounds();
|
1181 |
+
|
1182 |
+
if (bounds !== null && !bounds.contains(latLng)) {
|
1183 |
+
return false;
|
1184 |
+
}
|
1185 |
+
|
1186 |
+
// Raycast point in polygon method
|
1187 |
+
var inPoly = false;
|
1188 |
+
|
1189 |
+
var numPaths = this.getPaths().getLength();
|
1190 |
+
for (var p = 0; p < numPaths; p++) {
|
1191 |
+
var path = this.getPaths().getAt(p);
|
1192 |
+
var numPoints = path.getLength();
|
1193 |
+
var j = numPoints - 1;
|
1194 |
+
|
1195 |
+
for (var i = 0; i < numPoints; i++) {
|
1196 |
+
var vertex1 = path.getAt(i);
|
1197 |
+
var vertex2 = path.getAt(j);
|
1198 |
+
|
1199 |
+
if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
|
1200 |
+
if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
|
1201 |
+
inPoly = !inPoly;
|
1202 |
+
}
|
1203 |
+
}
|
1204 |
+
|
1205 |
+
j = i;
|
1206 |
+
}
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
return inPoly;
|
1210 |
+
};
|
1211 |
+
|
1212 |
+
google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
|
1213 |
+
return this.contains(latLng);
|
1214 |
+
};
|
1215 |
+
|
1216 |
+
google.maps.Marker.prototype.setFences = function(fences) {
|
1217 |
+
this.fences = fences;
|
1218 |
+
};
|
1219 |
+
|
1220 |
+
google.maps.Marker.prototype.addFence = function(fence) {
|
1221 |
+
this.fences.push(fence);
|
1222 |
+
};
|
1223 |
+
|
1224 |
+
return GMaps;
|
1225 |
+
}(jQuery));
|
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,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.4
|
7 |
+
Stable tag: 0.4.0
|
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 |
+
[This plugin maintained on GitHub.](https://github.com/miya0001/simple-map)
|
19 |
+
|
20 |
+
= Some features: =
|
21 |
+
|
22 |
+
* Allow you to embed google map based on shortcode.
|
23 |
+
* Points can be added using address or lat/ong.
|
24 |
+
* Display static map for iPhone automatically.
|
25 |
+
|
26 |
+
= Translators =
|
27 |
+
|
28 |
+
* Japanese(ja) - [Takayuki Miyauchi](http://firegoby.jp/)
|
29 |
+
|
30 |
+
Please contact to me.
|
31 |
+
|
32 |
+
* http://wpist.me/ (en)
|
33 |
+
* http://firegoby.jp/ (ja)
|
34 |
+
* @miya0001 on twitter.
|
35 |
+
* https://github.com/miya0001/simple-map
|
36 |
+
|
37 |
+
= Contributors =
|
38 |
+
|
39 |
+
* [Takayuki Miyauchi](http://firegoby.jp/)
|
40 |
+
|
41 |
+
== Installation ==
|
42 |
+
|
43 |
+
* A plug-in installation screen is displayed on the WordPress admin panel.
|
44 |
+
* It installs it in `wp-content/plugins`.
|
45 |
+
* The plug-in is made effective.
|
46 |
+
|
47 |
+
== Changelog ==
|
48 |
+
|
49 |
+
= 0.1.0 =
|
50 |
+
* The first release.
|
51 |
+
|
52 |
+
== Credits ==
|
53 |
+
|
54 |
+
This plug-in is not guaranteed though the user of WordPress can freely use this plug-in free of charge regardless of the purpose.
|
55 |
+
The author must acknowledge the thing that the operation guarantee and the support in this plug-in use are not done at all beforehand.
|
56 |
+
|
57 |
+
== Contact ==
|
58 |
+
|
59 |
+
twitter @miya0001
|
simple-map.php
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.4.0
|
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('wp_head', array(&$this, 'wp_head'));
|
27 |
+
add_shortcode('map', array(&$this, 'shortcode'));
|
28 |
+
}
|
29 |
+
|
30 |
+
public function wp_head()
|
31 |
+
{
|
32 |
+
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";
|
33 |
+
}
|
34 |
+
|
35 |
+
public function wp_enqueue_scripts()
|
36 |
+
{
|
37 |
+
wp_register_script(
|
38 |
+
'google-maps-api',
|
39 |
+
'http://maps.google.com/maps/api/js?sensor=false',
|
40 |
+
false,
|
41 |
+
null,
|
42 |
+
true
|
43 |
+
);
|
44 |
+
|
45 |
+
wp_register_script(
|
46 |
+
'gmaps.js',
|
47 |
+
plugins_url('js/gmaps.js' , __FILE__),
|
48 |
+
array('jquery', 'google-maps-api'),
|
49 |
+
'0.1.12.1',
|
50 |
+
true
|
51 |
+
);
|
52 |
+
|
53 |
+
wp_register_script(
|
54 |
+
'simplemap',
|
55 |
+
apply_filters(
|
56 |
+
"simplemap_script",
|
57 |
+
plugins_url('js/simplemap.js' , __FILE__)
|
58 |
+
),
|
59 |
+
array('gmaps.js'),
|
60 |
+
filemtime(dirname(__FILE__).'/js/simplemap.js'),
|
61 |
+
true
|
62 |
+
);
|
63 |
+
wp_enqueue_script('simplemap');
|
64 |
+
}
|
65 |
+
|
66 |
+
public function shortcode($p, $content = null)
|
67 |
+
{
|
68 |
+
add_action("wp_footer", array(&$this, "wp_enqueue_scripts"));
|
69 |
+
|
70 |
+
if (isset($p['width']) && preg_match("/^[0-9]+(%|px)$/", $p['width'])) {
|
71 |
+
$w = $p['width'];
|
72 |
+
} else {
|
73 |
+
$w = apply_filters("simplemap_default_width", $this->width);
|
74 |
+
}
|
75 |
+
if (isset($p['height']) && preg_match("/^[0-9]+(%|px)$/", $p['height'])) {
|
76 |
+
$h = $p['height'];
|
77 |
+
} else {
|
78 |
+
$h = apply_filters("simplemap_default_height", $this->height);
|
79 |
+
}
|
80 |
+
if (isset($p['zoom']) && $p['zoom']) {
|
81 |
+
$zoom = $p['zoom'];
|
82 |
+
} else {
|
83 |
+
$zoom = apply_filters('simplemap_default_zoom', $this->zoom);
|
84 |
+
}
|
85 |
+
if (isset($p['breakpoint']) && intval($p['breakpoint'])) {
|
86 |
+
if (intval($p['breakpoint']) > $this->max_breakpoint) {
|
87 |
+
$breakpoint = $this->max_breakpoint;
|
88 |
+
} else {
|
89 |
+
$breakpoint = intval($p['breakpoint']);
|
90 |
+
}
|
91 |
+
} else {
|
92 |
+
$breakpoint = apply_filters(
|
93 |
+
'simplemap_default_breakpoint',
|
94 |
+
$this->breakpoint
|
95 |
+
);
|
96 |
+
}
|
97 |
+
$addr = '';
|
98 |
+
$lat = '';
|
99 |
+
$lng = '';
|
100 |
+
if (isset($p['addr']) && $p['addr']) {
|
101 |
+
$addr = esc_html($p['addr']);
|
102 |
+
} elseif ($content) {
|
103 |
+
$addr = $content;
|
104 |
+
} elseif (isset($p['lat']) && preg_match("/^\-?[0-9\.]+$/", $p['lat'])
|
105 |
+
&& isset($p['lng']) && preg_match("/^\-?[0-9\.]+$/", $p['lng'])){
|
106 |
+
$lat = $p['lat'];
|
107 |
+
$lng = $p['lng'];
|
108 |
+
} else {
|
109 |
+
return;
|
110 |
+
}
|
111 |
+
return sprintf(
|
112 |
+
'<div class="%s"><div data-breakpoint="%s" data-lat="%s" data-lng="%s" data-zoom="%s" style="width:%s;height:%s;">%s</div></div>',
|
113 |
+
apply_filters("simplemap_class_name", $this->class_name),
|
114 |
+
$breakpoint,
|
115 |
+
$lat,
|
116 |
+
$lng,
|
117 |
+
$zoom,
|
118 |
+
$w,
|
119 |
+
$h,
|
120 |
+
$addr
|
121 |
+
);
|
122 |
+
}
|
123 |
+
|
124 |
+
}
|
125 |
+
|
126 |
+
|
127 |
+
// EOF
|