@zia_leung/leaflet.canvaslayer 1.0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Robert Plummer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Leaflet.Canvaslayer !
@@ -0,0 +1,2 @@
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var a=e();for(var n in a)("object"==typeof exports?exports:t)[n]=a[n]}}(globalThis,(()=>(()=>{"use strict";var t={d:(e,a)=>{for(var n in a)t.o(a,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:a[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{CanvasLayer:()=>a,default:()=>n}),L.DomUtil.setTransform||(L.DomUtil.setTransform=function(t,e,a){var n=e||new L.Point(0,0);t.style[L.DomUtil.TRANSFORM]=(L.Browser.ie3d?"translate("+n.x+"px,"+n.y+"px)":"translate3d("+n.x+"px,"+n.y+"px,0)")+(a?" scale("+a+")":"")});var a=(L.Layer?L.Layer:L.Class).extend({initialize:function(t){this._map=null,this._canvas=null,this._frame=null,this._delegate=null,this._paneBak=null,L.setOptions(this,t)},delegate:function(t){return this._delegate=t,this},needRedraw:function(){return this._frame||(this._frame=L.Util.requestAnimFrame(this.drawLayer,this)),this},_onLayerDidResize:function(t){this._canvas.width=t.newSize.x,this._canvas.height=t.newSize.y},_onLayerDidMove:function(){if(this._map){var t=this._map.containerPointToLayerPoint([0,0]);L.DomUtil.setPosition(this._canvas,t),this.drawLayer()}},getEvents:function(){var t={resize:this._onLayerDidResize,moveend:this._onLayerDidMove};return this._map.options.zoomAnimation&&L.Browser.any3d&&(t.zoomanim=this._animateZoom),t},onAdd:function(t){this._map=t,this._canvas=L.DomUtil.create("canvas","leaflet-layer"),this.tiles={};var e=this._map.getSize();this._canvas.width=e.x,this._canvas.height=e.y;var a=this._map.options.zoomAnimation&&L.Browser.any3d;L.DomUtil.addClass(this._canvas,"leaflet-zoom-"+(a?"animated":"hide")),this._paneBak=this._map.getPane(this.options.pane)||this._map._panes.overlayPane,this._paneBak.appendChild(this._canvas),t.on(this.getEvents(),this);var n=this._delegate||this;n.onLayerDidMount&&n.onLayerDidMount();var i=this;setTimeout((function(){i._onLayerDidMove()}),0)},onRemove:function(t){var e=this._delegate||this;e.onLayerWillUnmount&&e.onLayerWillUnmount(),this._paneBak.removeChild(this._canvas),t.off(this.getEvents(),this),this._canvas=null},addTo:function(t){return t.addLayer(this),this},LatLonToMercator:function(t){return{x:6378137*t.lng*Math.PI/180,y:6378137*Math.log(Math.tan((90+t.lat)*Math.PI/360))}},drawLayer:function(){var t=this._map.getSize(),e=this._map.getBounds(),a=this._map.getZoom(),n=this.LatLonToMercator(this._map.getCenter()),i=this.LatLonToMercator(this._map.containerPointToLatLng(this._map.getSize())),o=this._delegate||this;o.onDrawLayer&&o.onDrawLayer({layer:this,canvas:this._canvas,bounds:e,size:t,zoom:a,center:n,corner:i}),this._frame=null},_setTransform:function(t,e,a){var n=e||new L.Point(0,0);t.style[L.DomUtil.TRANSFORM]=(L.Browser.ie3d?"translate("+n.x+"px,"+n.y+"px)":"translate3d("+n.x+"px,"+n.y+"px,0)")+(a?" scale("+a+")":"")},_animateZoom:function(t){var e=this._map.getZoomScale(t.zoom),a=L.Layer?this._map._latLngToNewLayerPoint(this._map.getBounds().getNorthWest(),t.zoom,t.center):this._map._getCenterOffset(t.center)._multiplyBy(-e).subtract(this._map._getMapPanePos());L.DomUtil.setTransform(this._canvas,a,e)}});const n=a;return"undefined"!=typeof window&&window.L&&(window.L.CanvasLayer=a),e})()));
2
+ //# sourceMappingURL=canvaslayer-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvaslayer-browser.js","mappings":"CAAA,SAA2CA,EAAMC,GAChD,GAAsB,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,SACb,GAAqB,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,OACP,CACJ,IAAIK,EAAIL,IACR,IAAI,IAAIM,KAAKD,GAAuB,iBAAZJ,QAAuBA,QAAUF,GAAMO,GAAKD,EAAEC,EACvE,CACA,CATD,CASGC,YAAY,I,mBCRf,IAAIC,EAAsB,CCA1BA,EAAwB,CAACP,EAASQ,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAEV,EAASS,IAC5EE,OAAOC,eAAeZ,EAASS,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAA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QAA0BA,OAAOrG,IAE1CqG,OAAOrG,EAAEc,YAAcA,G","sources":["webpack://@zia_leung/leaflet.canvaslayer/webpack/universalModuleDefinition","webpack://@zia_leung/leaflet.canvaslayer/webpack/bootstrap","webpack://@zia_leung/leaflet.canvaslayer/webpack/runtime/define property getters","webpack://@zia_leung/leaflet.canvaslayer/webpack/runtime/hasOwnProperty shorthand","webpack://@zia_leung/leaflet.canvaslayer/webpack/runtime/make namespace object","webpack://@zia_leung/leaflet.canvaslayer/./src/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(globalThis, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","if (!L.DomUtil.setTransform) {\n L.DomUtil.setTransform = function(el, offset, scale) {\n var pos = offset || new L.Point(0, 0)\n\n el.style[L.DomUtil.TRANSFORM] = (L.Browser.ie3d ? 'translate(' + pos.x + 'px,' + pos.y + 'px)' : 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') + (scale ? ' scale(' + scale + ')' : '')\n }\n}\n\n\nexport var CanvasLayer = (L.Layer ? L.Layer : L.Class).extend({\n initialize: function(options) {\n this._map = null\n this._canvas = null\n this._frame = null\n this._delegate = null\n this._paneBak = null\n L.setOptions(this, options)\n },\n\n delegate: function(del) {\n this._delegate = del\n return this\n },\n\n needRedraw: function() {\n if (!this._frame) {\n this._frame = L.Util.requestAnimFrame(this.drawLayer, this)\n }\n return this\n },\n\n _onLayerDidResize: function(resizeEvent) {\n this._canvas.width = resizeEvent.newSize.x\n this._canvas.height = resizeEvent.newSize.y\n },\n \n _onLayerDidMove: function() {\n if (this._map) {\n var topLeft = this._map.containerPointToLayerPoint([0, 0])\n L.DomUtil.setPosition(this._canvas, topLeft)\n this.drawLayer()\n }\n },\n \n getEvents: function() {\n var events = {\n resize: this._onLayerDidResize,\n moveend: this._onLayerDidMove\n }\n if (this._map.options.zoomAnimation && L.Browser.any3d) {\n events.zoomanim = this._animateZoom\n }\n\n return events\n },\n \n onAdd: function(map) {\n this._map = map\n this._canvas = L.DomUtil.create('canvas', 'leaflet-layer')\n this.tiles = {}\n\n var size = this._map.getSize()\n this._canvas.width = size.x\n this._canvas.height = size.y\n\n var animated = this._map.options.zoomAnimation && L.Browser.any3d\n L.DomUtil.addClass(this._canvas, 'leaflet-zoom-' + (animated ? 'animated' : 'hide'))\n this._paneBak = this._map.getPane(this.options.pane) || this._map._panes.overlayPane\n this._paneBak.appendChild(this._canvas)\n map.on(this.getEvents(), this)\n\n var del = this._delegate || this\n del.onLayerDidMount && del.onLayerDidMount() \n // this.needRedraw()\n\n var self = this\n setTimeout(function() {\n self._onLayerDidMove()\n }, 0)\n },\n\n \n onRemove: function(map) {\n var del = this._delegate || this\n del.onLayerWillUnmount && del.onLayerWillUnmount()\n\n this._paneBak.removeChild(this._canvas)\n\n map.off(this.getEvents(), this)\n\n this._canvas = null\n },\n\n \n addTo: function(map) {\n map.addLayer(this)\n return this\n },\n \n LatLonToMercator: function(latlon) {\n return {\n x: (latlon.lng * 6378137 * Math.PI) / 180,\n y: Math.log(Math.tan(((90 + latlon.lat) * Math.PI) / 360)) * 6378137\n }\n },\n\n \n drawLayer: function() {\n var size = this._map.getSize()\n var bounds = this._map.getBounds()\n var zoom = this._map.getZoom()\n\n var center = this.LatLonToMercator(this._map.getCenter())\n var corner = this.LatLonToMercator(this._map.containerPointToLatLng(this._map.getSize()))\n\n var del = this._delegate || this\n del.onDrawLayer &&\n del.onDrawLayer({\n layer: this,\n canvas: this._canvas,\n bounds: bounds,\n size: size,\n zoom: zoom,\n center: center,\n corner: corner\n })\n this._frame = null\n },\n \n _setTransform: function(el, offset, scale) {\n var pos = offset || new L.Point(0, 0)\n\n el.style[L.DomUtil.TRANSFORM] = (L.Browser.ie3d ? 'translate(' + pos.x + 'px,' + pos.y + 'px)' : 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') + (scale ? ' scale(' + scale + ')' : '')\n },\n\n \n _animateZoom: function(e) {\n var scale = this._map.getZoomScale(e.zoom)\n var offset = L.Layer\n ? this._map._latLngToNewLayerPoint(this._map.getBounds().getNorthWest(), e.zoom, e.center)\n : this._map._getCenterOffset(e.center)._multiplyBy(-scale).subtract(this._map._getMapPanePos())\n\n L.DomUtil.setTransform(this._canvas, offset, scale)\n }\n})\nexport default CanvasLayer;\nif (typeof window !== \"undefined\" && window.L) {\n // @ts-expect-error exporting it to window\n window.L.CanvasLayer = CanvasLayer;\n}"],"names":["root","factory","exports","module","define","amd","a","i","globalThis","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","L","DomUtil","setTransform","el","offset","scale","pos","Point","style","TRANSFORM","Browser","ie3d","x","y","CanvasLayer","Layer","Class","extend","initialize","options","this","_map","_canvas","_frame","_delegate","_paneBak","setOptions","delegate","del","needRedraw","Util","requestAnimFrame","drawLayer","_onLayerDidResize","resizeEvent","width","newSize","height","_onLayerDidMove","topLeft","containerPointToLayerPoint","setPosition","getEvents","events","resize","moveend","zoomAnimation","any3d","zoomanim","_animateZoom","onAdd","map","create","tiles","size","getSize","animated","addClass","getPane","pane","_panes","overlayPane","appendChild","on","onLayerDidMount","self","setTimeout","onRemove","onLayerWillUnmount","removeChild","off","addTo","addLayer","LatLonToMercator","latlon","lng","Math","PI","log","tan","lat","bounds","getBounds","zoom","getZoom","center","getCenter","corner","containerPointToLatLng","onDrawLayer","layer","canvas","_setTransform","e","getZoomScale","_latLngToNewLayerPoint","getNorthWest","_getCenterOffset","_multiplyBy","subtract","_getMapPanePos","window"],"sourceRoot":""}
@@ -0,0 +1,2 @@
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var a=e();for(var n in a)("object"==typeof exports?exports:t)[n]=a[n]}}(globalThis,(()=>(()=>{"use strict";var t={d:(e,a)=>{for(var n in a)t.o(a,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:a[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{CanvasLayer:()=>a,default:()=>n}),L.DomUtil.setTransform||(L.DomUtil.setTransform=function(t,e,a){var n=e||new L.Point(0,0);t.style[L.DomUtil.TRANSFORM]=(L.Browser.ie3d?"translate("+n.x+"px,"+n.y+"px)":"translate3d("+n.x+"px,"+n.y+"px,0)")+(a?" scale("+a+")":"")});var a=(L.Layer?L.Layer:L.Class).extend({initialize:function(t){this._map=null,this._canvas=null,this._frame=null,this._delegate=null,this._paneBak=null,L.setOptions(this,t)},delegate:function(t){return this._delegate=t,this},needRedraw:function(){return this._frame||(this._frame=L.Util.requestAnimFrame(this.drawLayer,this)),this},_onLayerDidResize:function(t){this._canvas.width=t.newSize.x,this._canvas.height=t.newSize.y},_onLayerDidMove:function(){if(this._map){var t=this._map.containerPointToLayerPoint([0,0]);L.DomUtil.setPosition(this._canvas,t),this.drawLayer()}},getEvents:function(){var t={resize:this._onLayerDidResize,moveend:this._onLayerDidMove};return this._map.options.zoomAnimation&&L.Browser.any3d&&(t.zoomanim=this._animateZoom),t},onAdd:function(t){this._map=t,this._canvas=L.DomUtil.create("canvas","leaflet-layer"),this.tiles={};var e=this._map.getSize();this._canvas.width=e.x,this._canvas.height=e.y;var a=this._map.options.zoomAnimation&&L.Browser.any3d;L.DomUtil.addClass(this._canvas,"leaflet-zoom-"+(a?"animated":"hide")),this._paneBak=this._map.getPane(this.options.pane)||this._map._panes.overlayPane,this._paneBak.appendChild(this._canvas),t.on(this.getEvents(),this);var n=this._delegate||this;n.onLayerDidMount&&n.onLayerDidMount();var i=this;setTimeout((function(){i._onLayerDidMove()}),0)},onRemove:function(t){var e=this._delegate||this;e.onLayerWillUnmount&&e.onLayerWillUnmount(),this._paneBak.removeChild(this._canvas),t.off(this.getEvents(),this),this._canvas=null},addTo:function(t){return t.addLayer(this),this},LatLonToMercator:function(t){return{x:6378137*t.lng*Math.PI/180,y:6378137*Math.log(Math.tan((90+t.lat)*Math.PI/360))}},drawLayer:function(){var t=this._map.getSize(),e=this._map.getBounds(),a=this._map.getZoom(),n=this.LatLonToMercator(this._map.getCenter()),i=this.LatLonToMercator(this._map.containerPointToLatLng(this._map.getSize())),o=this._delegate||this;o.onDrawLayer&&o.onDrawLayer({layer:this,canvas:this._canvas,bounds:e,size:t,zoom:a,center:n,corner:i}),this._frame=null},_setTransform:function(t,e,a){var n=e||new L.Point(0,0);t.style[L.DomUtil.TRANSFORM]=(L.Browser.ie3d?"translate("+n.x+"px,"+n.y+"px)":"translate3d("+n.x+"px,"+n.y+"px,0)")+(a?" scale("+a+")":"")},_animateZoom:function(t){var e=this._map.getZoomScale(t.zoom),a=L.Layer?this._map._latLngToNewLayerPoint(this._map.getBounds().getNorthWest(),t.zoom,t.center):this._map._getCenterOffset(t.center)._multiplyBy(-e).subtract(this._map._getMapPanePos());L.DomUtil.setTransform(this._canvas,a,e)}});const n=a;return"und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C,EAAMF,GAAU,IAAIJ,EAAEO,MAAM,EAAG,GAEnCJ,EAAGK,MAAMR,EAAEC,QAAQQ,YAAcT,EAAEU,QAAQC,KAAO,aAAeL,EAAIM,EAAI,MAAQN,EAAIO,EAAI,MAAQ,eAAiBP,EAAIM,EAAI,MAAQN,EAAIO,EAAI,UAAYR,EAAQ,UAAYA,EAAQ,IAAM,GAC1L,EAGA4C,aAAc,SAAS4C,GACrB,IAAIxF,EAAQe,KAAKC,KAAKyE,aAAaD,EAAEV,MACjC/E,EAASJ,EAAEe,MACXK,KAAKC,KAAK0E,uBAAuB3E,KAAKC,KAAK6D,YAAYc,eAAgBH,EAAEV,KAAMU,EAAER,QACjFjE,KAAKC,KAAK4E,iBAAiBJ,EAAER,QAAQa,aAAa7F,GAAO8F,SAAS/E,KAAKC,KAAK+E,kBAEhFpG,EAAEC,QAAQC,aAAakB,KAAKE,QAASlB,EAAQC,EAC/C,IAEF,U,MACsB,oBAAXgG,QAA0BA,OAAOrG,IAE1CqG,OAAOrG,EAAEc,YAAcA,G","sources":["webpack://@zia_leung/leaflet.canvaslayer/webpack/universalModuleDefinition","webpack://@zia_leung/leaflet.canvaslayer/webpack/bootstrap","webpack://@zia_leung/leaflet.canvaslayer/webpack/runtime/define property getters","webpack://@zia_leung/leaflet.canvaslayer/webpack/runtime/hasOwnProperty shorthand","webpack://@zia_leung/leaflet.canvaslayer/webpack/runtime/make namespace object","webpack://@zia_leung/leaflet.canvaslayer/./src/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(globalThis, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","if (!L.DomUtil.setTransform) {\n L.DomUtil.setTransform = function(el, offset, scale) {\n var pos = offset || new L.Point(0, 0)\n\n el.style[L.DomUtil.TRANSFORM] = (L.Browser.ie3d ? 'translate(' + pos.x + 'px,' + pos.y + 'px)' : 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') + (scale ? ' scale(' + scale + ')' : '')\n }\n}\n\n\nexport var CanvasLayer = (L.Layer ? L.Layer : L.Class).extend({\n initialize: function(options) {\n this._map = null\n this._canvas = null\n this._frame = null\n this._delegate = null\n this._paneBak = null\n L.setOptions(this, options)\n },\n\n delegate: function(del) {\n this._delegate = del\n return this\n },\n\n needRedraw: function() {\n if (!this._frame) {\n this._frame = L.Util.requestAnimFrame(this.drawLayer, this)\n }\n return this\n },\n\n _onLayerDidResize: function(resizeEvent) {\n this._canvas.width = resizeEvent.newSize.x\n this._canvas.height = resizeEvent.newSize.y\n },\n \n _onLayerDidMove: function() {\n if (this._map) {\n var topLeft = this._map.containerPointToLayerPoint([0, 0])\n L.DomUtil.setPosition(this._canvas, topLeft)\n this.drawLayer()\n }\n },\n \n getEvents: function() {\n var events = {\n resize: this._onLayerDidResize,\n moveend: this._onLayerDidMove\n }\n if (this._map.options.zoomAnimation && L.Browser.any3d) {\n events.zoomanim = this._animateZoom\n }\n\n return events\n },\n \n onAdd: function(map) {\n this._map = map\n this._canvas = L.DomUtil.create('canvas', 'leaflet-layer')\n this.tiles = {}\n\n var size = this._map.getSize()\n this._canvas.width = size.x\n this._canvas.height = size.y\n\n var animated = this._map.options.zoomAnimation && L.Browser.any3d\n L.DomUtil.addClass(this._canvas, 'leaflet-zoom-' + (animated ? 'animated' : 'hide'))\n this._paneBak = this._map.getPane(this.options.pane) || this._map._panes.overlayPane\n this._paneBak.appendChild(this._canvas)\n map.on(this.getEvents(), this)\n\n var del = this._delegate || this\n del.onLayerDidMount && del.onLayerDidMount() \n // this.needRedraw()\n\n var self = this\n setTimeout(function() {\n self._onLayerDidMove()\n }, 0)\n },\n\n \n onRemove: function(map) {\n var del = this._delegate || this\n del.onLayerWillUnmount && del.onLayerWillUnmount()\n\n this._paneBak.removeChild(this._canvas)\n\n map.off(this.getEvents(), this)\n\n this._canvas = null\n },\n\n \n addTo: function(map) {\n map.addLayer(this)\n return this\n },\n \n LatLonToMercator: function(latlon) {\n return {\n x: (latlon.lng * 6378137 * Math.PI) / 180,\n y: Math.log(Math.tan(((90 + latlon.lat) * Math.PI) / 360)) * 6378137\n }\n },\n\n \n drawLayer: function() {\n var size = this._map.getSize()\n var bounds = this._map.getBounds()\n var zoom = this._map.getZoom()\n\n var center = this.LatLonToMercator(this._map.getCenter())\n var corner = this.LatLonToMercator(this._map.containerPointToLatLng(this._map.getSize()))\n\n var del = this._delegate || this\n del.onDrawLayer &&\n del.onDrawLayer({\n layer: this,\n canvas: this._canvas,\n bounds: bounds,\n size: size,\n zoom: zoom,\n center: center,\n corner: corner\n })\n this._frame = null\n },\n \n _setTransform: function(el, offset, scale) {\n var pos = offset || new L.Point(0, 0)\n\n el.style[L.DomUtil.TRANSFORM] = (L.Browser.ie3d ? 'translate(' + pos.x + 'px,' + pos.y + 'px)' : 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') + (scale ? ' scale(' + scale + ')' : '')\n },\n\n \n _animateZoom: function(e) {\n var scale = this._map.getZoomScale(e.zoom)\n var offset = L.Layer\n ? this._map._latLngToNewLayerPoint(this._map.getBounds().getNorthWest(), e.zoom, e.center)\n : this._map._getCenterOffset(e.center)._multiplyBy(-scale).subtract(this._map._getMapPanePos())\n\n L.DomUtil.setTransform(this._canvas, offset, scale)\n }\n})\nexport default CanvasLayer;\nif (typeof window !== \"undefined\" && window.L) {\n // @ts-expect-error exporting it to window\n window.L.CanvasLayer = CanvasLayer;\n}"],"names":["root","factory","exports","module","define","amd","a","i","globalThis","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","L","DomUtil","setTransform","el","offset","scale","pos","Point","style","TRANSFORM","Browser","ie3d","x","y","CanvasLayer","Layer","Class","extend","initialize","options","this","_map","_canvas","_frame","_delegate","_paneBak","setOptions","delegate","del","needRedraw","Util","requestAnimFrame","drawLayer","_onLayerDidResize","resizeEvent","width","newSize","height","_onLayerDidMove","topLeft","containerPointToLayerPoint","setPosition","getEvents","events","resize","moveend","zoomAnimation","any3d","zoomanim","_animateZoom","onAdd","map","create","tiles","size","getSize","animated","addClass","getPane","pane","_panes","overlayPane","appendChild","on","onLayerDidMount","self","setTimeout","onRemove","onLayerWillUnmount","removeChild","off","addTo","addLayer","LatLonToMercator","latlon","lng","Math","PI","log","tan","lat","bounds","getBounds","zoom","getZoom","center","getCenter","corner","containerPointToLatLng","onDrawLayer","layer","canvas","_setTransform","e","getZoomScale","_latLngToNewLayerPoint","getNorthWest","_getCenterOffset","_multiplyBy","subtract","_getMapPanePos","window"],"sourceRoot":""}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@zia_leung/leaflet.canvaslayer",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/canvaslayer.js",
6
+ "browser": "dist/canvaslayer-browser.js",
7
+ "module": "dist/canvaslayer-browser.js",
8
+ "files": [
9
+ "/dist"
10
+ ],
11
+ "scripts": {
12
+ "test": "jest",
13
+ "build": "webpack --config webpack.config.js",
14
+ "coverage": "jest --coverage --coverage-provider v8 && codecov",
15
+ "serve": "webpack-dev-server --config webpack.config.dev.js --open",
16
+ "prepublish-gh-pages": "webpack --config webpack.config.gh-pages.js",
17
+ "publish-gh-pages": "npm run prepublish-gh-pages; gh-pages -d .gh-pages",
18
+ "lint": "run-p lint:**",
19
+ "lint:eslint": "eslint --fix --ext .js,.ts src",
20
+ "lint:typecheck": "tsc --noEmit",
21
+ "prepublishOnly": "npm run build",
22
+ "prepare": "npm run build"
23
+ },
24
+ "author": "",
25
+ "license": "ISC",
26
+ "dependencies": {
27
+ "earcut": "^2.2.4",
28
+ "geojson-flatten": "^1.1.1",
29
+ "point-in-polygon": "^1.1.0",
30
+ "polygon-lookup": "^2.6.0",
31
+ "rbush": "^3.0.1"
32
+ },
33
+ "devDependencies": {
34
+ "@glen/jest-raw-loader": "^2.0.0",
35
+ "@types/earcut": "^2.1.4",
36
+ "@types/eslint": "8.56.10",
37
+ "@types/eslint-plugin-prettier": "^3.1.3",
38
+ "@types/geojson": "^7946.0.14",
39
+ "@types/jest": "^29.5.12",
40
+ "@types/leaflet": "^1.9.12",
41
+ "@types/node": "^20.14.2",
42
+ "@types/polygon-lookup": "^2.6.4",
43
+ "@typescript-eslint/eslint-plugin": "^7.13.0",
44
+ "@typescript-eslint/parser": "^7.13.0",
45
+ "brfs": "^2.0.2",
46
+ "c8": "^10.1.2",
47
+ "canvas": "^2.11.2",
48
+ "copy-webpack-plugin": "^12.0.2",
49
+ "eslint": "^8.0.1",
50
+ "eslint-config-love": "^52.0.0",
51
+ "eslint-config-prettier": "^9.1.0",
52
+ "eslint-config-standard": "^15.0.1",
53
+ "eslint-plugin-import": "^2.29.1",
54
+ "eslint-plugin-jest": "^28.6.0",
55
+ "eslint-plugin-node": "^11.1.0",
56
+ "eslint-plugin-prettier": "^5.1.3",
57
+ "eslint-plugin-promise": "^6.2.0",
58
+ "eslint-plugin-standard": "^5.0.0",
59
+ "gh-pages": "^6.1.1",
60
+ "glslify-bundle": "^5.1.1",
61
+ "glslify-deps": "^1.3.2",
62
+ "jest": "^29.7.0",
63
+ "jest-environment-jsdom": "^29.7.0",
64
+ "jest-webgl-canvas-mock": "^2.5.3",
65
+ "leaflet": "1.9.4",
66
+ "npm-run-all": "^4.1.5",
67
+ "prettier": "^3.3.2",
68
+ "ts-jest": "^29.1.4",
69
+ "ts-loader": "^9.5.1",
70
+ "ts-shader-loader": "^2.0.2",
71
+ "typescript": "^5.4.5",
72
+ "webpack": "^5.94.0",
73
+ "webpack-cli": "^5.1.4",
74
+ "webpack-dev-server": "^5.0.4"
75
+ },
76
+ "peerDependencies": {
77
+ "leaflet": "1.9.4"
78
+ }
79
+ }