F
F
fynjy_82015-08-17 01:38:30
Cartography
fynjy_8, 2015-08-17 01:38:30

How to set coordinates for tiles in Leaflet.js?

Hello! I have a map on leaflet.js map size 5913x7863 and it's in local planar (XY) coordinate system respectively L.CRS.Simple
Before this I used L.imageOverlay:

var imageBounds = ;
var file0 = new L.imageOverlay(imageUrl, imageBounds).addTo(map);

And everything was super
But I realized that this is a bad way (a single picture crashes on mobile phones and cards don’t do that) and you need to make tiles
Next, I cut into tiles
Tiles are stored in folders "1/1/0" "1/1/1 " etc.
I want to make XY coordinates - so that the map is in coordinates [1468.9700,-11.7050], [1968.2705,363.7705]
But I don't understand how to do it even in coordinates [0,0] [5913.7863].
The code is now like this:
map = L.map('map', {
          crs: L.CRS.Simple,
            maxZoom: 4,
            minZoom: 0
        }).setView([-60,100], 1);
 
L.tileLayer('./images/{z}/{x}/{y}.png', {
            continuousWorld: true,
            noWrap: false
        }).addTo(map);

At the same time, the picture is located in coordinates approximately [0,0], [-256,192] - I don’t understand why exactly these are.
Once again, the question is: how to make the borders exactly [1468.9700, -11.7050], [1968.2705,363.7705]?
Why is it so easy in L.imageOverlay and so difficult in L.tileLayer?
Please any ideas. I've been suffering for 2 months

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
fynjy_8, 2015-08-30
@fynjy_8

Moskus thanks for the comments
Managed to realize what was conceived in openlayers

var mapBounds = new OpenLayers.Bounds(-11.705000, 1468.971000, 363.770500, 1968.271500);
var mapMinZoom = 0;
var mapMaxZoom = 5;
var mapMaxResolution = 0.063500;
var gridBounds = new OpenLayers.Bounds(-11.705000, 1468.971000, 363.770500, 1968.271500);

The question now is how to do this in a leaflet :) As I understand it, simple manipulations will not work, you need to use Proj.4 and Proj4Leaflet, is there a conditional local coordinate system at all?
L.CRS.Wall = L.extend({}, L.CRS.Simple, {
  transformation: new L.Transformation(0.4920000014213405, 5.758860016636791, -0.4920000014213405, 968.389580797584),

    
});

M
Moskus, 2015-08-25
@Moskus

The easiest way to assign any coordinates to a raster file is to create a so-called World file for it https://en.wikipedia.org/wiki/World_file
This is a text file in which you need to fill in only four lines with non-zeros
: X axis (the difference between the extreme right and extreme left coordinates of the raster, divided by the number of pixels along the X axis)
- zero
- zero
- resolution along the Y axis (the difference between the extreme lower and extreme upper coordinates of the raster, divided by the number of pixels along the Y axis, traditionally negative number, because the axis goes from bottom to top)
- X
coordinates of the center of the top left pixel - Y coordinates of the center of the top left pixel
Next, you need to attach one more file to your raster - a projection description file with the same name as the raster, but with the .prj extension - download it from here spatialreference.org/ref/epsg/popular-visualisatio...
Then you all that remains is to feed this www.gdal.org/gdal2tiles.html or www.maptiler.com correctly and get the tiles you are looking for, which you can then connect to Leaflet as if they have real coordinates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question