I am trying to create a map using openlayers, but I want to center it in a unique way. For example, I have a z/x/y coordinate of 12/2045/-1362. Can someone help me convert this to longitude/latitude? It's the complete opposite of this: How to get X Y Z coordinates of tile by click on Leaflet map
I find it challenging to understand the logic in the link above and reverse engineer it. If anyone has experience or a ready-made formula for this, I would greatly appreciate it. Thank you.
Eventually, I will use this to render the center of my map like this:
var z = 12;
var x = 2045;
var y = -1362;
function convertXYZtoCoor(z, x, y) {
// code here
return [lng, lat];
}
var coor = convertXYZtoCoor(z, x, y);
var view = new ol.View({
center: ol.proj.transform(
[coor[0], coor[1]], 'EPSG:4326', 'EPSG:3857'),
zoom: z
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: view
});
I hope my question is clear, thank you.
Edit: Added code