I am looking to get the image url of the tile under the mouse.
Using the newest version v4.6.4
Any ideas?
Thank you
I am looking to get the image url of the tile under the mouse.
Using the newest version v4.6.4
Any ideas?
Thank you
The tile source classes have all the information about the tile grid: tileSource.getTileGrid()
You can access it's loader function and pass coordinate, ratio and projection to it.
const source = new ol.source.OSM();
const layer = new ol.layer.Tile({ source });
const view = new ol.View({
center: [2500000, 0], zoom: 5
});
const map = new ol.Map({
layers: [ layer,
new ol.layer.Tile({
source: new ol.source.TileDebug({
projection: 'EPSG:3857',
tileGrid: source.getTileGrid()
})
})
],
target: 'map',
view
});
const tileUrlFunction = source.getTileUrlFunction();
map.on('click', function(event) {
const grid = source.getTileGrid();
const tileCord = grid.getTileCoordForCoordAndZ(event.coordinate, view.getZoom());
console.log('clicked ', event.coordinate[0], event.coordinate[1]);
console.log('tile z,x,y is:', tileCord[0],tileCord[1], tileCord[2]);
console.log(tileUrlFunction(tileCord, 1, ol.proj.get('EPSG:3857')));
});
<link href="https://openlayers.org/en/v4.6.4/css/ol.css" rel="stylesheet"/>
<script src="https://openlayers.org/en/v4.6.4/build/ol-debug.js"></script>
<div id="map" class="map"></div>