首页 > 解决方案 > 如何使用 Angular 中的单击按钮放大某个位置

问题描述

我想zoomopenlayers图书馆的某个位置,例如:Berlin当用户点击按钮时。有人能告诉我怎么可能吗?

以下是我的代码:

app.component.html

<button id='berlin' (click)="onClick('berlin')">Zoom to Berlin</button>

app.component.ts

berlin = fromLonLat([13.388866, 52.517071]);

public onClick(city:any) {
   console.log(city);
   view.animate({
      center: city,
      duration: 2000
   });
}

标签: angularopenlayersangular-openlayers

解决方案


var bern = ol.proj.transform([7.4458,46.95], 'EPSG:4326', 'EPSG:3857'); 
document.getElementById ("berlin").addEventListener ("click", berlinZoom, false);
 function berlinZoom() {

            var bernview = new ol.View({
                center: bern,
                zoom: 6
            });  
         map.setView(bernview); 
        }

推荐阅读