在Angular + Openlayers中使用click事件来检测单击的图层

问题描述 投票:0回答:1

我需要知道我在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()的方法,但我没有让它工作

angular openlayers geoserver
1个回答
0
投票

好的,迈克给出了解决方案

this.map.forEachLayerAtPixel(this.map.getEventPixel(event))得到用于.getSource().getGetFeatureInfoUrl()的图层

© www.soinside.com 2019 - 2024. All rights reserved.