openlayers - OpenLayers:查询 TileImage 源中的像素而不在地图上显示图层
问题描述
在 OpenLayers 4.6.5 中,我试图从 TileImage 源中读取像素值,而没有实际将源渲染为地图上的图层。我一直在尝试对这个问题的一些代码进行如下调整 - 请注意,在这个阶段,我只需要检查图块是否存在,还没有到实际查询图块的地步:
window['tiles'] = {};
window["L8SourceNRG"] = new ol.source.TileImage({
url: NRGtileURL,
crossOrigin: 'anonymous',
transition: 0,
preload: Infinity,
tileGrid: L8SourceTileGrid
});
window["L8SourceNRG"].on("tileloadend", (e) => {
console.log('tileloadend event fired');
let coord = e.tile.getTileCoord();
window['tiles'][coord.join('-')] = e.tile.getImage();
});
map.on('pointermove', (evt) => {
if (evt.dragging) {
return;
}
let coordinate = ol.proj.transform(evt.coordinate, map.getView().getProjection(), ol.proj.get('EPSG:3857'));
let tileCoord = L8SourceTileGrid.getTileCoordForCoordAndResolution(coordinate, this.map.getView().getResolution());
let key = tileCoord.join('-');
if (key in window['tiles']) {
console.log('key in tiles');
}
});
单独使用上面的代码,控制台日志消息“key in tiles”永远不会出现。如果我已经将“L8SourceNRG”源加载到图层中并在地图上渲染,我只能显示它。但我不想在地图上显示它——我只想使用像素值来运行一些计算,这些计算将用于创建一个新的多边形图层。
如您所见,在定义该源时,我还尝试使用“预加载”设置,但这似乎没有任何区别——尽管我很有可能做错了。
是否可以更改我的代码以使其工作 - 或者是否有更好的方法从 TileImage 源读取像素值而不将源渲染为地图上的图层?
解决方案
推荐阅读
- java - Android 在 Java 中高效读取大文本
- ms-access - 根据字段状态打印表单
- java - Android studio ConstraintLayout 调整大小问题
- node.js - AWS Lambda 仅在满足条件时触发函数
- firebase - Firebase 身份验证重定向到 Google 登录页面到 Vue 路由器
- python - 具有等效字符串的清洁列
- amazon-web-services - 包含 Spot 实例的 AutoScaling 组是否会响应 Spot 实例中断通知?
- php - “ldap_bind():无法绑定到服务器:凭据无效”,凭据正确
- css - 在移动设备上查看时,SVG 图像回退到 Times New Roman?
- c# - 显示来自foreach循环的许多图片后如何在视图数据中显示获取项目ID