Openlayers在鼠标下获取图块的图像URL [英] Openlayers get the image url of the tile under the mouse

查看:108
本文介绍了Openlayers在鼠标下获取图块的图像URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找鼠标下方磁贴的图像网址.

I am looking to get the image url of the tile under the mouse.

使用最新版本v4.6.4

Using the newest version v4.6.4

有什么想法吗?

谢谢

推荐答案

瓦片源类具有有关瓦片网格的所有信息:tileSource.getTileGrid() 您可以访问它的加载器函数并传递坐标,比例和投影.

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>

这篇关于Openlayers在鼠标下获取图块的图像URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆