gmap3.min.js 9.7 KB

12345678910
  1. /*
  2. * GMAP3 Plugin for jQuery
  3. * Version : 7.2
  4. * Date : 2016/12/03
  5. * Author : DEMONTE Jean-Baptiste
  6. * Contact : jbdemonte@gmail.com
  7. * Web site : http://gmap3.net
  8. * Licence : GPL-3.0+
  9. */
  10. !function(af,ao,Q){function ag(a){return an(!0,{},a||{})}function ak(){var a=Array.prototype.slice,b=a.call(arguments,1);return a.apply(arguments[0],b)}function Y(a){return"undefined"==typeof a}function aq(a){return ah.apply(af,a)}function z(a){return ah().then(function(){return a})}function I(h,m){var f=Math,j=f.PI,k=j*h.lat()/180,g=j*h.lng()/180,p=j*m.lat()/180,b=j*m.lng()/180,d=f.cos,l=f.sin;return 6371000*f.acos(f.min(d(k)*d(p)*d(g)*d(b)+d(k)*l(g)*d(p)*l(b)+l(k)*l(p),1))}function am(a){"loading"!=Q.readyState?a():Q.addEventListener("DOMContentLoaded",a)}function V(a){return ar(a).map(function(b){return encodeURIComponent(b)+"="+encodeURIComponent(a[b])}).join("&")}function ai(a){return N[a]||(N[a]=ab(a)),N[a]}function ab(b){function c(d){return a.apply(this,d)}var a=U[b];return c.prototype=a.prototype,new c(ak(arguments,1))}function W(a){var b=q();return"string"==typeof a&&(a={address:a}),ai("Geocoder").geocode(a,function(d,c){c===U.GeocoderStatus.OK?b.resolve(d[0].geometry.location):b.reject(c)}),b}function K(a,b){X(a.split(" "),b)}function X(a,b){(al(a)?a:[a]).forEach(b)}function ar(a){return Object.keys(a)}function av(a){return ar(a).map(function(b){return a[b]})}function ad(a,b){return a=ag(a),a.bounds&&(a.bounds=aj(a.bounds)),z(b(a))}function ac(b,d,a){var c=q();return b=ag(b),ah().then(function(){var f=b.address;return f?(delete b.address,W(f).then(function(g){b[d]=g})):void (b[d]=au(b[d]))}).then(function(){c.resolve(a(b))}).fail(function(e){c.reject(e)}),c}function at(b,c,a){return b=ag(b),b[c]=(b[c]||[]).map(au),z(a(b))}function au(a,b){return al(a)?new U.LatLng(a[0],a[1]):!b||!a||a instanceof U.LatLng?a:new U.LatLng(a.lat,a.lng)}function aj(a,b){return al(a)?new U.LatLngBounds({lat:a[2],lng:a[3]},{lat:a[0],lng:a[1]}):b&&!a.getCenter?new U.LatLngBounds({lat:a.south,lng:a.west},{lat:a.north,lng:a.east}):a}function G(d,b){function c(){function g(i){return f.getProjection().fromLatLngToDivPixel(i)}var f=this,h=[];a.call(f),f.setMap(d),f.onAdd=function(){var i=f.getPanes();i.overlayMouseTarget.appendChild(e[0])},b.position?(f.getPosition=function(){return b.position},f.setPosition=function(i){b.position=i,f.draw()},f.draw=function(){var i=g(b.position);e.css({left:i.x+b.x+"px",top:i.y+b.y+"px"})}):(f.getBounds=function(){return b.bounds},f.setBounds=function(i){b.bounds=i,f.draw()},f.draw=function(){var j=g(b.bounds.getSouthWest()),i=g(b.bounds.getNorthEast());e.css({left:j.x+b.x+"px",top:i.y+b.y+"px",width:i.x-j.x+b.x+"px",height:j.y-i.y+b.y+"px"})}),f.onRemove=function(){h.map(function(i){U.event.removeListener(i)}),e.remove(),f.$=e=null},f.$=e}var a=U.OverlayView,e=af(Q.createElement("div")).css({border:"none",borderWidth:0,position:"absolute"}).append(b.content);return b=an({x:0,y:0},b),b.position?b.position=au(b.position,!0):b.bounds&&(b.bounds=aj(b.bounds,!0)),c.prototype=new a,new c}function ae(b){function c(){var d=this;return d.onAdd=d.onRemove=d.draw=function(){},U.OverlayView.call(d)}c.prototype=new U.OverlayView;var a=new c;return a.setMap(b),a.getProjection()}function H(b,f,a,c){var d=this;d.cluster=b,d.markers=f,d.$=a.$,d.overlay=a,a.getBounds=function(){return ab("LatLngBounds",c.getSouthWest(),c.getNorthEast())}}function J(A,M){function j(){var a=ab("Circle",{center:A.getCenter(),radius:1.15*I(A.getCenter(),A.getBounds().getNorthEast())});return a.getBounds()}function r(a){var d=h.fromLatLngToDivPixel(a);return ab("LatLngBounds",h.fromDivPixelToLatLng(ab("Point",d.x-D,d.y+D)),h.fromDivPixelToLatLng(ab("Point",d.x+D,d.y-D)))}function R(){var w,e,g,t,k,m,i=A.getZoom(),L={},C=[],n={};m=""+i,i>3&&(e=j(),X(S,function(a,d){e.contains(a.getPosition())||(m+="-"+d,n[d]=!0,a.getMap()&&a.setMap(null))})),y&&X(S,function(a,d){n[d]||y(a)||(m+="-"+d,n[d]=!0,a.getMap()&&a.setMap(null))}),m!==o&&(o=m,X(S,function(a,d){n[d]||(w=[d],e=r(a.getPosition()),c&&X(ak(S,d+1),function(f,p){p+=d+1,!n[p]&&e.contains(f.getPosition())&&(w.push(p),n[p]=!0)}),t=w.join("-"),L[t]=!0,O[t]||(k=w.map(function(f){return S[f]}),g=M.cb(ak(k)),g?(e=ab("LatLngBounds"),X(k,function(f){e.extend(f.getPosition()),f.getMap()&&f.setMap(null)}),g=ag(g),g.position=e.getCenter(),O[t]=new H(x,ak(k),G(A,g),e),C.push(O[t])):X(k,function(f){f.getMap()||f.setMap(A)})))}),X(ar(O),function(a){L[a]||(O[a].overlay.setMap(null),delete O[a])}),C.length&&X(v,function(a){a(C)}))}function b(){clearTimeout(l),l=setTimeout(R,100)}function E(){U.event.addListener(A,"zoom_changed",b),U.event.addListener(A,"bounds_changed",b),R()}var l,B,o,h,y,x=this,S=[],D=(M.size||200)>>1,c=!0,O={},v=[];M=M||{},M.markers=M.markers||[],x._b=function(a){a(av(O)),v.push(a)},x.markers=function(){return ak(S)},x.groups=function(){return av(O)},x.enable=function(){c||(c=!0,o="",b())},x.disable=function(){c&&(c=!1,o="",b())},x.add=function(a){S.push(a),o="",b()},x.remove=function(a){S=S.filter(function(d){return d!==a}),o="",b()},x.filter=function(a){y!==a&&(y=a,o="",b())},M.markers.map(function(a){a.position=au(a.position),S.push(ab("Marker",a))}),B=setInterval(function(){h=ae(A),h&&(clearInterval(B),E())},10)}function ap(b,c){var a=this;ar(c[0]).forEach(function(d){a[d]=function(){var f=[],e=ak(arguments);return c.forEach(function(g){f.push(g[d].apply(g,e))}),"get"===d?f.length>1?f:f[0]:a}}),a.$=b}function aa(l,b){function a(){return{$:l,get:i.get}}function k(p,c,g,f){var r=arguments.length>3;r||(f=g),af.each(p,function(e,o){X(c,function(u){var t=u instanceof H,w=t||u instanceof U.OverlayView,v=w?u.$.get(0):u;U.event["add"+(w?"Dom":"")+"Listener"+(f?"Once":"")](v,e,function(s){X(o,function(y){if(F(y)){if(t){y.call(a(),void 0,u,u.cluster,s)}else{if(r){var x=ak(g);x.unshift(u),x.push(s),y.apply(a(),x)}else{y.call(a(),u,s)}}}})})})})}function d(c){return function(p){if(al(p)){var f=[],g=p.map(function(e){return c.call(i,e).then(function(o){f.push(o)})});return aq(g).then(function(){return n.push(f),f})}return c.apply(i,arguments).then(function(e){return n.push(e),e})}}function h(c){return function(){var e=ak(arguments);return j=j.then(function(f){return F(e[0])?ah(e[0].call(a(),f)).then(function(g){return e[0]=g,c.apply(i,e)}):ah(c.apply(i,e))})}}var m,n=[],j=ah(),i=this;i.map=h(function(c){return m||ac(c,"center",function(e){return m=ab("Map",l.get(0),e),n.push(m),m})}),K("Marker:position Circle:center InfoWindow:position:0 Polyline:path Polygon:paths",function(c){c=c.split(":");var e=c[1]||"";i[c[0].toLowerCase()]=h(d(function(f){return(e.match(/^path/)?at:ac)(f,e,function(g){return"0"!==c[2]&&(g.map=m),ab(c[0],g)})}))}),K("TrafficLayer TransitLayer BicyclingLayer",function(c){i[c.toLowerCase()]=h(function(){var e=ab(c);return n.push(e),e.setMap(m),e})}),i.kmllayer=h(d(function(c){return c=ag(c),c.map=m,ah(ab("KmlLayer",c))})),i.rectangle=h(d(function(c){return ad(c,function(e){return e.map=m,ab("Rectangle",e)})})),i.overlay=h(d(function(c){function e(f){return G(m,f)}return c=ag(c),c.bounds?ad(c,e):ac(c,"position",e)})),i.groundoverlay=h(function(f,g,c){return ad({bounds:g},function(o){c=ag(c),c.map=m;var e=ab("GroundOverlay",f,o.bounds,c);return n.push(e),e})}),i.styledmaptype=h(function(f,p,c){var g=ab("StyledMapType",p,c);return n.push(g),m.mapTypes.set(f,g),g}),i.streetviewpanorama=h(function(f,c){return ac(c,"position",function(g){var p=ab("StreetViewPanorama",af(f).get(0),g);return m.setStreetView(p),n.push(p),p})}),i.route=h(function(c){var e=q();return c=ag(c),c.origin=au(c.origin),c.destination=au(c.destination),ai("DirectionsService").route(c,function(g,f){n.push(g),e.resolve(f===U.DirectionsStatus.OK?g:!1)}),e}),i.cluster=h(function(c){var e=new J(m,ag(c));return n.push(e),z(e)}),i.directionsrenderer=h(function(f){var c;return f&&(f=ag(f),f.map=m,f.panel&&(f.panel=af(f.panel).get(0)),c=ab("DirectionsRenderer",f)),n.push(c),c}),i.latlng=h(d(function(c){return ac(c,"latlng",function(e){return n.push(e.latlng),e.latlng})})),i.fit=h(function(){var c=ab("LatLngBounds");return X(n,function(e){e!==m&&X(e,function(f){f&&(f.getPosition&&f.getPosition()?c.extend(f.getPosition()):f.getBounds&&f.getBounds()?(c.extend(f.getBounds().getNorthEast()),c.extend(f.getBounds().getSouthWest())):f.getPaths&&f.getPaths()?X(f.getPaths().getArray(),function(g){X(g.getArray(),function(o){c.extend(o)})}):f.getPath&&f.getPath()?X(f.getPath().getArray(),function(g){c.extend(g)}):f.getCenter&&f.getCenter()&&c.extend(f.getCenter()))})}),c.isEmpty()||m.fitBounds(c),!0}),i.wait=function(c){j=j.then(function(g){var f=q();return setTimeout(function(){f.resolve(g)},c),f})},i.then=function(c){F(c)&&(j=j.then(function(e){return ah(c.call(a(),e)).then(function(f){return Y(f)?e:f})}))},i["catch"]=function(c){F(c)&&(j=j.then(null,function(e){return ah(c.call(a(),e))}))},K("on once",function(c,e){i[c]=function(){var f=arguments[0];f&&("string"==typeof f&&(f={},f[arguments[0]]=ak(arguments,1)),j.then(function(g){if(g){if(g instanceof J){return g._b(function(o){o&&o.length&&k(f,o,e)}),k(f,g.markers(),[void 0,g],e)}k(f,g,e)}}))}}),i.get=function(c){return Y(c)?n.map(function(e){return al(e)?e.slice():e}):(0>c&&(c=n.length+c),al(n[c])?n[c].slice():n[c])},b&&i.map(b)}var U,Z,N={},ah=af.when,an=af.extend,al=af.isArray,F=af.isFunction,q=af.Deferred;ah(function(){var b,c=q(),a="__gmap3";return af.holdReady(!0),am(function(){ao.google&&ao.google.maps||Z===!1?c.resolve():(ao[a]=function(){delete ao[a],c.resolve()},b=Q.createElement("script"),b.type="text/javascript",b.src="https://maps.googleapis.com/maps/api/js?callback="+a+(Z?"&"+("string"==typeof Z?Z:V(Z)):""),af("head").append(b))}),c}()).then(function(){af.holdReady(!1)}),af.gmap3=function(a){Z=a},af.fn.gmap3=function(a){var b=[];return U=ao.google.maps,this.each(function(){var d=af(this),c=d.data("gmap3");c||(c=new aa(d,a),d.data("gmap3",c)),b.push(c)}),new ap(this,b)}}(jQuery,window,document);