A
A
Alexey2020-02-05 02:50:25
leaflet
Alexey, 2020-02-05 02:50:25

Offset for initial coordinates?

How can I make the length and width count from the center of the map, and not from the top left corner?

var map = L.map('mapElement', {
  crs: L.CRS.Simple,
  minZoom: 0,
  maxZoom: 0,
  continuousWorld: false,
});
map.setView([-128, 128], 0);

L.tileLayer('/img/map/{z}/{x}/{y}.jpg', {
  attribution: 'no attribution',
}).addTo(map);

map.on('click', (e) => {
  new L.marker({lat: 0, lng: 0}).addTo(map); // ставит в верхнем левом краю
});

Is there any setting at which it will perceive the origin of coordinates as the center of the central tile?
that is, now to put the marker in the center, you need to do an offset new L.marker({lat: -128, lng: 128}).addTo(map);
here's how to get rid of the need to register this offset without using an additional function?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dom1n1k, 2020-02-05
@dom1n1k

I suppose to make my own projection by adjusting the project/unproject functions to the same delta:
https://github.com/Leaflet/Leaflet/blob/master/src...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question