Answer the question
In order to leave comments, you need to log in
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);
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);
Answer the question
In order to leave comments, you need to log in
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);
L.CRS.Wall = L.extend({}, L.CRS.Simple, {
transformation: new L.Transformation(0.4920000014213405, 5.758860016636791, -0.4920000014213405, 968.389580797584),
});
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 questionAsk a Question
731 491 924 answers to any question