leaflet-rotate 0.2.0 → 0.2.1

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/lib/debug.js CHANGED
@@ -194,6 +194,8 @@ L.Rotate = {
194
194
  padInput.addEventListener('mousemove', L.Rotate.displayCenter.bind(this));
195
195
  padInput.addEventListener('change', L.Rotate.displayBounds.bind(this));
196
196
  padInput.addEventListener('mousemove', L.Rotate.displayBounds.bind(this));
197
+ padInput.addEventListener('change', L.Rotate.displayLayersBounds.bind(this));
198
+ padInput.addEventListener('mousemove', L.Rotate.displayLayersBounds.bind(this));
197
199
  padInput.addEventListener('change', L.Rotate.displayPixelBounds.bind(this));
198
200
  padInput.addEventListener('mousemove', L.Rotate.displayPixelBounds.bind(this));
199
201
 
@@ -203,6 +205,7 @@ L.Rotate = {
203
205
  map.on('rotate', this.updatePivotDot);
204
206
  map.on('moveend zoomend resetview rotate', this.displayCenter.bind(this));
205
207
  map.on('moveend zoomend resetview rotate', this.displayBounds.bind(this));
208
+ map.on('moveend zoomend resetview rotate', this.displayLayersBounds.bind(this));
206
209
  map.on('moveend zoomend resetview rotate', this.displayPixelBounds.bind(this));
207
210
 
208
211
  this.updatePixelOrigin.call(map);
@@ -210,6 +213,7 @@ L.Rotate = {
210
213
  this.updatePivotDot.call(map);
211
214
  this.displayCenter.call(this);
212
215
  this.displayBounds.call(this);
216
+ this.displayLayersBounds.call(this);
213
217
  this.displayPixelBounds.call(this);
214
218
 
215
219
  if (L.Browser.mobile) {
@@ -252,20 +256,24 @@ L.Rotate = {
252
256
  * Debug L.Map._pixelOrigin
253
257
  */
254
258
  updatePixelOrigin: function() {
259
+ if (this._pixelOrigin) {
255
260
  document.getElementById('ogx').innerHTML = this._pixelOrigin.x;
256
261
  document.getElementById('ogy').innerHTML = this._pixelOrigin.y;
257
262
  this.___rotatePixelOrigin.style.left = (-this._pixelOrigin.x - 1) + 'px';
258
263
  this.___rotatePixelOrigin.style.top = (-this._pixelOrigin.y - 1) + 'px';
264
+ }
259
265
  },
260
266
 
261
267
  /**
262
268
  * Debug L.Map._pivot
263
269
  */
264
270
  updatePivotDot: function() {
271
+ if (this._pivot) {
265
272
  document.getElementById('pvx').innerHTML = this._pivot.x;
266
273
  document.getElementById('pvy').innerHTML = this._pivot.y;
267
274
  this.___rotatePivotDot.style.left = (this._pivot.x - 1) + 'px';
268
275
  this.___rotatePivotDot.style.top = (this._pivot.y - 1) + 'px';
276
+ }
269
277
  },
270
278
 
271
279
  /**
@@ -330,7 +338,7 @@ L.Rotate = {
330
338
  var lngSpan = northEast.lng - southWest.lng;
331
339
  var latSpan = northEast.lat - southWest.lat;
332
340
  var m = L.marker( L.latLng(southWest.lat + latSpan * Math.random(), southWest.lng + lngSpan * Math.random()) );
333
- m.addTo(L.Rotate._map);
341
+ // m.addTo(L.Rotate._map);
334
342
  L.Rotate.___cluster.addLayer(m);
335
343
  }
336
344
  }
@@ -381,6 +389,7 @@ L.Rotate = {
381
389
  if (this.___bounds) {
382
390
  this.___bounds.remove();
383
391
  }
392
+
384
393
  var padding = document.getElementById('pad_input').valueAsNumber;
385
394
  var latLngBounds = map.getBounds().pad(padding)
386
395
  this.___bounds = L.rectangle(latLngBounds, {
@@ -393,6 +402,35 @@ L.Rotate = {
393
402
  }).addTo(map);
394
403
  },
395
404
 
405
+ /**
406
+ * DEBUG: map.flyToBounds(path.getBounds())
407
+ */
408
+ displayLayersBounds: function() {
409
+ for (const flytopath of ['path', 'polygon', 'circle']) {
410
+ if (!globalThis[flytopath]) {
411
+ continue;
412
+ } else if (this[`___${flytopath}bounds`]) {
413
+ this[`___${flytopath}bounds`].remove();
414
+ }
415
+ let layer = globalThis[flytopath];
416
+ let layerBounds = layer.getBounds();
417
+ this[`___${flytopath}bounds`] = L.featureGroup([
418
+ L.rectangle(layerBounds, {
419
+ fill: false,
420
+ lineCap: 'square',
421
+ color: 'yellow',
422
+ dashArray: '5, 10',
423
+ weight: 1,
424
+ opacity: 0.5
425
+ }),
426
+ L.marker(layerBounds.getNorthWest(), { scale: 0.5, rotation: -45 * L.DomUtil.DEG_TO_RAD, rotateWithView: true }).bindTooltip('<b>NW</b>', {direction: 'center'}),
427
+ L.marker(layerBounds.getNorthEast(), { scale: 0.5, rotation: 45 * L.DomUtil.DEG_TO_RAD, rotateWithView: true }).bindTooltip('<b>NE</b>', {direction: 'center'}),
428
+ L.marker(layerBounds.getSouthEast(), { scale: 0.5, rotation: 135 * L.DomUtil.DEG_TO_RAD, rotateWithView: true }).bindTooltip('<b>SE</b>', {direction: 'center'}),
429
+ L.marker(layerBounds.getSouthWest(), { scale: 0.5, rotation: -135 * L.DomUtil.DEG_TO_RAD, rotateWithView: true }).bindTooltip('<b>SW</b>', {direction: 'center'}),
430
+ ]).addTo(map).eachLayer(m => { if (m.getElement && m.getElement()) m.getElement().style.filter = 'hue-rotate(150deg)'; });
431
+ }
432
+ },
433
+
396
434
  /**
397
435
  * @TODO Debug L.Map.getPixelBounds()
398
436
  */
@@ -410,9 +448,9 @@ L.Rotate = {
410
448
  const BR = L.point(rect).add(L.point(rect.width, rect.height))
411
449
  const BL = L.point(rect).add(L.point(0, rect.height));
412
450
 
413
- const topLeft = L.marker( map.containerPointToLatLng(TL), { title: 'Top Left corner', rotation: 135 * L.DomUtil.DEG_TO_RAD } );
414
- const topRight = L.marker( map.containerPointToLatLng(TR), { title: 'Top Right corner', rotation: -135 * L.DomUtil.DEG_TO_RAD } );
415
- const bottomRight = L.marker( map.containerPointToLatLng(BR), { title: 'Bottom Right corner', rotation: -45 * L.DomUtil.DEG_TO_RAD } );
451
+ const topLeft = L.marker( map.containerPointToLatLng(TL), { title: 'Top Left corner', rotation: -45 * L.DomUtil.DEG_TO_RAD } );
452
+ const topRight = L.marker( map.containerPointToLatLng(TR), { title: 'Top Right corner', rotation: 45 * L.DomUtil.DEG_TO_RAD } );
453
+ const bottomRight = L.marker( map.containerPointToLatLng(BR), { title: 'Bottom Right corner', rotation: 135 * L.DomUtil.DEG_TO_RAD } );
416
454
  const bottomLeft = L.marker( map.containerPointToLatLng(BL), { title: 'Bottom Left corner', rotation: -135 * L.DomUtil.DEG_TO_RAD } );
417
455
 
418
456
  this.___corners = L.featureGroup([topLeft, topRight, bottomRight, bottomLeft]).addTo(map).eachLayer(marker => marker.getElement().style.filter = 'hue-rotate(150deg)');
package/lib/debug.min.js CHANGED
@@ -1 +1 @@
1
- L.Rotate={debug:function(map,options={}){this._map=map,document.head.insertAdjacentHTML("beforeend","<style>\n .leaflet-rotate-info {\n width: 100%;\n }\n .leaflet-rotate-info td {\n /* width: 7em; */\n overflow: hidden;\n /* max-width: 7em; */\n text-overflow: ellipsis;\n /* white-space: nowrap; */\n }\n .leaflet-rotate-info td:nth-of-type(3) {\n font-family: Monospace;\n }\n .leaflet-rotate-info th {\n text-align: left;\n }\n div.crosshair {\n position:absolute;\n width:1px;\n height:1px;\n border: 1px solid green;\n z-index: 100;\n left: 50%;\n right: 50%;\n }\n div.pivot {\n position:absolute;\n width:1px;\n height:1px;\n border: 5px solid yellow;\n border-radius: 100%;\n z-index: 1000;\n }\n div.pixelorigin {\n position: absolute;\n width: 1px;\n height: 1px;\n border: 5px solid yellow;\n border-radius: 100%;\n z-index: 1000;\n }\n div.pivot:before {\n left: -1.5em;\n bottom: -2em;\n position: absolute;\n content: 'PIVOT';\n color: yellow;\n }\n div.pixelorigin:before {\n left: -1.75em;\n top: -2em;\n position: absolute;\n content: 'ORIGIN';\n color: yellow;\n }\n div.panebounds.main {\n position:absolute;\n width:800px;\n height:600px;\n border: 1px solid red;\n border-bottom: 1px red dashed;\n border-right: 1px red dashed;\n z-index: 100;\n }\n div.panebounds.rotate {\n position:absolute;\n width:800px;\n height:600px;\n border: 1px solid purple;\n border-bottom: 1px purple dashed;\n border-right: 1px purple dashed;\n z-index: 100;\n }\n div.crosshair.c1 {\n left:calc(50% - 5px);\n top:50%;\n height: 0;\n width: 10px;\n }\n div.crosshair.c2 {\n left:50%;\n top:calc(50% - 5px);\n width: 0;\n height: 10px;\n }\n #rho_input {\n vertical-align: middle;\n }\n .panebounds:before {\n padding: 1ch;\n }\n .panebounds.rotate:before {\n float: right;\n content: 'ROTATED';\n }\n .panebounds.main:before {\n float: left;\n content: 'MAIN';\n }\n </style>"),map._container.insertAdjacentHTML("afterbegin",'<div class="crosshair c1"></div><div class="crosshair c2"></div>'),map._container.insertAdjacentHTML("afterend",'<hr>\n <table class="leaflet-rotate-info">\n <tr>\n <td>\n <button onclick="L.Rotate._map.setBearing(0);" title="map.setBearing(0);"> 0</button>\n <button onclick="L.Rotate._map.setBearing(15);" title="map.setBearing(15);">15</button>\n <button onclick="L.Rotate._map.setBearing(30);" title="map.setBearing(30);">30</button>\n <button onclick="L.Rotate._map.setBearing(45);" title="map.setBearing(45);">45</button>\n <button onclick="L.Rotate._map.setBearing(60);" title="map.setBearing(60);">60</button>\n <button onclick="L.Rotate._map.setBearing(75);" title="map.setBearing(75);">75</button>\n <button onclick="L.Rotate._map.setBearing(90);" title="map.setBearing(90);">90</button>\n <button onclick="L.Rotate._map.setBearing(180);" title="map.setBearing(180);">180</button>\n </td>\n <td>\n <input title="increase/decrease rotation angle" type="range" min="0" max="360" step="1" value="0" name="rho" id=\'rho_input\' /><span id=\'rho\'></span>\n </td>\n <td>\n <input title="increase/decrease padding bounds" type="range" min="-0.25" max="0" value="0" step="0.01" name="pad" id=\'pad_input\' />\n </td>\n <td>\n <button onclick="L.Rotate.randomRotateMarkers(L.Rotate._map);" title="markers.setRotation(Math.random() * Math.PI / 30 + 0.1)">Rotate Markers</button>\n <button onclick="L.Rotate.randomMarkers(L.Rotate._map, 100);" title="add 100 random markers to map">Add Markers</button>\n </td>\n </tr>\n <tr>\n <th>LatLng </th>\n <td id=\'llx\'></td>\n <td id=\'lly\'></td>\n <td class=\'long\'>LatLng of mouse pointer</td>\n </tr>\n <tr>\n <th>Rel to pane </th>\n <td id=\'lyx\'></td>\n <td id=\'lyy\'></td>\n <td class=\'long\'>Mouse pointer pixel coords relative to _rotatePane</td>\n </tr>\n <tr>\n <th>Rel to container</th>\n <td id=\'cnx\'></td>\n <td id=\'cny\'></td>\n <td class=\'long\'>Mouse pointer coords relative to map &lt;div&gt;</td>\n </tr>\n <tr>\n <th>Pivot </th>\n <td id=\'pvx\'></td>\n <td id=\'pvy\'></td>\n <td class=\'long\'>Last _rotationPane pivot pixel coords relative to _rotationPane</td>\n </tr>\n <tr>\n <th>Pane offset </th>\n <td id=\'pox\'></td>\n <td id=\'poy\'></td>\n <td class=\'long\'>Pixel offset of _mapPane</td>\n </tr>\n <tr>\n <th>Pixel origin </th>\n <td id=\'ogx\'></td>\n <td id=\'ogy\'></td>\n <td class=\'long\'>Negative pixel coords of the (0,0) CRS point relative to _rotatePane</td>\n </tr>\n <tr>\n <th>Pixel bounds </th>\n <td id=\'ogbx\'></td>\n <td id=\'ogby\'></td>\n <td class=\'long\'>Bounds of the current map view in projected pixel coordinates {min, max}.</td>\n </tr>\n </table>'),map.___rotatePixelOrigin=L.DomUtil.create("div","pixelorigin",map._rotatePane),map.___rotatePivotDot=L.DomUtil.create("div","pivot",map._mapPane),L.DomUtil.create("div","panebounds rotate",map._rotatePane),L.DomUtil.create("div","panebounds main",map._mapPane);var rhoInput=document.getElementById("rho_input"),padInput=document.getElementById("pad_input");rhoInput.addEventListener("change",L.Rotate.rotate.bind(this)),rhoInput.addEventListener("mousemove",L.Rotate.rotate.bind(this)),padInput.addEventListener("change",L.Rotate.displayCenter.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayCenter.bind(this)),padInput.addEventListener("change",L.Rotate.displayBounds.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayBounds.bind(this)),padInput.addEventListener("change",L.Rotate.displayPixelBounds.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayPixelBounds.bind(this)),map.on("move rotate zoomend",this.updatePanePos),map.on("rotate zoomend load",this.updatePixelOrigin),map.on("rotate",this.updateRhoInput),map.on("rotate",this.updatePivotDot),map.on("moveend zoomend resetview rotate",this.displayCenter.bind(this)),map.on("moveend zoomend resetview rotate",this.displayBounds.bind(this)),map.on("moveend zoomend resetview rotate",this.displayPixelBounds.bind(this)),this.updatePixelOrigin.call(map),this.updateRhoInput.call(map),this.updatePivotDot.call(map),this.displayCenter.call(this),this.displayBounds.call(this),this.displayPixelBounds.call(this),L.Browser.mobile&&map.compassBearing.enable(),map.on("mousemove",this.logMouse),map.on("locationfound",this.resetHeading),options.log&&map.on("click movestart move moveend zoomstart zoomend locationfound locationerror locationfound",this.logEvent)},logEvent:function(e){console.log(e,e.type)},logMouse:function(e){document.getElementById("llx").innerHTML=e.latlng.lng,document.getElementById("lly").innerHTML=e.latlng.lat,document.getElementById("lyx").innerHTML=e.layerPoint.x,document.getElementById("lyy").innerHTML=e.layerPoint.y,document.getElementById("cnx").innerHTML=e.containerPoint.x,document.getElementById("cny").innerHTML=e.containerPoint.y},rotate:function(e){return 0!==e.buttons&&this._map.setBearing(e.target.valueAsNumber)},updatePixelOrigin:function(){document.getElementById("ogx").innerHTML=this._pixelOrigin.x,document.getElementById("ogy").innerHTML=this._pixelOrigin.y,this.___rotatePixelOrigin.style.left=-this._pixelOrigin.x-1+"px",this.___rotatePixelOrigin.style.top=-this._pixelOrigin.y-1+"px"},updatePivotDot:function(){document.getElementById("pvx").innerHTML=this._pivot.x,document.getElementById("pvy").innerHTML=this._pivot.y,this.___rotatePivotDot.style.left=this._pivot.x-1+"px",this.___rotatePivotDot.style.top=this._pivot.y-1+"px"},updatePanePos:function(){var panePos=this._getMapPanePos();document.getElementById("pox").innerHTML=panePos.x,document.getElementById("poy").innerHTML=panePos.y},updateRhoInput:function(){document.getElementById("rho_input").value=this.getBearing()},rotateOneDegree:function(){var angle=document.getElementById("rho_input").valueAsNumber++;this.setBearing(angle<360?angle:0)},randomRotateMarkers:function(map){var markers=[],steps=[];for(var i in map._layers)map._layers[i]instanceof L.Marker&&(markers.push(map._layers[i]),steps.push(Math.random()*Math.PI/30+.1));function stepOn(steps_left){for(var i=0;i<markers.length;i++)markers[i].setRotation(markers[i].options.rotation+steps[i]);--steps_left&&setTimeout(stepOn.bind(null,steps_left),20)}stepOn(25)},randomMarkers:function(map,number){var map=this._map,populate=function(){for(var i=0;i<number;i++){var bounds=map.getBounds(),southWest=bounds.getSouthWest(),northEast=bounds.getNorthEast(),lngSpan=northEast.lng-southWest.lng,latSpan=northEast.lat-southWest.lat,m=L.marker(L.latLng(southWest.lat+latSpan*Math.random(),southWest.lng+lngSpan*Math.random()));m.addTo(L.Rotate._map),L.Rotate.___cluster.addLayer(m)}};this.___cluster?"function"==typeof L.markerClusterGroup&&populate():this.___cluster=import("https://unpkg.com/leaflet.markercluster@1.4.1/src/index.js").then(m=>{document.head.insertAdjacentHTML("beforeend",'\n \x3c!-- Leaflet-MarkerCluster --\x3e\n <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.css">\n <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css">\n '),Object.assign(globalThis.L,m),this.___cluster=L.markerClusterGroup({spiderfyOnMaxZoom:!1,showCoverageOnHover:!1,zoomToBoundsOnClick:!1}).on("clusterclick",a=>a.layer.spiderfy()).addTo(map),populate()})},displayCenter:function(){var map=this._map;this.___centerMarker&&this.___centerMarker.remove(),this.___centerMarker=L.circleMarker(map.getCenter(),{radius:3,color:"red"}).addTo(map).bindTooltip("<b>center</b>",{direction:"right",permanent:!0}),this.___centerMarker.getTooltip().getElement().setAttribute("tabindex","-1")},displayBounds:function(){var map=this._map;this.___bounds&&this.___bounds.remove();var padding=document.getElementById("pad_input").valueAsNumber,latLngBounds=map.getBounds().pad(padding);this.___bounds=L.rectangle(latLngBounds,{fill:!1,lineCap:"square",color:"yellow",dashArray:"5, 10",weight:2}).addTo(map)},displayPixelBounds:function(){var map=this._map;this.___corners&&this.___corners.remove(),this.___pixelbounds&&this.___pixelbounds.remove();const size=map.getSize(),rect=map._container.getBoundingClientRect(),pixelBounds=map.getPixelBounds(),TL=L.point(rect),TR=L.point(rect).add(L.point(rect.width,0)),BR=L.point(rect).add(L.point(rect.width,rect.height)),BL=L.point(rect).add(L.point(0,rect.height)),topLeft=L.marker(map.containerPointToLatLng(TL),{title:"Top Left corner",rotation:135*L.DomUtil.DEG_TO_RAD}),topRight=L.marker(map.containerPointToLatLng(TR),{title:"Top Right corner",rotation:-135*L.DomUtil.DEG_TO_RAD}),bottomRight=L.marker(map.containerPointToLatLng(BR),{title:"Bottom Right corner",rotation:-45*L.DomUtil.DEG_TO_RAD}),bottomLeft=L.marker(map.containerPointToLatLng(BL),{title:"Bottom Left corner",rotation:-135*L.DomUtil.DEG_TO_RAD});this.___corners=L.featureGroup([topLeft,topRight,bottomRight,bottomLeft]).addTo(map).eachLayer(marker=>marker.getElement().style.filter="hue-rotate(150deg)"),document.getElementById("ogbx").innerHTML=JSON.stringify(pixelBounds.min),document.getElementById("ogby").innerHTML=JSON.stringify(pixelBounds.max)},resetHeading:function(e){null!==e.heading&&this.setBearing(e.heading)},locate:function(){this._map.locate({setView:!0,enableHighAccuracy:!0})}};
1
+ L.Rotate={debug:function(map,options={}){this._map=map,document.head.insertAdjacentHTML("beforeend","<style>\n .leaflet-rotate-info {\n width: 100%;\n }\n .leaflet-rotate-info td {\n /* width: 7em; */\n overflow: hidden;\n /* max-width: 7em; */\n text-overflow: ellipsis;\n /* white-space: nowrap; */\n }\n .leaflet-rotate-info td:nth-of-type(3) {\n font-family: Monospace;\n }\n .leaflet-rotate-info th {\n text-align: left;\n }\n div.crosshair {\n position:absolute;\n width:1px;\n height:1px;\n border: 1px solid green;\n z-index: 100;\n left: 50%;\n right: 50%;\n }\n div.pivot {\n position:absolute;\n width:1px;\n height:1px;\n border: 5px solid yellow;\n border-radius: 100%;\n z-index: 1000;\n }\n div.pixelorigin {\n position: absolute;\n width: 1px;\n height: 1px;\n border: 5px solid yellow;\n border-radius: 100%;\n z-index: 1000;\n }\n div.pivot:before {\n left: -1.5em;\n bottom: -2em;\n position: absolute;\n content: 'PIVOT';\n color: yellow;\n }\n div.pixelorigin:before {\n left: -1.75em;\n top: -2em;\n position: absolute;\n content: 'ORIGIN';\n color: yellow;\n }\n div.panebounds.main {\n position:absolute;\n width:800px;\n height:600px;\n border: 1px solid red;\n border-bottom: 1px red dashed;\n border-right: 1px red dashed;\n z-index: 100;\n }\n div.panebounds.rotate {\n position:absolute;\n width:800px;\n height:600px;\n border: 1px solid purple;\n border-bottom: 1px purple dashed;\n border-right: 1px purple dashed;\n z-index: 100;\n }\n div.crosshair.c1 {\n left:calc(50% - 5px);\n top:50%;\n height: 0;\n width: 10px;\n }\n div.crosshair.c2 {\n left:50%;\n top:calc(50% - 5px);\n width: 0;\n height: 10px;\n }\n #rho_input {\n vertical-align: middle;\n }\n .panebounds:before {\n padding: 1ch;\n }\n .panebounds.rotate:before {\n float: right;\n content: 'ROTATED';\n }\n .panebounds.main:before {\n float: left;\n content: 'MAIN';\n }\n </style>"),map._container.insertAdjacentHTML("afterbegin",'<div class="crosshair c1"></div><div class="crosshair c2"></div>'),map._container.insertAdjacentHTML("afterend",'<hr>\n <table class="leaflet-rotate-info">\n <tr>\n <td>\n <button onclick="L.Rotate._map.setBearing(0);" title="map.setBearing(0);"> 0</button>\n <button onclick="L.Rotate._map.setBearing(15);" title="map.setBearing(15);">15</button>\n <button onclick="L.Rotate._map.setBearing(30);" title="map.setBearing(30);">30</button>\n <button onclick="L.Rotate._map.setBearing(45);" title="map.setBearing(45);">45</button>\n <button onclick="L.Rotate._map.setBearing(60);" title="map.setBearing(60);">60</button>\n <button onclick="L.Rotate._map.setBearing(75);" title="map.setBearing(75);">75</button>\n <button onclick="L.Rotate._map.setBearing(90);" title="map.setBearing(90);">90</button>\n <button onclick="L.Rotate._map.setBearing(180);" title="map.setBearing(180);">180</button>\n </td>\n <td>\n <input title="increase/decrease rotation angle" type="range" min="0" max="360" step="1" value="0" name="rho" id=\'rho_input\' /><span id=\'rho\'></span>\n </td>\n <td>\n <input title="increase/decrease padding bounds" type="range" min="-0.25" max="0" value="0" step="0.01" name="pad" id=\'pad_input\' />\n </td>\n <td>\n <button onclick="L.Rotate.randomRotateMarkers(L.Rotate._map);" title="markers.setRotation(Math.random() * Math.PI / 30 + 0.1)">Rotate Markers</button>\n <button onclick="L.Rotate.randomMarkers(L.Rotate._map, 100);" title="add 100 random markers to map">Add Markers</button>\n </td>\n </tr>\n <tr>\n <th>LatLng </th>\n <td id=\'llx\'></td>\n <td id=\'lly\'></td>\n <td class=\'long\'>LatLng of mouse pointer</td>\n </tr>\n <tr>\n <th>Rel to pane </th>\n <td id=\'lyx\'></td>\n <td id=\'lyy\'></td>\n <td class=\'long\'>Mouse pointer pixel coords relative to _rotatePane</td>\n </tr>\n <tr>\n <th>Rel to container</th>\n <td id=\'cnx\'></td>\n <td id=\'cny\'></td>\n <td class=\'long\'>Mouse pointer coords relative to map &lt;div&gt;</td>\n </tr>\n <tr>\n <th>Pivot </th>\n <td id=\'pvx\'></td>\n <td id=\'pvy\'></td>\n <td class=\'long\'>Last _rotationPane pivot pixel coords relative to _rotationPane</td>\n </tr>\n <tr>\n <th>Pane offset </th>\n <td id=\'pox\'></td>\n <td id=\'poy\'></td>\n <td class=\'long\'>Pixel offset of _mapPane</td>\n </tr>\n <tr>\n <th>Pixel origin </th>\n <td id=\'ogx\'></td>\n <td id=\'ogy\'></td>\n <td class=\'long\'>Negative pixel coords of the (0,0) CRS point relative to _rotatePane</td>\n </tr>\n <tr>\n <th>Pixel bounds </th>\n <td id=\'ogbx\'></td>\n <td id=\'ogby\'></td>\n <td class=\'long\'>Bounds of the current map view in projected pixel coordinates {min, max}.</td>\n </tr>\n </table>'),map.___rotatePixelOrigin=L.DomUtil.create("div","pixelorigin",map._rotatePane),map.___rotatePivotDot=L.DomUtil.create("div","pivot",map._mapPane),L.DomUtil.create("div","panebounds rotate",map._rotatePane),L.DomUtil.create("div","panebounds main",map._mapPane);var rhoInput=document.getElementById("rho_input"),padInput=document.getElementById("pad_input");rhoInput.addEventListener("change",L.Rotate.rotate.bind(this)),rhoInput.addEventListener("mousemove",L.Rotate.rotate.bind(this)),padInput.addEventListener("change",L.Rotate.displayCenter.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayCenter.bind(this)),padInput.addEventListener("change",L.Rotate.displayBounds.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayBounds.bind(this)),padInput.addEventListener("change",L.Rotate.displayLayersBounds.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayLayersBounds.bind(this)),padInput.addEventListener("change",L.Rotate.displayPixelBounds.bind(this)),padInput.addEventListener("mousemove",L.Rotate.displayPixelBounds.bind(this)),map.on("move rotate zoomend",this.updatePanePos),map.on("rotate zoomend load",this.updatePixelOrigin),map.on("rotate",this.updateRhoInput),map.on("rotate",this.updatePivotDot),map.on("moveend zoomend resetview rotate",this.displayCenter.bind(this)),map.on("moveend zoomend resetview rotate",this.displayBounds.bind(this)),map.on("moveend zoomend resetview rotate",this.displayLayersBounds.bind(this)),map.on("moveend zoomend resetview rotate",this.displayPixelBounds.bind(this)),this.updatePixelOrigin.call(map),this.updateRhoInput.call(map),this.updatePivotDot.call(map),this.displayCenter.call(this),this.displayBounds.call(this),this.displayLayersBounds.call(this),this.displayPixelBounds.call(this),L.Browser.mobile&&map.compassBearing.enable(),map.on("mousemove",this.logMouse),map.on("locationfound",this.resetHeading),options.log&&map.on("click movestart move moveend zoomstart zoomend locationfound locationerror locationfound",this.logEvent)},logEvent:function(e){console.log(e,e.type)},logMouse:function(e){document.getElementById("llx").innerHTML=e.latlng.lng,document.getElementById("lly").innerHTML=e.latlng.lat,document.getElementById("lyx").innerHTML=e.layerPoint.x,document.getElementById("lyy").innerHTML=e.layerPoint.y,document.getElementById("cnx").innerHTML=e.containerPoint.x,document.getElementById("cny").innerHTML=e.containerPoint.y},rotate:function(e){return 0!==e.buttons&&this._map.setBearing(e.target.valueAsNumber)},updatePixelOrigin:function(){this._pixelOrigin&&(document.getElementById("ogx").innerHTML=this._pixelOrigin.x,document.getElementById("ogy").innerHTML=this._pixelOrigin.y,this.___rotatePixelOrigin.style.left=-this._pixelOrigin.x-1+"px",this.___rotatePixelOrigin.style.top=-this._pixelOrigin.y-1+"px")},updatePivotDot:function(){this._pivot&&(document.getElementById("pvx").innerHTML=this._pivot.x,document.getElementById("pvy").innerHTML=this._pivot.y,this.___rotatePivotDot.style.left=this._pivot.x-1+"px",this.___rotatePivotDot.style.top=this._pivot.y-1+"px")},updatePanePos:function(){var panePos=this._getMapPanePos();document.getElementById("pox").innerHTML=panePos.x,document.getElementById("poy").innerHTML=panePos.y},updateRhoInput:function(){document.getElementById("rho_input").value=this.getBearing()},rotateOneDegree:function(){var angle=document.getElementById("rho_input").valueAsNumber++;this.setBearing(angle<360?angle:0)},randomRotateMarkers:function(map){var markers=[],steps=[];for(var i in map._layers)map._layers[i]instanceof L.Marker&&(markers.push(map._layers[i]),steps.push(Math.random()*Math.PI/30+.1));function stepOn(steps_left){for(var i=0;i<markers.length;i++)markers[i].setRotation(markers[i].options.rotation+steps[i]);--steps_left&&setTimeout(stepOn.bind(null,steps_left),20)}stepOn(25)},randomMarkers:function(map,number){var map=this._map,populate=function(){for(var i=0;i<number;i++){var bounds=map.getBounds(),southWest=bounds.getSouthWest(),northEast=bounds.getNorthEast(),lngSpan=northEast.lng-southWest.lng,latSpan=northEast.lat-southWest.lat,m=L.marker(L.latLng(southWest.lat+latSpan*Math.random(),southWest.lng+lngSpan*Math.random()));L.Rotate.___cluster.addLayer(m)}};this.___cluster?"function"==typeof L.markerClusterGroup&&populate():this.___cluster=import("https://unpkg.com/leaflet.markercluster@1.4.1/src/index.js").then(m=>{document.head.insertAdjacentHTML("beforeend",'\n \x3c!-- Leaflet-MarkerCluster --\x3e\n <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.css">\n <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css">\n '),Object.assign(globalThis.L,m),this.___cluster=L.markerClusterGroup({spiderfyOnMaxZoom:!1,showCoverageOnHover:!1,zoomToBoundsOnClick:!1}).on("clusterclick",a=>a.layer.spiderfy()).addTo(map),populate()})},displayCenter:function(){var map=this._map;this.___centerMarker&&this.___centerMarker.remove(),this.___centerMarker=L.circleMarker(map.getCenter(),{radius:3,color:"red"}).addTo(map).bindTooltip("<b>center</b>",{direction:"right",permanent:!0}),this.___centerMarker.getTooltip().getElement().setAttribute("tabindex","-1")},displayBounds:function(){var map=this._map;this.___bounds&&this.___bounds.remove();var padding=document.getElementById("pad_input").valueAsNumber,latLngBounds=map.getBounds().pad(padding);this.___bounds=L.rectangle(latLngBounds,{fill:!1,lineCap:"square",color:"yellow",dashArray:"5, 10",weight:2}).addTo(map)},displayLayersBounds:function(){for(const flytopath of["path","polygon","circle"]){if(!globalThis[flytopath])continue;this[`___${flytopath}bounds`]&&this[`___${flytopath}bounds`].remove();let layer,layerBounds=globalThis[flytopath].getBounds();this[`___${flytopath}bounds`]=L.featureGroup([L.rectangle(layerBounds,{fill:!1,lineCap:"square",color:"yellow",dashArray:"5, 10",weight:1,opacity:.5}),L.marker(layerBounds.getNorthWest(),{scale:.5,rotation:-45*L.DomUtil.DEG_TO_RAD,rotateWithView:!0}).bindTooltip("<b>NW</b>",{direction:"center"}),L.marker(layerBounds.getNorthEast(),{scale:.5,rotation:45*L.DomUtil.DEG_TO_RAD,rotateWithView:!0}).bindTooltip("<b>NE</b>",{direction:"center"}),L.marker(layerBounds.getSouthEast(),{scale:.5,rotation:135*L.DomUtil.DEG_TO_RAD,rotateWithView:!0}).bindTooltip("<b>SE</b>",{direction:"center"}),L.marker(layerBounds.getSouthWest(),{scale:.5,rotation:-135*L.DomUtil.DEG_TO_RAD,rotateWithView:!0}).bindTooltip("<b>SW</b>",{direction:"center"})]).addTo(map).eachLayer(m=>{m.getElement&&m.getElement()&&(m.getElement().style.filter="hue-rotate(150deg)")})}},displayPixelBounds:function(){var map=this._map;this.___corners&&this.___corners.remove(),this.___pixelbounds&&this.___pixelbounds.remove();const size=map.getSize(),rect=map._container.getBoundingClientRect(),pixelBounds=map.getPixelBounds(),TL=L.point(rect),TR=L.point(rect).add(L.point(rect.width,0)),BR=L.point(rect).add(L.point(rect.width,rect.height)),BL=L.point(rect).add(L.point(0,rect.height)),topLeft=L.marker(map.containerPointToLatLng(TL),{title:"Top Left corner",rotation:-45*L.DomUtil.DEG_TO_RAD}),topRight=L.marker(map.containerPointToLatLng(TR),{title:"Top Right corner",rotation:45*L.DomUtil.DEG_TO_RAD}),bottomRight=L.marker(map.containerPointToLatLng(BR),{title:"Bottom Right corner",rotation:135*L.DomUtil.DEG_TO_RAD}),bottomLeft=L.marker(map.containerPointToLatLng(BL),{title:"Bottom Left corner",rotation:-135*L.DomUtil.DEG_TO_RAD});this.___corners=L.featureGroup([topLeft,topRight,bottomRight,bottomLeft]).addTo(map).eachLayer(marker=>marker.getElement().style.filter="hue-rotate(150deg)"),document.getElementById("ogbx").innerHTML=JSON.stringify(pixelBounds.min),document.getElementById("ogby").innerHTML=JSON.stringify(pixelBounds.max)},resetHeading:function(e){null!==e.heading&&this.setBearing(e.heading)},locate:function(){this._map.locate({setView:!0,enableHighAccuracy:!0})}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leaflet-rotate",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A Leaflet plugin that allows to add rotation functionality to map tiles",
5
5
  "type": "module",
6
6
  "main": "dist/leaflet-rotate.js",
@@ -13,7 +13,7 @@ L.extend(L.DomUtil, {
13
13
 
14
14
  if (!bearing) {
15
15
  offset = pos._round();
16
- return domUtilProto.setTransform.call(this, el, offset, scale);
16
+ return domUtilProto.setTransform.apply(this, arguments);
17
17
  }
18
18
 
19
19
  pos = pos.rotateFrom(bearing, pivot);
@@ -24,9 +24,9 @@ L.extend(L.DomUtil, {
24
24
  ' rotate(' + bearing + 'rad)';
25
25
  },
26
26
 
27
- setPosition: function(el, point, bearing, pivot) { // (HTMLElement, Point[, Boolean])
27
+ setPosition: function(el, point, bearing, pivot, scale) { // (HTMLElement, Point[, Boolean])
28
28
  if (!bearing) {
29
- return domUtilProto.setPosition.call(this, el, point);
29
+ return domUtilProto.setPosition.apply(this, arguments);
30
30
  }
31
31
 
32
32
  /*eslint-disable */
@@ -34,7 +34,7 @@ L.extend(L.DomUtil, {
34
34
  /*eslint-enable */
35
35
 
36
36
  if (L.Browser.any3d) {
37
- L.DomUtil.setTransform(el, point, undefined, bearing, pivot);
37
+ L.DomUtil.setTransform(el, point, scale, bearing, pivot);
38
38
  } else {
39
39
  el.style.left = point.x + 'px';
40
40
  el.style.top = point.y + 'px';
@@ -9,12 +9,12 @@ const divOverlayProto = L.extend({}, L.DivOverlay.prototype);
9
9
  L.DivOverlay.include({
10
10
 
11
11
  getEvents: function() {
12
- return L.extend(divOverlayProto.getEvents.call(this), { rotate: this._updatePosition });
12
+ return L.extend(divOverlayProto.getEvents.apply(this, arguments), { rotate: this._updatePosition });
13
13
  },
14
14
 
15
15
  _updatePosition: function() {
16
16
  // 0. update anchor (leaflet v1.9.3)
17
- divOverlayProto._updatePosition.call(this);
17
+ divOverlayProto._updatePosition.apply(this, arguments);
18
18
  // 1. subtract anchor
19
19
  // 2. rotate element
20
20
  // 3. restore anchor
@@ -10,7 +10,7 @@ L.Popup.include({
10
10
 
11
11
  _animateZoom: function(e) {
12
12
  // 0. update anchor (leaflet v1.9.3)
13
- popupProto._animateZoom.call(this, e);
13
+ popupProto._animateZoom.apply(this, arguments);
14
14
  // 1. subtract anchor
15
15
  // 2. rotate element
16
16
  // 3. restore anchor
@@ -10,7 +10,7 @@ L.Tooltip.include({
10
10
 
11
11
  _animateZoom: function(e) {
12
12
  if (!this._map._rotate) {
13
- return tooltipProto._animateZoom.call(this, e);
13
+ return tooltipProto._animateZoom.apply(this, arguments);
14
14
  }
15
15
  var pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
16
16
 
@@ -20,7 +20,7 @@ L.Tooltip.include({
20
20
 
21
21
  _updatePosition: function() {
22
22
  if (!this._map._rotate) {
23
- return tooltipProto._updatePosition.call(this);
23
+ return tooltipProto._updatePosition.apply(this, arguments);
24
24
  }
25
25
  var pos = this._map.latLngToLayerPoint(this._latlng);
26
26
 
@@ -17,6 +17,10 @@ L.Marker.mergeOptions({
17
17
  // Rotate this marker when map rotates
18
18
  rotateWithView: false,
19
19
 
20
+ // @option scale: Number = undefined
21
+ // Scale of the marker icon
22
+ scale: undefined,
23
+
20
24
  });
21
25
 
22
26
  var markerDragProto; // retrived at runtime (see below: L.Marker::_initInteraction())
@@ -25,7 +29,7 @@ var MarkerDrag = {
25
29
 
26
30
  // _onDragStart: function() {
27
31
  // if (!this._marker._map._rotate) {
28
- // return markerDragProto._onDragStart.call(this)
32
+ // return markerDragProto._onDragStart.apply(this, arguments);
29
33
  // }
30
34
  // this._draggable.updateMapBearing(this._marker._map._bearing);
31
35
  // },
@@ -68,7 +72,7 @@ var MarkerDrag = {
68
72
  if (this._marker._map._rotate) {
69
73
  this._marker.update();
70
74
  }
71
- markerDragProto._onDragEnd.call(this, e);
75
+ markerDragProto._onDragEnd.apply(this, arguments);
72
76
  },
73
77
 
74
78
  };
@@ -76,16 +80,16 @@ var MarkerDrag = {
76
80
  L.Marker.include({
77
81
 
78
82
  getEvents: function() {
79
- return L.extend(markerProto.getEvents.call(this), { rotate: this.update });
83
+ return L.extend(markerProto.getEvents.apply(this, arguments), { rotate: this.update });
80
84
  },
81
85
 
82
86
  onAdd: function(map) {
83
- markerProto.onAdd.call(this, map);
87
+ markerProto.onAdd.apply(this, arguments);
84
88
  map.on('rotate', this.update, this);
85
89
  },
86
90
 
87
91
  _initInteraction: function() {
88
- var ret = markerProto._initInteraction.call(this);
92
+ var ret = markerProto._initInteraction.apply(this, arguments);
89
93
  if (this.dragging && this.dragging.enabled() && this._map && this._map._rotate) {
90
94
  // L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable
91
95
  markerDragProto = markerDragProto || Object.getPrototypeOf(this.dragging);
@@ -115,12 +119,12 @@ L.Marker.include({
115
119
 
116
120
  /** @TODO use markerProto._setPos */
117
121
  if (this._icon) {
118
- L.DomUtil.setPosition(this._icon, pos, bearing, pos);
122
+ L.DomUtil.setPosition(this._icon, pos, bearing, pos, this.options.scale);
119
123
  }
120
124
 
121
125
  /** @TODO use markerProto._setPos */
122
126
  if (this._shadow) {
123
- L.DomUtil.setPosition(this._shadow, pos, bearing, pos);
127
+ L.DomUtil.setPosition(this._shadow, pos, bearing, pos, this.options.scale);
124
128
  }
125
129
 
126
130
  this._zIndex = pos.y + this.options.zIndexOffset;
@@ -130,7 +134,7 @@ L.Marker.include({
130
134
 
131
135
  _updateZIndex: function(offset) {
132
136
  if (!this._map._rotate) {
133
- return markerProto._updateZIndex.call(this, offset)
137
+ return markerProto._updateZIndex.apply(this, arguments);
134
138
  }
135
139
  this._icon.style.zIndex = Math.round(this._zIndex + offset);
136
140
  },
@@ -9,7 +9,7 @@ const gridLayerProto = L.extend({}, L.GridLayer.prototype);
9
9
  L.GridLayer.include({
10
10
 
11
11
  getEvents: function() {
12
- var events = gridLayerProto.getEvents.call(this);
12
+ var events = gridLayerProto.getEvents.apply(this, arguments);
13
13
  if (this._map._rotate && !this.options.updateWhenIdle) {
14
14
  if (!this._onRotate) {
15
15
  this._onRotate = L.Util.throttle(this._onMoveEnd, this.options.updateInterval, this);
@@ -21,7 +21,7 @@ L.GridLayer.include({
21
21
 
22
22
  _getTiledPixelBounds: function(center) {
23
23
  if (!this._map._rotate) {
24
- return gridLayerProto._getTiledPixelBounds.call(this, center);
24
+ return gridLayerProto._getTiledPixelBounds.apply(this, arguments);
25
25
  }
26
26
 
27
27
  return this._map._getNewPixelBounds(center, this._tileZoom);
@@ -9,18 +9,18 @@ const canvasProto = L.extend({}, L.Canvas.prototype);
9
9
  L.Canvas.include({
10
10
 
11
11
  // onAdd: function() {
12
- // canvasProto.onAdd.call(this);
12
+ // canvasProto.onAdd.apply(this, arguments);
13
13
  // // When rotating the canvas itself, it is cleared by some weird reason, so redraw.
14
14
  // this._map.on('rotate', this._redraw, this);
15
15
  // },
16
16
 
17
17
  // onRemove: function() {
18
- // canvasProto.onRemove.call(this);
18
+ // canvasProto.onRemove.apply(this, arguments);
19
19
  // this._map.off('rotate', this._redraw, this);
20
20
  // },
21
21
 
22
22
  // _update: function() {
23
- // canvasProto._update.call(this);
23
+ // canvasProto._update.apply(this, arguments);
24
24
  // // Tell paths to redraw themselves
25
25
  // this.fire('update')
26
26
  // },
@@ -9,12 +9,12 @@ const rendererProto = L.extend({}, L.Renderer.prototype);
9
9
  L.Renderer.include({
10
10
 
11
11
  // onAdd: function() {
12
- // rendererProto.onAdd.call(this);
12
+ // rendererProto.onAdd.apply(this, arguments);
13
13
  // // this._map.on('rotate', this._update, this);
14
14
  // },
15
15
 
16
16
  // onRemove: function() {
17
- // rendererProto.onRemove.call(this);
17
+ // rendererProto.onRemove.apply(this, arguments);
18
18
  // // this._map.off('rotate', this._update, this);
19
19
  // },
20
20
 
@@ -25,7 +25,7 @@ L.Renderer.include({
25
25
  */
26
26
  _updateTransform: function(center, zoom) {
27
27
  if (!this._map._rotate) {
28
- return rendererProto._updateTransform.call(this, center, zoom);
28
+ return rendererProto._updateTransform.apply(this, arguments);
29
29
  }
30
30
  var scale = this._map.getZoomScale(zoom, this._zoom),
31
31
  offset = this._map._latLngToNewLayerPoint(this._topLeft, zoom, center);
@@ -38,7 +38,7 @@ L.Renderer.include({
38
38
 
39
39
  _update: function() {
40
40
  if (!this._map._rotate) {
41
- return rendererProto._update.call(this);
41
+ return rendererProto._update.apply(this, arguments);
42
42
  }
43
43
  // Update pixel bounds of renderer container (for positioning/sizing/clipping later)
44
44
  // Subclasses are responsible of firing the 'update' event.
@@ -9,7 +9,7 @@ const svgProto = L.extend({}, L.SVG.prototype);
9
9
  L.SVG.include({
10
10
 
11
11
  // _update: function() {
12
- // svgProto._update.call(this);
12
+ // svgProto._update.apply(this, arguments);
13
13
  // if (this._map._rotate) {
14
14
  // this.fire('update');
15
15
  // }