leaflet-rotate 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/test.js +18 -0
- package/dist/leaflet-rotate-src.js +261 -216
- package/dist/leaflet-rotate-src.js.map +3 -3
- package/dist/leaflet-rotate.js +1 -1
- package/dist/leaflet-rotate.js.map +3 -3
- package/lib/debug.js +84 -66
- package/lib/debug.min.js +1 -1
- package/misc/leaflet-heat-rotate.js +7 -7
- package/misc/loremIpsum.js +1 -1
- package/misc/places.js +1 -1
- package/misc/route.js +1 -1
- package/package.json +5 -5
- package/src/control/Rotate.js +20 -24
- package/src/dom/DomUtil.js +31 -47
- package/src/dom/Draggable.js +1 -1
- package/src/geometry/Point.js +16 -7
- package/src/layer/DivOverlay.js +10 -8
- package/src/layer/Popup.js +15 -13
- package/src/layer/Tooltip.js +5 -5
- package/src/layer/marker/Icon.js +8 -8
- package/src/layer/marker/Marker.js +18 -18
- package/src/layer/tile/GridLayer.js +4 -4
- package/src/layer/vector/Renderer.js +47 -7
- package/src/map/Map.js +71 -66
- package/src/map/handler/CompassBearing.js +6 -6
- package/src/map/handler/ContainerMutation.js +2 -2
- package/src/map/handler/ShiftKeyRotate.js +4 -4
- package/src/map/handler/TouchGestures.js +29 -23
- package/src/map/handler/TouchRotate.js +2 -2
- package/src/map/handler/TouchZoom.js +4 -4
- package/test/features/example.feature +5 -0
- package/test/index.html +59 -22
- package/test/steps/bearing.steps.js +3 -3
- package/test/steps/example.steps.js +72 -11
- package/test/steps/gestures.steps.js +4 -4
- package/test/steps/overlays.steps.js +32 -32
- package/test/support/hooks.js +50 -2
package/dist/leaflet-rotate.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var leafletRotate=(()=>{var c=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var D=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of M(e))!T.call(t,n)&&n!==i&&c(t,n,{get:()=>e[n],enumerable:!(o=b(e,n))||o.enumerable});return t};var B=t=>D(c({},"__esModule",{value:!0}),t);var z={};var g=L.extend({},L.DomUtil);L.extend(L.DomUtil,{setTransform:function(t,e,i,o,n){var a=e||new L.Point(0,0);if(!o)return e=a._round(),g.setTransform.apply(this,arguments);a=a.rotateFrom(o,n),t.style[L.DomUtil.TRANSFORM]="translate3d("+a.x+"px,"+a.y+"px,0)"+(i?" scale("+i+")":"")+" rotate("+o+"rad)"},setPosition:function(t,e,i,o,n){if(!i)return g.setPosition.apply(this,arguments);t._leaflet_pos=e,L.Browser.any3d?L.DomUtil.setTransform(t,e,n,i,o):(t.style.left=e.x+"px",t.style.top=e.y+"px")},DEG_TO_RAD:Math.PI/180,RAD_TO_DEG:180/Math.PI});L.Draggable.include({});L.extend(L.Point.prototype,{rotate:function(t){return this.rotateFrom(t,new L.Point(0,0))},rotateFrom:function(t,e){if(!t)return this;var i=Math.sin(t),o=Math.cos(t),n=e.x,a=e.y,s=this.x-n,h=this.y-a;return new L.Point(s*o-h*i+n,s*i+h*o+a)}});var f=L.extend({},L.DivOverlay.prototype);L.DivOverlay.include({getEvents:function(){return L.extend(f.getEvents.apply(this,arguments),{rotate:this._updatePosition})},_updatePosition:function(){if(this._map){if(f._updatePosition.apply(this,arguments),this._map._rotate&&this._zoomAnimated){var t=this._getAnchor(),e=L.DomUtil.getPosition(this._container).subtract(t);L.DomUtil.setPosition(this._container,this._map.rotatedPointToMapPanePoint(e).add(t))}else if(this._map._rotate){var i=this._map.rotatedPointToMapPanePoint(this._map.latLngToLayerPoint(this._latlng)),o=L.point(this.options.offset),t=this._getAnchor();this._containerLeft=-Math.round(this._containerWidth/2)+i.x+o.x+t.x,this._containerBottom=-(i.y+o.y+t.y),this._container.style.left=this._containerLeft+"px",this._container.style.bottom=this._containerBottom+"px",this._container.style.top="",L.DomUtil.setPosition(this._container,new L.Point(0,0)),this._container.style.transform=""}}}});var w=L.extend({},L.Popup.prototype);L.Popup.include({_animateZoom:function(t){if(w._animateZoom.apply(this,arguments),this._map&&this._map._rotate){var e=this._getAnchor(),i=L.DomUtil.getPosition(this._container).subtract(e);L.DomUtil.setPosition(this._container,this._map.rotatedPointToMapPanePoint(i).add(e))}},_adjustPan:function(){if(!(!this.options.autoPan||this._map._panAnim&&this._map._panAnim._inProgress)){if(this._autopanning){this._autopanning=!1;return}var t=this._map,e=parseInt(L.DomUtil.getStyle(this._container,"marginBottom"),10)||0,i=this._container.offsetHeight+e,o=this._containerWidth,n=new L.Point(this._containerLeft,-i-this._containerBottom);n._add(L.DomUtil.getPosition(this._container));var a=n._add(this._map._getMapPanePos()),s=L.point(this.options.autoPanPadding),h=L.point(this.options.autoPanPaddingTopLeft||s),r=L.point(this.options.autoPanPaddingBottomRight||s),l=t.getSize(),m=0,d=0;a.x+o+r.x>l.x&&(m=a.x+o-l.x+r.x),a.x-m-h.x<0&&(m=a.x-h.x),a.y+i+r.y>l.y&&(d=a.y+i-l.y+r.y),a.y-d-h.y<0&&(d=a.y-h.y),(m||d)&&(this.options.keepInView&&(this._autopanning=!0),t.fire("autopanstart").panBy([m,d]))}}});var P=L.extend({},L.Tooltip.prototype);L.Tooltip.include({_animateZoom:function(t){if(!this._map._rotate)return P._animateZoom.apply(this,arguments);var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center);e=this._map.rotatedPointToMapPanePoint(e),this._setPosition(e)},_updatePosition:function(){if(!this._map._rotate)return P._updatePosition.apply(this,arguments);var t=this._map.latLngToLayerPoint(this._latlng);t=this._map.rotatedPointToMapPanePoint(t),this._setPosition(t)}});var k=L.extend({},L.Icon.prototype);L.Icon.include({_setIconStyles:function(t,e){var i=this.options,o=i[e+"Size"];typeof o=="number"&&(o=[o,o]);var n=L.point(o),a=L.point(e==="shadow"&&i.shadowAnchor||i.iconAnchor||n&&n.divideBy(2,!0));t.className="leaflet-marker-"+e+" "+(i.className||""),a&&(t.style.marginLeft=-a.x+"px",t.style.marginTop=-a.y+"px",t.style[L.DomUtil.TRANSFORM+"Origin"]=a.x+"px "+a.y+"px 0px"),n&&(t.style.width=n.x+"px",t.style.height=n.y+"px")}});var y=L.extend({},L.Marker.prototype);L.Marker.mergeOptions({rotation:0,rotateWithView:!1,keepUpright:!1,scale:void 0});var u,v={_onDrag:function(t){var e=this._marker,i=e.options.rotation||e.options.rotateWithView,o=e._shadow,n=L.DomUtil.getPosition(e._icon);!i&&o&&L.DomUtil.setPosition(o,n),e._map._rotate&&(n=e._map.mapPanePointToRotatedPoint(n));var a=e._map.layerPointToLatLng(n);e._latlng=a,t.latlng=a,t.oldLatLng=this._oldLatLng,i?e.setLatLng(a):e.fire("move",t),e.fire("drag",t)},_onDragEnd:function(t){this._marker._map._rotate&&this._marker.update(),u._onDragEnd.apply(this,arguments)}};L.Marker.include({getEvents:function(){return L.extend(y.getEvents.apply(this,arguments),{rotate:this.update})},_initInteraction:function(){var t=y._initInteraction.apply(this,arguments);return this.dragging&&this.dragging.enabled()&&this._map&&this._map._rotate&&(u=u||Object.getPrototypeOf(this.dragging),this.dragging.disable(),Object.assign(this.dragging,{_onDrag:v._onDrag.bind(this.dragging),_onDragEnd:v._onDragEnd.bind(this.dragging)}),this.dragging.enable()),t},_setPos:function(t){this._map._rotate&&(t=this._map.rotatedPointToMapPanePoint(t));var e=this.options.rotation||0;this.options.rotateWithView&&(e+=this._map._bearing),this.options.keepUpright&&(e=(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),e>Math.PI/2&&e<3*Math.PI/2&&(e+=Math.PI),e%=2*Math.PI),this._icon&&L.DomUtil.setPosition(this._icon,t,e,t,this.options.scale),this._shadow&&L.DomUtil.setPosition(this._shadow,t,e,t,this.options.scale),this._zIndex=t.y+this.options.zIndexOffset,this._resetZIndex()},setRotation:function(t){this.options.rotation=t,this.update()}});var x=L.extend({},L.GridLayer.prototype);L.GridLayer.include({getEvents:function(){var t=x.getEvents.apply(this,arguments);return this._map._rotate&&!this.options.updateWhenIdle&&(this._onRotate||(this._onRotate=L.Util.throttle(this._onMoveEnd,this.options.updateInterval,this)),t.rotate=this._onRotate),t},_getTiledPixelBounds:function(t){return this._map._rotate?this._map._getNewPixelBounds(t,this._tileZoom):x._getTiledPixelBounds.apply(this,arguments)}});var p=L.extend({},L.Renderer.prototype);L.Renderer.include({getEvents:function(){return L.extend(p.getEvents.apply(this,arguments),{rotate:this._update})},onAdd:function(){p.onAdd.apply(this,arguments),L.version<="1.9.3"&&this._container.classList.add("leaflet-zoom-animated")},_updateTransform:function(t,e){if(!this._map._rotate)return p._updateTransform.apply(this,arguments);if(e!==this._zoom){var i=this._map.getZoomScale(e,this._zoom),o=this._map._latLngToNewLayerPoint(this._topLeft,e,t);L.DomUtil.setTransform(this._container,o,i)}},_update:function(){if(!this._map._rotate)return p._update.apply(this,arguments);this._bounds=this._map._getPaddedPixelBounds(this.options.padding),this._topLeft=this._map.layerPointToLatLng(this._bounds.min),this._center=this._map.getCenter(),this._zoom=this._map.getZoom()}});var _=L.extend({},L.Map.prototype);L.Map.mergeOptions({rotate:!1,bearing:0});L.Map.include({_animateZoomNoDelay:function(t,e){this._mapPane&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=e,this._move(t,e,void 0,!0),this._onZoomTransitionEnd())},initialize:function(t,e){e.rotate&&(this._rotate=!0,this._bearing=0),_.initialize.apply(this,arguments),this.options.rotate&&this.setBearing(this.options.bearing)},containerPointToLayerPoint:function(t){return this._rotate?L.point(t).subtract(this._getMapPanePos()).rotateFrom(-this._bearing,this._getRotatePanePos()).subtract(this._getRotatePanePos()):_.containerPointToLayerPoint.apply(this,arguments)},layerPointToContainerPoint:function(t){return this._rotate?L.point(t).add(this._getRotatePanePos()).rotateFrom(this._bearing,this._getRotatePanePos()).add(this._getMapPanePos()):_.layerPointToContainerPoint.apply(this,arguments)},rotatedPointToMapPanePoint:function(t){return L.point(t).rotate(this._bearing)._add(this._getRotatePanePos())},mapPanePointToRotatedPoint:function(t){return L.point(t)._subtract(this._getRotatePanePos()).rotate(-this._bearing)},mapBoundsToContainerBounds:function(t){if(!this._rotate&&_.mapBoundsToContainerBounds)return _.mapBoundsToContainerBounds.apply(this,arguments);let e=this.getPixelOrigin(),i=this.layerPointToContainerPoint(this.project(t.getNorthWest())._subtract(e)),o=this.layerPointToContainerPoint(this.project(t.getNorthEast())._subtract(e)),n=this.layerPointToContainerPoint(this.project(t.getSouthWest())._subtract(e)),a=this.layerPointToContainerPoint(this.project(t.getSouthEast())._subtract(e));return L.bounds([L.point(Math.min(i.x,o.x,a.x,n.x),Math.min(i.y,o.y,a.y,n.y)),L.point(Math.max(i.x,o.x,a.x,n.x),Math.max(i.y,o.y,a.y,n.y))])},getBounds:function(){if(!this._rotate)return _.getBounds.apply(this,arguments);var t=this.getSize();return new L.LatLngBounds([this.containerPointToLatLng([0,0]),this.containerPointToLatLng([t.x,0]),this.containerPointToLatLng([t.x,t.y]),this.containerPointToLatLng([0,t.y])])},setBearing:function(t,e){if(!(!L.Browser.any3d||!this._rotate)){if(e&&e.animate){this._bearingAnimationId=(this._bearingAnimationId||0)+1;var i=this._bearingAnimationId;this._bearingAnimationFrame&&L.Util.cancelAnimFrame(this._bearingAnimationFrame);var o=this.getBearing(),n=L.Util.wrapNum(t,[0,360]),a=(n-o+540)%360-180,s=Math.max(0,e.duration==null?.25:e.duration)*1e3,h=Math.max(e.easeLinearity||.5,.2),r=performance.now(),l=function(){if(!this._mapPane){delete this._bearingAnimationFrame;return}var m=s?Math.min((performance.now()-r)/s,1):1,d=1-Math.pow(1-m,1/h);this._setBearing(m===1?n:o+a*d),this._bearingAnimationId===i&&(m<1?this._bearingAnimationFrame=L.Util.requestAnimFrame(l,this):delete this._bearingAnimationFrame)};this._bearingAnimationFrame=L.Util.requestAnimFrame(l,this);return}this._bearingAnimationId=(this._bearingAnimationId||0)+1,this._bearingAnimationFrame&&(L.Util.cancelAnimFrame(this._bearingAnimationFrame),delete this._bearingAnimationFrame),this._setBearing(t)}},_setBearing:function(t){var e=L.Util.wrapNum(t,[0,360])*L.DomUtil.DEG_TO_RAD,i=this._getPixelCenter(),o=this._getRotatePanePos().rotateFrom(-this._bearing,i),n=o.rotateFrom(e,i);L.DomUtil.setPosition(this._rotatePane,o,e,i),this._pivot=i,this._bearing=e,this._rotatePanePos=n,this.fire("rotate")},getBearing:function(){return this._bearing*L.DomUtil.RAD_TO_DEG},_initPanes:function(){var t=this._panes={};this._paneRenderers={},this._mapPane=this.createPane("mapPane",this._container),L.DomUtil.setPosition(this._mapPane,new L.Point(0,0)),this._rotate?(this._rotatePane=this.createPane("rotatePane",this._mapPane),this._norotatePane=this.createPane("norotatePane",this._mapPane),this.createPane("tilePane",this._rotatePane),this.createPane("overlayPane",this._rotatePane),this.createPane("shadowPane",this._norotatePane),this.createPane("markerPane",this._norotatePane),this.createPane("tooltipPane",this._norotatePane),this.createPane("popupPane",this._norotatePane)):(this.createPane("tilePane"),this.createPane("overlayPane"),this.createPane("shadowPane"),this.createPane("markerPane"),this.createPane("tooltipPane"),this.createPane("popupPane")),this.options.markerZoomAnimation||(L.DomUtil.addClass(t.markerPane,"leaflet-zoom-hide"),L.DomUtil.addClass(t.shadowPane,"leaflet-zoom-hide"))},panInside(t,e){if(!this._rotate||Math.abs(this._bearing).toFixed(1)<.1)return _.panInside.apply(this,arguments);e=e||{};let i=L.point(e.paddingTopLeft||e.padding||[0,0]),o=L.point(e.paddingBottomRight||e.padding||[0,0]),n=this.latLngToContainerPoint(t),a=L.bounds([L.point(0,0),this.getSize()]),s=a.getCenter(),h=L.bounds([a.min.add(i),a.max.subtract(o)]),r=h.getSize();if(!h.contains(n)){this._enforcingBounds=!0;let l=n.subtract(h.getCenter()),m=h.extend(n).getSize().subtract(r);s.x+=l.x<0?-m.x:m.x,s.y+=l.y<0?-m.y:m.y,this.panTo(this.containerPointToLatLng(s),e),this._enforcingBounds=!1}return this},getBoundsZoom(t,e,i){if(!this._rotate||Math.abs(this._bearing).toFixed(1)<.1)return _.getBoundsZoom.apply(this,arguments);t=L.latLngBounds(t),i=L.point(i||[0,0]);let o=this.getZoom()||0,n=this.getMinZoom(),a=this.getMaxZoom(),s=this.getSize().subtract(i),h=this.mapBoundsToContainerBounds(t).getSize(),r=this.options.zoomSnap,l=s.x/h.x,m=s.y/h.y,d=e?Math.max(l,m):Math.min(l,m);return o=this.getScaleZoom(d,o),r&&(o=Math.round(o/(r/100))*(r/100),o=e?Math.ceil(o/r)*r:Math.floor(o/r)*r),Math.max(n,Math.min(a,o))},_getCenterOffset:function(t){var e=_._getCenterOffset.apply(this,arguments);return this._rotate&&(e=e.rotate(this._bearing)),e},_getRotatePanePos:function(){return this._rotatePanePos||new L.Point(0,0)},_getNewPixelOrigin:function(t,e){if(!this._rotate)return _._getNewPixelOrigin.apply(this,arguments);var i=this.getSize()._divideBy(2);return this.project(t,e).rotate(this._bearing)._subtract(i)._add(this._getMapPanePos())._add(this._getRotatePanePos()).rotate(-this._bearing)._round()},_getNewPixelBounds:function(t,e){if(t=t||this.getCenter(),e=e||this.getZoom(),!this._rotate&&_._getNewPixelBounds)return _._getNewPixelBounds.apply(this,arguments);var i=this._animatingZoom?Math.max(this._animateToZoom,this.getZoom()):this.getZoom(),o=this.getZoomScale(i,e),n=this.project(t,e).floor(),a=this.getSize(),s=new L.Bounds([this.containerPointToLayerPoint([0,0]).floor(),this.containerPointToLayerPoint([a.x,0]).floor(),this.containerPointToLayerPoint([0,a.y]).floor(),this.containerPointToLayerPoint([a.x,a.y]).floor()]).getSize().divideBy(o*2);return new L.Bounds(n.subtract(s),n.add(s))},_getPixelCenter:function(){return!this._rotate&&_._getPixelCenter?_._getPixelCenter.apply(this,arguments):this.getSize()._divideBy(2)._subtract(this._getMapPanePos())},_getPaddedPixelBounds:function(t){if(!this._rotate&&_._getPaddedPixelBounds)return _._getPaddedPixelBounds.apply(this,arguments);var e=t,i=this.getSize(),o=i.multiplyBy(-e),n=i.multiplyBy(1+e);return new L.Bounds([this.containerPointToLayerPoint([o.x,o.y]).floor(),this.containerPointToLayerPoint([o.x,n.y]).floor(),this.containerPointToLayerPoint([n.x,o.y]).floor(),this.containerPointToLayerPoint([n.x,n.y]).floor()])},_handleGeolocationResponse:function(t){if(this._container._leaflet_id){var e=t.coords.latitude,i=t.coords.longitude,o=t.coords.heading,n=new L.LatLng(e,i),a=n.toBounds(t.coords.accuracy),s=this._locateOptions;if(s.setView){var h=this.getBoundsZoom(a);this.setView(n,s.maxZoom?Math.min(h,s.maxZoom):h)}var r={latlng:n,bounds:a,timestamp:t.timestamp,heading:o};for(var l in t.coords)typeof t.coords[l]=="number"&&(r[l]=t.coords[l]);this.fire("locationfound",r)}}});L.Map.CompassBearing=L.Handler.extend({initialize:function(t){this._map=t,"ondeviceorientationabsolute"in window?this.__deviceOrientationEvent="deviceorientationabsolute":"ondeviceorientation"in window&&(this.__deviceOrientationEvent="deviceorientation"),this._throttled=L.Util.throttle(this._onDeviceOrientation,100,this)},addHooks:function(){this._map._rotate&&this.__deviceOrientationEvent?L.DomEvent.on(window,this.__deviceOrientationEvent,this._throttled,this):this.disable()},removeHooks:function(){this._map._rotate&&this.__deviceOrientationEvent&&L.DomEvent.off(window,this.__deviceOrientationEvent,this._throttled,this)},_onDeviceOrientation:function(t){var e=t.webkitCompassHeading!=null?t.webkitCompassHeading:t.alpha,i=0;Number.isFinite(e)&&(!t.absolute&&t.webkitCompassHeading&&(e=360-e),!t.absolute&&typeof window.orientation<"u"&&(i=window.orientation),this._map.setBearing(e-i))}});L.Map.addInitHook("addHandler","compassBearing",L.Map.CompassBearing);L.Map.mergeOptions({trackContainerMutation:!1});L.Map.ContainerMutation=L.Handler.extend({addHooks:function(){this._observer||(this._observer=new MutationObserver(L.Util.bind(this._map.invalidateSize,this._map))),this._observer.observe(this._map.getContainer(),{childList:!1,attributes:!0,characterData:!1,subtree:!1,attributeFilter:["style"]})},removeHooks:function(){this._observer.disconnect()}});L.Map.addInitHook("addHandler","trackContainerMutation",L.Map.ContainerMutation);L.Map.mergeOptions({bounceAtZoomLimits:!0});L.Map.TouchGestures=L.Handler.extend({initialize:function(t){this._map=t,this.rotate=!!this._map.options.touchRotate,this.zoom=!!this._map.options.touchZoom},addHooks:function(){L.DomEvent.on(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){L.DomEvent.off(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(t){var e=this._map;if(!(!t.touches||t.touches.length!==2||e._animatingZoom||this._zooming||this._rotating)){var i=e.mouseEventToContainerPoint(t.touches[0]),o=e.mouseEventToContainerPoint(t.touches[1]),n=i.subtract(o);this._centerPoint=e.getSize()._divideBy(2),this._startLatLng=e.containerPointToLatLng(this._centerPoint),this.zoom?(e.options.touchZoom!=="center"&&(this._pinchStartLatLng=e.containerPointToLatLng(i.add(o)._divideBy(2))),this._startDist=i.distanceTo(o),this._startZoom=e.getZoom(),this._zooming=!0):this._zooming=!1,this.rotate?(this._startTheta=Math.atan(n.x/n.y),this._startBearing=e.getBearing(),n.y<0&&(this._startBearing+=180),this._rotating=!0):this._rotating=!1,this._moved=!1,e._stop(),L.DomEvent.on(document,"touchmove",this._onTouchMove,this).on(document,"touchend touchcancel",this._onTouchEnd,this),L.DomEvent.preventDefault(t)}},_onTouchMove:function(t){if(!(!t.touches||t.touches.length!==2||!(this._zooming||this._rotating))){var e=this._map,i=e.mouseEventToContainerPoint(t.touches[0]),o=e.mouseEventToContainerPoint(t.touches[1]),n=i.subtract(o),a=i.distanceTo(o)/this._startDist,s;if(this._rotating){var h=Math.atan(n.x/n.y),r=(h-this._startTheta)*L.DomUtil.RAD_TO_DEG;n.y<0&&(r+=180),r&&e.setBearing(this._startBearing-r)}if(this._zooming)if(this._zoom=e.getScaleZoom(a,this._startZoom),!e.options.bounceAtZoomLimits&&(this._zoom<e.getMinZoom()&&a<1||this._zoom>e.getMaxZoom()&&a>1)&&(this._zoom=e._limitZoom(this._zoom)),e.options.touchZoom==="center"){if(this._center=this._startLatLng,a===1)return}else{if(s=i._add(o)._divideBy(2)._subtract(this._centerPoint),a===1&&s.x===0&&s.y===0)return;var l=-e.getBearing()*L.DomUtil.DEG_TO_RAD;this._center=e.unproject(e.project(this._pinchStartLatLng).subtract(s.rotate(l)))}this._moved||(e._moveStart(!0,!1),this._moved=!0),L.Util.cancelAnimFrame(this._animRequest);var m=e._move.bind(e,this._center,this._zoom,{pinch:!0,round:!1},void 0);this._animRequest=L.Util.requestAnimFrame(m,this,!0),this.zoom&&(e.options.zoomAnimation?e._animateZoomNoDelay(this._center,e._limitZoom(this._zoom)):e._resetView(this._center,e._limitZoom(this._zoom))),L.DomEvent.preventDefault(t)}},_onTouchEnd:function(){if(!this._moved||!(this._zooming||this._rotating)){this._zooming=!1;return}this._zooming=!1,this._rotating=!1,L.Util.cancelAnimFrame(this._animRequest),L.DomEvent.off(document,"touchmove",this._onTouchMove,this).off(document,"touchend touchcancel",this._onTouchEnd,this),this.zoom&&(this._map.options.zoomAnimation?this._map._animateZoom(this._center,this._map._limitZoom(this._zoom),!0,this._map.options.zoomSnap):this._map._resetView(this._center,this._map._limitZoom(this._zoom)))}});L.Map.addInitHook("addHandler","touchGestures",L.Map.TouchGestures);L.Map.mergeOptions({touchRotate:!1});L.Map.TouchRotate=L.Handler.extend({addHooks:function(){this._map.touchGestures.enable(),this._map.touchGestures.rotate=!0},removeHooks:function(){this._map.touchGestures.rotate=!1}});L.Map.addInitHook("addHandler","touchRotate",L.Map.TouchRotate);L.Map.mergeOptions({shiftKeyRotate:!0});L.Map.ShiftKeyRotate=L.Handler.extend({addHooks:function(){L.DomEvent.on(this._map._container,"wheel",this._handleShiftScroll,this),this._map.shiftKeyRotate.rotate=!0},removeHooks:function(){L.DomEvent.off(this._map._container,"wheel",this._handleShiftScroll,this),this._map.shiftKeyRotate.rotate=!1},_handleShiftScroll:function(t){t.shiftKey?(t.preventDefault(),this._map.scrollWheelZoom.disable(),this._map.setBearing(this._map._bearing*L.DomUtil.RAD_TO_DEG+Math.sign(t.deltaY)*5)):this._map.scrollWheelZoom.enable()}});L.Map.addInitHook("addHandler","shiftKeyRotate",L.Map.ShiftKeyRotate);L.Map.addInitHook(function(){this.scrollWheelZoom.enabled()&&this.shiftKeyRotate.enabled()&&(this.scrollWheelZoom.disable(),this.scrollWheelZoom.enable())});L.Map.mergeOptions({touchZoom:L.Browser.touch,bounceAtZoomLimits:!1});L.Map.TouchZoom=L.Handler.extend({addHooks:function(){L.DomUtil.addClass(this._map._container,"leaflet-touch-zoom"),this._map.touchGestures.enable(),this._map.touchGestures.zoom=!0},removeHooks:function(){L.DomUtil.removeClass(this._map._container,"leaflet-touch-zoom"),this._map.touchGestures.zoom=!1}});L.Map.addInitHook("addHandler","touchZoom",L.Map.TouchZoom);L.Control.Rotate=L.Control.extend({options:{position:"topleft",closeOnZeroBearing:!0},onAdd:function(t){var e=this._container=L.DomUtil.create("div","leaflet-control-rotate leaflet-bar"),i=this._arrow=L.DomUtil.create("span","leaflet-control-rotate-arrow");i.style.backgroundImage=`url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0 0 29 29' xmlns='http://www.w3.org/2000/svg' fill='%23333'%3E%3Cpath d='M10.5 14l4-8 4 8h-8z'/%3E%3Cpath d='M10.5 16l4 8 4-8h-8z' fill='%23ccc'/%3E%3C/svg%3E")`,i.style.cursor="grab",i.style.display="block",i.style.width="100%",i.style.height="100%",i.style.backgroundRepeat="no-repeat",i.style.backgroundPosition="50%";var o=this._link=L.DomUtil.create("a","leaflet-control-rotate-toggle",e);return o.appendChild(i),o.href="#",o.title="Rotate map",L.DomEvent.on(o,"dblclick",L.DomEvent.stopPropagation).on(o,"mousedown",this._handleMouseDown,this).on(o,"click",L.DomEvent.stop).on(o,"click",this._cycleState,this).on(o,"click",this._refocusOnMap,this),L.Browser.any3d||L.DomUtil.addClass(o,"leaflet-disabled"),this._restyle(),t.on("rotate",this._restyle,this),this._follow=!1,this._canFollow=!1,this.options.closeOnZeroBearing&&t.getBearing()===0&&(e.style.display="none"),e},onRemove:function(t){t.off("rotate",this._restyle,this)},_handleMouseDown:function(t){L.DomEvent.stop(t),this.dragging=!0,this.dragstartX=t.pageX,this.dragstartY=t.pageY,L.DomEvent.on(document,"mousemove",this._handleMouseDrag,this).on(document,"mouseup",this._handleMouseUp,this)},_handleMouseUp:function(t){L.DomEvent.stop(t),this.dragging=!1,L.DomEvent.off(document,"mousemove",this._handleMouseDrag,this).off(document,"mouseup",this._handleMouseUp,this)},_handleMouseDrag:function(t){if(this.dragging){var e=t.clientX-this.dragstartX;this._map.setBearing(e)}},_cycleState:function(t){if(this._map){var e=this._map;!e.touchRotate.enabled()&&!e.compassBearing.enabled()?e.touchRotate.enable():e.compassBearing.enabled()?(e.compassBearing.disable(),e.setBearing(0),this.options.closeOnZeroBearing&&e.touchRotate.enable()):(e.touchRotate.disable(),(DeviceOrientationEvent&&DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission():Promise.resolve("granted")).then(i=>i==="granted"&&e.compassBearing.enable())),this._restyle()}},_restyle:function(){if(!this._map.options.rotate)L.DomUtil.addClass(this._link,"leaflet-disabled");else{var t=this._map,e=t.getBearing();this._arrow.style.transform="rotate("+e+"deg)",e&&this.options.closeOnZeroBearing&&(this._container.style.display="block"),t.compassBearing.enabled()?this._link.style.backgroundColor="orange":t.touchRotate.enabled()?this._link.style.backgroundColor=null:(this._link.style.backgroundColor="grey",e===0&&this.options.closeOnZeroBearing&&(this._container.style.display="none"))}}});L.control.rotate=function(t){return new L.Control.Rotate(t)};L.Map.mergeOptions({rotateControl:!0});L.Map.addInitHook(function(){if(this.options.rotateControl){var t=typeof this.options.rotateControl=="object"?this.options.rotateControl:{};this.rotateControl=L.control.rotate(t),this.addControl(this.rotateControl)}});return B(z);})();
|
|
1
|
+
var leafletRotate=(()=>{var f=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var i in e)f(t,i,{get:e[i],enumerable:!0})},z=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of T(e))!O.call(t,n)&&n!==i&&f(t,n,{get:()=>e[n],enumerable:!(o=B(e,n))||o.enumerable});return t};var Z=t=>z(f({},"__esModule",{value:!0}),t);var E={};D(E,{toPoint:()=>p});var P=Object.assign({},L.DomUtil);Object.assign(L.DomUtil,{setTransform(t,e,i,o,n){let a=e||new L.Point(0,0);if(!o)return P.setTransform(t,a._round(),i);a=a.rotateFrom(o,n),t.style.transform="translate3d("+a.x+"px,"+a.y+"px,0)"+(i?" scale("+i+")":"")+" rotate("+o+"rad)"},setPosition(t,e,i,o,n){if(!i)return P.setPosition(t,e);t._leaflet_pos=e,L.DomUtil.setTransform(t,e,n,i,o)},getPosition(t){return t._leaflet_pos||P.getPosition(t)}});L.Draggable.include({});Object.assign(L.Point.prototype,{rotate(t){return this.rotateFrom(t,new L.Point(0,0))},rotateFrom(t,e){if(!t)return this;let i=Math.sin(t),o=Math.cos(t),n=e.x,a=e.y,s=this.x-n,h=this.y-a;return new L.Point(s*o-h*i+n,s*i+h*o+a)}});function p(t){return t==null||t instanceof L.Point?t:Array.isArray(t)?new L.Point(t[0],t[1]):new L.Point(t.x,t.y)}var b=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.DivOverlay.prototype));L.DivOverlay.include({getEvents(){return Object.assign(b.getEvents.apply(this,arguments),{rotate:this._updatePosition})},_updatePosition(){if(this._map){if(b._updatePosition.apply(this,arguments),this._map._rotate&&this._zoomAnimated){let t=this._getAnchor(),e=L.DomUtil.getPosition(this._container).subtract(t);L.DomUtil.setPosition(this._container,this._map.rotatedPointToMapPanePoint(e).add(t))}else if(this._map._rotate){let t=this._map.rotatedPointToMapPanePoint(this._map.latLngToLayerPoint(this._latlng)),e=p(this.options.offset||[0,0]),i=this._getAnchor();this._containerLeft=-Math.round(this._containerWidth/2)+t.x+e.x+i.x,this._containerBottom=-(t.y+e.y+i.y),this._container.style.left=this._containerLeft+"px",this._container.style.bottom=this._containerBottom+"px",this._container.style.top="",L.DomUtil.setPosition(this._container,new L.Point(0,0)),this._container.style.transform=""}}}});var k=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.Popup.prototype));L.Popup.include({_animateZoom(t){if(k._animateZoom.apply(this,arguments),this._map&&this._map._rotate){let e=this._getAnchor(),i=L.DomUtil.getPosition(this._container).subtract(e);L.DomUtil.setPosition(this._container,this._map.rotatedPointToMapPanePoint(i).add(e))}},_adjustPan(){if(!this.options.autoPan||this._map._panAnim&&this._map._panAnim._inProgress)return;if(this._autopanning){this._autopanning=!1;return}let t=this._map,e=parseInt(getComputedStyle(this._container).marginBottom,10)||0,i=this._container.offsetHeight+e,o=this._containerWidth,n=new L.Point(this._containerLeft,-i-this._containerBottom);n._add(L.DomUtil.getPosition(this._container));let a=n._add(this._map._getMapPanePos()),s=p(this.options.autoPanPadding||[0,0]),h=p(this.options.autoPanPaddingTopLeft||s),r=p(this.options.autoPanPaddingBottomRight||s),_=t.getSize(),l=0,d=0;a.x+o+r.x>_.x&&(l=a.x+o-_.x+r.x),a.x-l-h.x<0&&(l=a.x-h.x),a.y+i+r.y>_.y&&(d=a.y+i-_.y+r.y),a.y-d-h.y<0&&(d=a.y-h.y),(l||d)&&(this.options.keepInView&&(this._autopanning=!0),t.fire("autopanstart").panBy([l,d]))}});var x=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.Tooltip.prototype));L.Tooltip.include({_animateZoom(t){if(!this._map._rotate)return x._animateZoom.apply(this,arguments);let e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center);e=this._map.rotatedPointToMapPanePoint(e),this._setPosition(e)},_updatePosition(){if(!this._map._rotate)return x._updatePosition.apply(this,arguments);let t=this._map.latLngToLayerPoint(this._latlng);t=this._map.rotatedPointToMapPanePoint(t),this._setPosition(t)}});var H=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.Icon.prototype));L.Icon.include({_setIconStyles(t,e){let i=this.options,o=i[e+"Size"];typeof o=="number"&&(o=[o,o]);let n=o?new L.Point(...Array.isArray(o)?o:[o.x,o.y]):null,a=e==="shadow"&&i.shadowAnchor||i.iconAnchor||n&&n.divideBy(2,!0),s=a?new L.Point(...Array.isArray(a)?a:[a.x,a.y]):null;t.className="leaflet-marker-"+e+" "+(i.className||""),s&&(t.style.marginLeft=-s.x+"px",t.style.marginTop=-s.y+"px",t.style.transformOrigin=s.x+"px "+s.y+"px 0px"),n&&(t.style.width=n.x+"px",t.style.height=n.y+"px")}});var v=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.Marker.prototype));L.Marker.mergeOptions({rotation:0,rotateWithView:!1,keepUpright:!1,scale:void 0});var y,M={_onDrag(t){let e=this._marker,i=e.options.rotation||e.options.rotateWithView,o=e._shadow,n=L.DomUtil.getPosition(e._icon);!i&&o&&L.DomUtil.setPosition(o,n),e._map._rotate&&(n=e._map.mapPanePointToRotatedPoint(n));let a=e._map.layerPointToLatLng(n);e._latlng=a,t.latlng=a,t.oldLatLng=this._oldLatLng,i?e.setLatLng(a):e.fire("move",t),e.fire("drag",t)},_onDragEnd(t){this._marker._map._rotate&&this._marker.update(),y._onDragEnd.apply(this,arguments)}};L.Marker.include({getEvents(){return Object.assign(v.getEvents.apply(this,arguments),{rotate:this.update})},_initInteraction(){let t=v._initInteraction.apply(this,arguments);return this.dragging&&this.dragging.enabled()&&this._map&&this._map._rotate&&(y=y||Object.getPrototypeOf(this.dragging),this.dragging.disable(),Object.assign(this.dragging,{_onDrag:M._onDrag.bind(this.dragging),_onDragEnd:M._onDragEnd.bind(this.dragging)}),this.dragging.enable()),t},_setPos(t){this._map._rotate&&(t=this._map.rotatedPointToMapPanePoint(t));let e=this.options.rotation||0;this.options.rotateWithView&&(e+=this._map._bearing),this.options.keepUpright&&(e=(e%(2*Math.PI)+2*Math.PI)%(2*Math.PI),e>Math.PI/2&&e<3*Math.PI/2&&(e+=Math.PI),e%=2*Math.PI),this._icon&&L.DomUtil.setPosition(this._icon,t,e,t,this.options.scale),this._shadow&&L.DomUtil.setPosition(this._shadow,t,e,t,this.options.scale),this._zIndex=t.y+this.options.zIndexOffset,this._resetZIndex()},setRotation(t){this.options.rotation=t,this.update()}});var w=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.GridLayer.prototype));L.GridLayer.include({getEvents(){let t=w.getEvents.apply(this,arguments);return this._map._rotate&&!this.options.updateWhenIdle&&(this._onRotate||(this._onRotate=L.Util.throttle(this._onMoveEnd,this.options.updateInterval,this)),t.rotate=this._onRotate),t},_getTiledPixelBounds(t){return this._map._rotate?this._map._getNewPixelBounds(t,this._tileZoom):w._getTiledPixelBounds.apply(this,arguments)}});var c=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.Renderer.prototype)),g=Object.getPrototypeOf(L.Renderer.prototype),C=c.getEvents||g.getEvents;L.Renderer.include({getEvents(){let t=C.apply(this,arguments);return L.version.startsWith("2.")?t:Object.assign(t,{rotate:this._update})},onAdd(){c.onAdd.apply(this,arguments),L.version<="1.9.3"&&this._container.classList.add("leaflet-zoom-animated")},_updateTransform(t,e){if(L.version.startsWith("2.")){if(this._map._rotate){let n=this._map.getZoomScale(e,this._zoom),a=this._topLeftPoint.multiplyBy(n).subtract(this._map._getNewPixelOrigin(t,e));L.DomUtil.setTransform(this._container,a,n);return}return g._updateTransform.apply(this,arguments)}if(!this._map._rotate)return c._updateTransform.apply(this,arguments);if(e===this._zoom)return;let i=this._map.getZoomScale(e,this._zoom),o=this._map._latLngToNewLayerPoint(this._topLeft,e,t);L.DomUtil.setTransform(this._container,o,i)},_onMoveEnd(t){if(!L.version.startsWith("2.")||!this._map._rotate)return g._onMoveEnd.apply(this,arguments);this._bounds=this._map._getPaddedPixelBounds(this.options.padding),this._topLeft=this._map.layerPointToLatLng(this._bounds.min),this._center=this._map.getCenter(),this._zoom=this._map.getZoom(),this._topLeftPoint=this._map._getNewPixelOrigin(this._center,this._zoom).add(this._bounds.min),this._updateTransform(this._center,this._zoom),this._resizeContainer(),this._onSettled(t)},_resizeContainer(){if(!L.version.startsWith("2.")||!this._map._rotate||!this._bounds)return g._resizeContainer.apply(this,arguments);let t=this._bounds.getSize();return this._container.style.width=t.x+"px",this._container.style.height=t.y+"px",t},_update(){if(!this._map._rotate)return c._update.apply(this,arguments);this._bounds=this._map._getPaddedPixelBounds(this.options.padding),this._topLeft=this._map.layerPointToLatLng(this._bounds.min),this._center=this._map.getCenter(),this._zoom=this._map.getZoom()}});var m=Object.defineProperties({},Object.getOwnPropertyDescriptors(L.Map.prototype));L.Map.mergeOptions({rotate:!1,bearing:0});L.Map.include({_animateZoomNoDelay(t,e){this._mapPane&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=e,this._move(t,e,void 0,!0),this._onZoomTransitionEnd())},initialize(t,e){e.rotate&&(this._rotate=!0,this._bearing=0),m.initialize.apply(this,arguments),this.options.rotate&&this.setBearing(this.options.bearing)},containerPointToLayerPoint(t){return this._rotate?p(t).subtract(this._getMapPanePos()).rotateFrom(-this._bearing,this._getRotatePanePos()).subtract(this._getRotatePanePos()):m.containerPointToLayerPoint.apply(this,arguments)},layerPointToContainerPoint(t){return this._rotate?p(t).add(this._getRotatePanePos()).rotateFrom(this._bearing,this._getRotatePanePos()).add(this._getMapPanePos()):m.layerPointToContainerPoint.apply(this,arguments)},rotatedPointToMapPanePoint(t){return p(t).rotate(this._bearing)._add(this._getRotatePanePos())},mapPanePointToRotatedPoint(t){return p(t)._subtract(this._getRotatePanePos()).rotate(-this._bearing)},mapBoundsToContainerBounds(t){if(!this._rotate&&m.mapBoundsToContainerBounds)return m.mapBoundsToContainerBounds.apply(this,arguments);let e=this.getPixelOrigin(),i=this.layerPointToContainerPoint(this.project(t.getNorthWest())._subtract(e)),o=this.layerPointToContainerPoint(this.project(t.getNorthEast())._subtract(e)),n=this.layerPointToContainerPoint(this.project(t.getSouthWest())._subtract(e)),a=this.layerPointToContainerPoint(this.project(t.getSouthEast())._subtract(e));return new L.Bounds([new L.Point(Math.min(i.x,o.x,a.x,n.x),Math.min(i.y,o.y,a.y,n.y)),new L.Point(Math.max(i.x,o.x,a.x,n.x),Math.max(i.y,o.y,a.y,n.y))])},getBounds(){if(!this._rotate)return m.getBounds.apply(this,arguments);let t=this.getSize();return new L.LatLngBounds([this.containerPointToLatLng([0,0]),this.containerPointToLatLng([t.x,0]),this.containerPointToLatLng([t.x,t.y]),this.containerPointToLatLng([0,t.y])])},setBearing(t,e){if(this._rotate){if(e&&e.animate){this._bearingAnimationId=(this._bearingAnimationId||0)+1;let i=this._bearingAnimationId;this._bearingAnimationFrame&&cancelAnimationFrame(this._bearingAnimationFrame);let o=this.getBearing(),n=L.Util.wrapNum(t,[0,360]),a=(n-o+540)%360-180,s=Math.max(0,e.duration==null?.25:e.duration)*1e3,h=Math.max(e.easeLinearity||.5,.2),r=performance.now(),_=function(){if(!this._mapPane){delete this._bearingAnimationFrame;return}let l=s?Math.min((performance.now()-r)/s,1):1,d=1-Math.pow(1-l,1/h);this._setBearing(l===1?n:o+a*d),this._bearingAnimationId===i&&(l<1?this._bearingAnimationFrame=requestAnimationFrame(_.bind(this)):delete this._bearingAnimationFrame)};this._bearingAnimationFrame=requestAnimationFrame(_.bind(this));return}this._bearingAnimationId=(this._bearingAnimationId||0)+1,this._bearingAnimationFrame&&(cancelAnimationFrame(this._bearingAnimationFrame),delete this._bearingAnimationFrame),this._setBearing(t)}},_setBearing(t){let e=L.Util.wrapNum(t,[0,360])*(Math.PI/180),i=this._getPixelCenter(),o=this._getRotatePanePos().rotateFrom(-this._bearing,i),n=o.rotateFrom(e,i);L.DomUtil.setPosition(this._rotatePane,o,e,i),this._pivot=i,this._bearing=e,this._rotatePanePos=n,this.fire("rotate")},getBearing(){return this._bearing*(180/Math.PI)},_initPanes(){let t=this._panes={};this._paneRenderers={},this._mapPane=this.createPane("mapPane",this._container),L.DomUtil.setPosition(this._mapPane,new L.Point(0,0)),this._rotate?(this._rotatePane=this.createPane("rotatePane",this._mapPane),this._norotatePane=this.createPane("norotatePane",this._mapPane),L.version.startsWith("2.")&&(this._rotatePane.style.transformOrigin="0 0"),this.createPane("tilePane",this._rotatePane),this.createPane("overlayPane",this._rotatePane),this.createPane("shadowPane",this._norotatePane),this.createPane("markerPane",this._norotatePane),this.createPane("tooltipPane",this._norotatePane),this.createPane("popupPane",this._norotatePane)):(this.createPane("tilePane"),this.createPane("overlayPane"),this.createPane("shadowPane"),this.createPane("markerPane"),this.createPane("tooltipPane"),this.createPane("popupPane")),this.options.markerZoomAnimation||(t.markerPane.classList.add("leaflet-zoom-hide"),t.shadowPane.classList.add("leaflet-zoom-hide"))},panInside(t,e){if(!this._rotate||Math.abs(this._bearing).toFixed(1)<.1)return m.panInside.apply(this,arguments);e=e||{};let i=p(e.paddingTopLeft||e.padding||[0,0]),o=p(e.paddingBottomRight||e.padding||[0,0]),n=this.latLngToContainerPoint(t),a=new L.Bounds([new L.Point(0,0),this.getSize()]),s=a.getCenter(),h=new L.Bounds([a.min.add(i),a.max.subtract(o)]),r=h.getSize();if(!h.contains(n)){this._enforcingBounds=!0;let _=n.subtract(h.getCenter()),l=h.extend(n).getSize().subtract(r);s.x+=_.x<0?-l.x:l.x,s.y+=_.y<0?-l.y:l.y,this.panTo(this.containerPointToLatLng(s),e),this._enforcingBounds=!1}return this},getBoundsZoom(t,e,i){if(!this._rotate||Math.abs(this._bearing).toFixed(1)<.1)return m.getBoundsZoom.apply(this,arguments);t=t instanceof L.LatLngBounds?t:new L.LatLngBounds(t),i=p(i||[0,0]);let o=this.getZoom()||0,n=this.getMinZoom(),a=this.getMaxZoom(),s=this.getSize().subtract(i),h=this.mapBoundsToContainerBounds(t).getSize(),r=this.options.zoomSnap,_=s.x/h.x,l=s.y/h.y,d=e?Math.max(_,l):Math.min(_,l);return o=this.getScaleZoom(d,o),r&&(o=Math.round(o/(r/100))*(r/100),o=e?Math.ceil(o/r)*r:Math.floor(o/r)*r),Math.max(n,Math.min(a,o))},_getCenterOffset(t){let e=m._getCenterOffset.apply(this,arguments);return this._rotate&&(e=e.rotate(this._bearing)),e},_getRotatePanePos(){return this._rotatePanePos||new L.Point(0,0)},_getNewPixelOrigin(t,e){if(!this._rotate||L.version.startsWith("2."))return m._getNewPixelOrigin.apply(this,arguments);let i=this.getSize()._divideBy(2);return this.project(t,e).rotate(this._bearing)._subtract(i)._add(this._getMapPanePos())._add(this._getRotatePanePos()).rotate(-this._bearing)._round()},_getNewPixelBounds(t,e){if(t=t||this.getCenter(),e=e||this.getZoom(),!this._rotate&&m._getNewPixelBounds)return m._getNewPixelBounds.apply(this,arguments);let i=this._animatingZoom?Math.max(this._animateToZoom,this.getZoom()):this.getZoom(),o=this.getZoomScale(i,e),n=this.project(t,e).floor(),a=this.getSize(),s=new L.Bounds([this.containerPointToLayerPoint([0,0]).floor(),this.containerPointToLayerPoint([a.x,0]).floor(),this.containerPointToLayerPoint([0,a.y]).floor(),this.containerPointToLayerPoint([a.x,a.y]).floor()]).getSize().divideBy(o*2);return new L.Bounds(n.subtract(s),n.add(s))},_getPixelCenter(){return!this._rotate&&m._getPixelCenter?m._getPixelCenter.apply(this,arguments):this.getSize()._divideBy(2)._subtract(this._getMapPanePos())},_getPaddedPixelBounds(t){if(!this._rotate&&m._getPaddedPixelBounds)return m._getPaddedPixelBounds.apply(this,arguments);let e=t,i=this.getSize(),o=i.multiplyBy(-e),n=i.multiplyBy(1+e);return new L.Bounds([this.containerPointToLayerPoint([o.x,o.y]).floor(),this.containerPointToLayerPoint([o.x,n.y]).floor(),this.containerPointToLayerPoint([n.x,o.y]).floor(),this.containerPointToLayerPoint([n.x,n.y]).floor()])},_handleGeolocationResponse(t){if(!this._container._leaflet_id)return;let e=t.coords.latitude,i=t.coords.longitude,o=t.coords.heading,n=new L.LatLng(e,i),a=n.toBounds(t.coords.accuracy),s=this._locateOptions;if(s.setView){let r=this.getBoundsZoom(a);this.setView(n,s.maxZoom?Math.min(r,s.maxZoom):r)}let h={latlng:n,bounds:a,timestamp:t.timestamp,heading:o};for(let r in t.coords)typeof t.coords[r]=="number"&&(h[r]=t.coords[r]);this.fire("locationfound",h)}});L.Map.CompassBearing=L.Handler.extend({initialize(t){this._map=t,"ondeviceorientationabsolute"in window?this.__deviceOrientationEvent="deviceorientationabsolute":"ondeviceorientation"in window&&(this.__deviceOrientationEvent="deviceorientation"),this._throttled=L.Util.throttle(this._onDeviceOrientation,100,this)},addHooks(){this._map._rotate&&this.__deviceOrientationEvent?L.DomEvent.on(window,this.__deviceOrientationEvent,this._throttled,this):this.disable()},removeHooks(){this._map._rotate&&this.__deviceOrientationEvent&&L.DomEvent.off(window,this.__deviceOrientationEvent,this._throttled,this)},_onDeviceOrientation(t){let e=t.webkitCompassHeading!=null?t.webkitCompassHeading:t.alpha,i=0;Number.isFinite(e)&&(!t.absolute&&t.webkitCompassHeading&&(e=360-e),!t.absolute&&typeof window.orientation<"u"&&(i=window.orientation),this._map.setBearing(e-i))}});L.Map.addInitHook("addHandler","compassBearing",L.Map.CompassBearing);L.Map.mergeOptions({trackContainerMutation:!1});L.Map.ContainerMutation=L.Handler.extend({addHooks(){this._observer||(this._observer=new MutationObserver(L.Util.bind(this._map.invalidateSize,this._map))),this._observer.observe(this._map.getContainer(),{childList:!1,attributes:!0,characterData:!1,subtree:!1,attributeFilter:["style"]})},removeHooks(){this._observer.disconnect()}});L.Map.addInitHook("addHandler","trackContainerMutation",L.Map.ContainerMutation);function u(t,e){let i=t.getContainer(),o=i.getBoundingClientRect();return new L.Point(e.clientX-o.left-i.clientLeft,e.clientY-o.top-i.clientTop)}L.Map.mergeOptions({bounceAtZoomLimits:!0});L.Map.TouchGestures=L.Handler.extend({initialize(t){this._map=t,this.rotate=!!this._map.options.touchRotate,this.zoom=!!this._map.options.touchZoom},addHooks(){L.DomEvent.on(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks(){L.DomEvent.off(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart(t){let e=this._map;if(!t.touches||t.touches.length!==2||e._animatingZoom||this._zooming||this._rotating)return;let i=u(e,t.touches[0]),o=u(e,t.touches[1]),n=i.subtract(o);this._centerPoint=e.getSize()._divideBy(2),this._startLatLng=e.containerPointToLatLng(this._centerPoint),this.zoom?(e.options.touchZoom!=="center"&&(this._pinchStartLatLng=e.containerPointToLatLng(i.add(o)._divideBy(2))),this._startDist=i.distanceTo(o),this._startZoom=e.getZoom(),this._zooming=!0):this._zooming=!1,this.rotate?(this._startTheta=Math.atan(n.x/n.y),this._startBearing=e.getBearing(),n.y<0&&(this._startBearing+=180),this._rotating=!0):this._rotating=!1,this._moved=!1,e._stop(),L.DomEvent.on(document,"touchmove",this._onTouchMove,this).on(document,"touchend touchcancel",this._onTouchEnd,this),L.DomEvent.preventDefault(t)},_onTouchMove(t){if(!t.touches||t.touches.length!==2||!(this._zooming||this._rotating))return;let e=this._map,i=u(e,t.touches[0]),o=u(e,t.touches[1]),n=i.subtract(o),a=i.distanceTo(o)/this._startDist,s;if(this._rotating){let _=(Math.atan(n.x/n.y)-this._startTheta)*(180/Math.PI);n.y<0&&(_+=180),_&&e.setBearing(this._startBearing-_)}if(this._zooming)if(this._zoom=e.getScaleZoom(a,this._startZoom),!e.options.bounceAtZoomLimits&&(this._zoom<e.getMinZoom()&&a<1||this._zoom>e.getMaxZoom()&&a>1)&&(this._zoom=e._limitZoom(this._zoom)),e.options.touchZoom==="center"){if(this._center=this._startLatLng,a===1)return}else{if(s=i._add(o)._divideBy(2)._subtract(this._centerPoint),a===1&&s.x===0&&s.y===0)return;let r=-e.getBearing()*(Math.PI/180);this._center=e.unproject(e.project(this._pinchStartLatLng).subtract(s.rotate(r)))}this._moved||(e._moveStart(!0,!1),this._moved=!0),e._move.bind(e,this._center,this._zoom,{pinch:!0,round:!1},void 0)(),this.zoom&&(e.options.zoomAnimation?e._animateZoomNoDelay(this._center,e._limitZoom(this._zoom)):e._resetView(this._center,e._limitZoom(this._zoom))),L.DomEvent.preventDefault(t)},_onTouchEnd(){if(!this._moved||!(this._zooming||this._rotating)){this._zooming=!1;return}this._zooming=!1,this._rotating=!1,L.DomEvent.off(document,"touchmove",this._onTouchMove,this).off(document,"touchend touchcancel",this._onTouchEnd,this),this.zoom&&(this._map.options.zoomAnimation?this._map._animateZoom(this._center,this._map._limitZoom(this._zoom),!0,this._map.options.zoomSnap):this._map._resetView(this._center,this._map._limitZoom(this._zoom)))}});L.Map.addInitHook("addHandler","touchGestures",L.Map.TouchGestures);L.Map.mergeOptions({touchRotate:!1});L.Map.TouchRotate=L.Handler.extend({addHooks(){this._map.touchGestures.enable(),this._map.touchGestures.rotate=!0},removeHooks(){this._map.touchGestures.rotate=!1}});L.Map.addInitHook("addHandler","touchRotate",L.Map.TouchRotate);L.Map.mergeOptions({shiftKeyRotate:!0});L.Map.ShiftKeyRotate=L.Handler.extend({addHooks(){L.DomEvent.on(this._map._container,"wheel",this._handleShiftScroll,this),this._map.shiftKeyRotate.rotate=!0},removeHooks(){L.DomEvent.off(this._map._container,"wheel",this._handleShiftScroll,this),this._map.shiftKeyRotate.rotate=!1},_handleShiftScroll(t){t.shiftKey?(t.preventDefault(),this._map.scrollWheelZoom.disable(),this._map.setBearing(this._map._bearing*(180/Math.PI)+Math.sign(t.deltaY)*5)):this._map.scrollWheelZoom.enable()}});L.Map.addInitHook("addHandler","shiftKeyRotate",L.Map.ShiftKeyRotate);L.Map.addInitHook(function(){this.scrollWheelZoom.enabled()&&this.shiftKeyRotate.enabled()&&(this.scrollWheelZoom.disable(),this.scrollWheelZoom.enable())});L.Map.mergeOptions({touchZoom:L.Browser.touch,bounceAtZoomLimits:!1});L.Map.TouchZoom=L.Handler.extend({addHooks(){this._map._container.classList.add("leaflet-touch-zoom"),this._map.touchGestures.enable(),this._map.touchGestures.zoom=!0},removeHooks(){this._map._container.classList.remove("leaflet-touch-zoom"),this._map.touchGestures.zoom=!1}});L.Map.addInitHook("addHandler","touchZoom",L.Map.TouchZoom);L.Control.Rotate=L.Control.extend({options:{position:"topleft",closeOnZeroBearing:!0},onAdd(t){let e=this._container=L.DomUtil.create("div","leaflet-control-rotate leaflet-bar"),i=this._arrow=L.DomUtil.create("span","leaflet-control-rotate-arrow");i.style.backgroundImage=`url("data:image/svg+xml;charset=utf-8,%3Csvg width='29' height='29' viewBox='0 0 29 29' xmlns='http://www.w3.org/2000/svg' fill='%23333'%3E%3Cpath d='M10.5 14l4-8 4 8h-8z'/%3E%3Cpath d='M10.5 16l4 8 4-8h-8z' fill='%23ccc'/%3E%3C/svg%3E")`,i.style.cursor="grab",i.style.display="block",i.style.width="100%",i.style.height="100%",i.style.backgroundRepeat="no-repeat",i.style.backgroundPosition="50%";let o=this._link=L.DomUtil.create("a","leaflet-control-rotate-toggle",e);return o.appendChild(i),o.href="#",o.title="Rotate map",L.DomEvent.on(o,"dblclick",L.DomEvent.stopPropagation).on(o,"mousedown",this._handleMouseDown,this).on(o,"click",L.DomEvent.stop).on(o,"click",this._cycleState,this).on(o,"click",this._refocusOnMap,this),this._restyle(),t.on("rotate",this._restyle,this),this._follow=!1,this._canFollow=!1,this.options.closeOnZeroBearing&&t.getBearing()===0&&(e.style.display="none"),e},onRemove(t){t.off("rotate",this._restyle,this)},_handleMouseDown(t){L.DomEvent.stop(t),this.dragging=!0,this.dragstartX=t.pageX,this.dragstartY=t.pageY,L.DomEvent.on(document,"mousemove",this._handleMouseDrag,this).on(document,"mouseup",this._handleMouseUp,this)},_handleMouseUp(t){L.DomEvent.stop(t),this.dragging=!1,L.DomEvent.off(document,"mousemove",this._handleMouseDrag,this).off(document,"mouseup",this._handleMouseUp,this)},_handleMouseDrag(t){if(!this.dragging)return;let e=t.clientX-this.dragstartX;this._map.setBearing(e)},_cycleState(t){if(!this._map)return;let e=this._map;!e.touchRotate.enabled()&&!e.compassBearing.enabled()?e.touchRotate.enable():e.compassBearing.enabled()?(e.compassBearing.disable(),e.setBearing(0),this.options.closeOnZeroBearing&&e.touchRotate.enable()):(e.touchRotate.disable(),(DeviceOrientationEvent&&DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission():Promise.resolve("granted")).then(i=>i==="granted"&&e.compassBearing.enable())),this._restyle()},_restyle(){if(!this._map.options.rotate)this._link.classList.add("leaflet-disabled");else{let t=this._map,e=t.getBearing();this._arrow.style.transform="rotate("+e+"deg)",e&&this.options.closeOnZeroBearing&&(this._container.style.display="block"),t.compassBearing.enabled()?this._link.style.backgroundColor="orange":t.touchRotate.enabled()?this._link.style.backgroundColor=null:(this._link.style.backgroundColor="grey",e===0&&this.options.closeOnZeroBearing&&(this._container.style.display="none"))}}});L.control&&(L.control.rotate=t=>new L.Control.Rotate(t));L.Map.mergeOptions({rotateControl:!0});L.Map.addInitHook(function(){if(this.options.rotateControl){let t=typeof this.options.rotateControl=="object"?this.options.rotateControl:{};this.rotateControl=new L.Control.Rotate(t),this.addControl(this.rotateControl)}});return Z(E);})();
|
|
2
2
|
//# sourceMappingURL=leaflet-rotate.js.map
|