简体   繁体   English

如何在 Angular 9 中绑定 OpenLayers 中的缩放变化

[英]How to bind zoom change in OpenLayers in Angular 9

I am searching for some change listener for my openlayers map.我正在为我的 openlayers map 寻找一些更改监听器。

For a not experienced Angular person, I am not sure if I should bind div changes or, the part I do not know how, bind directly map?对于一个没有经验的Angular的人,我不确定是否应该绑定div更改,或者我不知道如何直接绑定map的部分? In that case how can I call my function if there is not any element on which I can set a (change) or (ngModel) or similar?在这种情况下,如果没有任何可以设置(更改)或(ngModel)或类似元素的元素,我该如何调用我的 function?

The map is being created onInit calling this function: map 正在创建 onInit 调用此 function:

createOpenLayersMap(){
  this.map = new Map({
    target: 'hotel_map',
    layers: [new TileLayer({
      source: new OSM()
    })],
    view: new View({
      center: olProj.fromLonLat([this.lng, this.lat]),
      zoom: 7
    })
  });
  this.crForm = this.fb.group({
  crControl: [1],
  crEndControl: [1]
});
}

The map target is div by id 'hotel_map': map 目标是 id 为“hotel_map”的 div:

CSS: CSS:

#hotel_map {
  height: 100%;
  width: 100%;
 }

HTML: HTML:

      <div id="hotel_map" (change)="getZoom()"></div>

Typescript function: Typescript function:

  zoomLevel: any = '';
  getZoom(){
  this.zoomLevel = this.map.getView().getZoom();
  console.log(this.zoomLevel)
  }

Now I need to know the zoom parameters which would use to change circle radius.现在我需要知道用来改变圆半径的缩放参数。

For any solutions and advices, thanks in advance!对于任何解决方案和建议,提前致谢!

this.map.getView().on('change:resolution', () => {
    this.zoomLevel = this.map.getView().getZoom();
    console.log(this.zoomLevel)
})

just listen "change:resolution"只听“变化:分辨率”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM