angular - 在 Angular + Openlayers 中使用点击事件来检测点击的图层
问题描述
我需要知道我在 openlayers 地图中单击了哪个图层,以便稍后获取它的一些数据。
我以前做过,但只用了一层。现在我有不止一个,我想知道我点击哪个图层来从地理服务器获取它的信息。
capa1WMS:TileLayer;
map:Map;
...
getDatosCapaWMS(url:string): Observable<any>{
return this.http.get(url);
}
clickMapa(event:any):void{
if(this.capa1WMS.getSource()!=null){
var url = this.capa1WMS.getSource().getGetFeatureInfoUrl(
this.map.getEventCoordinate(event), this.view.getResolution(), this.view.getProjection(),
{'INFO_FORMAT': 'application/json'});
this.getDatosCapaWMS(url).subscribe(data => {
//stuff
});
}
}
还有我的 HTML 代码
<div id="map" class="map" (click)="clickMapa($event)"></div>
我已经看到 openlayers 有一个名为forEachFeatureAtPixel()
但我没有让它工作的方法
解决方案
好的,迈克给出了解决方案
this.map.forEachLayerAtPixel(this.map.getEventPixel(event))
获取要使用的图层.getSource().getGetFeatureInfoUrl()
推荐阅读
- api - Instagram 订阅
- javascript - 为什么 HTTP 请求可以在本地和网络空间上工作,而不是在 Raspberry Pi 上?
- python - 将数据框与(更长的)日期时间系列合并
- windows - 从 .txt 文件中修剪特定行
- pandas - 如何复制熊猫数据框,使其成为 2 个变量?
- linux - 使用 bash 检查具有文件路径的文本文件中的文件名在文本文件中是否唯一
- swift - Mapbox MGLAnnotations 未在 MapView for Mapbox iOS 上呈现
- mysql - 休眠使用默认方言而不是 application.properties 中的方言
- c - C 内存管理约定:通过在堆栈上分配的对象释放在堆上分配的内存
- java - 如何在 Java 中实现体重指数(BMI)