L
L
lyrion2018-09-24 09:52:48
JavaScript
lyrion, 2018-09-24 09:52:48

How to fix coordinates on Leaflet custom map?

What was done
SasPlanet pulled out the OSM (Open Street Map) map tiles from the cache. Using the Leaflet library, I brought the map to the page:

<body>
  <div id='map'></div>
  <script src="./script.js"></script>
</body>

js code:
var osm = L.tileLayer('./map/OsmCircle/{z}/{dop}/{x}/{dop}/{y}.png',{ maxZoom: 15, dop: '0' });    
var map = L.map('map',{center: [76.5, -48.5], zoom:5, layers: osm});
var baseLayers = {"Open Street Map": osm};
L.control.layers(baseLayers).addTo(map);
L.control.mousePosition().addTo(map);

The map is displayed, but the coordinates are fundamentally wrong. For example, the coordinates of Moscow are 76; -72;
Using Leaflet's standard output of latitude and longitude (latlng), I determined that the 0:0 point was in the bottom right corner of the map.
As you can see, the problem is not even in negative numbers, the length of the entire map in terms of coordinates is also 180, and the height is ~ 85, the fact is that the coordinates seem to be displayed without taking into account the curvature of the planet, just as linear.
Please tell me how to fix this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lyrion, 2018-09-27
@lyrion

So, got it. Thanks for the advice Moskus he gave me the right thoughts.
I looked at my map in developer mode and saw that at scales from 1 to 3, LeafLet was completing the gray tiles. I counted their number and came to the following conclusion:
You just had to map z1 - 0 , z2 -1 , etc. Due to the lack of the necessary tiles, LeafLet began to be tricky with the coordinates, after fixing everything became normal. The "infinity" of the map appeared, i.e. tiles as you scroll left and right are completed again.
Ps I also advise you to display the marker at the point 0; 0 on a large scale, it should stand at the intersection of the equator and the zero meridian, if everything is so, then the reading will be correct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question