Leaflet pixel size depending on zoom level

I need to display a 5x5 degree pie chart on the flyer map. I can display a pie chart using the large leaflet-dvf library , but I have to provide the radius in a pixel, and so far it is static.

I would like it to be dynamic, so that at any zoom level the pie chart fills a 5x5 square (aka radius = 5x5 degree length).

How to find the length in pixel from the side of the square 5x5 degrees depending on the zoom level?

thank

+4
source share
2 answers

I used the following page, which displays a pixel per meter on the flyer map, depending on the zoom level:

http://wiki.openstreetmap.org/wiki/Zoom_levels

5x5 : 556000 . = 0: $ scope.lengthRatio = 556000/156412// /

, ($ scope.mapZoom):

var radius = $scope.lengthRatio * Math.pow(2, $scope.mapZoom))/2

/2 , ,

Simple!

+1

metresPerPixel = 40075016.686 * Math.abs(Math.cos(map.getCenter().lat / 180 * Math.PI)) / Math.pow(2, map.getZoom()+8);
+1

Source: https://habr.com/ru/post/1532054/


All Articles