openlayers获取鼠标下tile的图片url

Openlayers get the image url of the tile under the mouse

我想获取鼠标下方的图块图像 url。

使用最新版本v4.6.4

有什么想法吗?

谢谢

图块源类有关于图块网格的所有信息:tileSource.getTileGrid() 您可以访问它的 loader function 并将坐标、比率和投影传递给它。

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>