28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
L.control.scale().addTo(map);
|
|
function pixelsInOneMeterWidth() {
|
|
var div = document.createElement('div');
|
|
div.id="mesure";
|
|
div.style.cssText = 'position: absolute; left: -100%; top: -100%; width: 100cm';
|
|
document.body.appendChild(div);
|
|
var px = div.offsetWidth;
|
|
document.body.removeChild(div);
|
|
return px;
|
|
}
|
|
|
|
function scaleManage(){
|
|
var pos = map.getCenter();
|
|
var screenWidth = screen.width;
|
|
var wFrameInPx = document.getElementById("map").clientWidth;
|
|
var mapSpan = map.containerPointToLatLng([0, 0]).distanceTo(map.containerPointToLatLng([0, wFrameInPx]));
|
|
var frameInMeter = wFrameInPx/pixelsInOneMeterWidth();
|
|
return [pos,screenWidth,wFrameInPx,mapSpan, pixelsInOneMeterWidth(), frameInMeter, mapSpan/frameInMeter];
|
|
}
|
|
|
|
const widthInMeter = 6378137 * 2 * Math.PI * Math.cos(map.getCenter().lat * Math.PI / 180);
|
|
var scaleOutput = document.getElementById("scaleOutput");
|
|
scaleOutput.innerHTML = widthInMeter;
|
|
map.on('moveend', function(){
|
|
scaleOutput.innerHTML = widthInMeter;
|
|
console.log(widthInMeter);
|
|
console.log(scaleManage());
|
|
});
|