[GIS] LeafletJS Measurement of distance in deepzoom tilelayer

leafletleaflet-draw

I have been trying to understand how LeafletJS determines distances between two points in a layer. I am trying to implement the custom scale plugin, (and have done so successfully) on a static tiled image using the leaflet deepzoom tilelayer plugin.

Added Information

Using CRS.Simple, the image zoom is adjusted by powers of 2 by the looks of it:

CRS.Simple seems to operate in powers of 2:

o.CRS.Simple=o.extend({},o.CRS,{projection:o.Projection.LonLat,transformation:new o.Transformation(1,0,-1,0),scale:function(t){return Math.pow(2,t)}})

Constants that I know:

  1. DPI
  2. tile size (256 x 256 pixels)
  3. map size in pixels (bounds of the image)
  4. leaflet zoom level
  5. size of image in the real world

What do I change in Leaflet to allow me to make accurate scale bars?

Best Answer

If tiles are always 256x256 pixels, with one tile covering the planet at zoom level 0, increasing by powers of 4 at every zoom level, then roughly calculating distance per pixel at any zoom level is relatively straightforward (given the inherent errors of distance measurement in EPSG:3857)

If your image has been correctly georeferenced, split into tiles that are 256x256 pixels to match Leaflet's global {x}{y}{z} referencing system, and then displayed using Leaflet, then the custom scale plugin should work... But it sounds like you are using Leaflet as a continuous zoom viewer, without regard to where your tiles fit on earth in {x}{y}{z} space, and therefore the scale bar and the pixel distance per zoom table you referenced will not apply.