【问题标题】:why ngx-leaflet in angular 2 does not render the map after changing state by *ngif为什么 Angular 2 中的 ngx-leaflet 在通过 *ngif 更改状态后不渲染地图
【发布时间】:2018-11-10 12:43:28
【问题描述】:

我对 Angular 2 的 ngx-leaflet 组件有疑问。 在地图出现时将 *ngif 的状态从 true 更改为 false 并再次从 false 更改为 true 后,没有发生图块渲染。 我该怎么做才能避免这个问题?

这是我的 html 代码

<button (click)="showMap=!showMap">toggle</button>
<div *ngif="showMap">
  <div [style.height.px]="mapHeight" leaflet
       (leafletClick)="mapOnClick($event)"
       [(leafletCenter)]="mapCenter"
       [leafletOptions]="options"
       (leafletMapReady)="onMapReady($event)"
       [leafletLayers]="layers">
  </div>
</div>

这是我的打字稿代码

options = {
  layers: [
    tileLayer('http://tile.openstreetmap.org/...', 
    { maxZoom: 18, attribution: '...' })
  ],
  zoom: 12,
  center: latLng(35.679966, 51.4)
};

map = null;

onMapReady(map: Map) {
  this.map = map; 
}

mapOnClick(evt) {
}    

【问题讨论】:

标签: angular ngx-leaflet


【解决方案1】:

options 使用getter。

  get options(){
    return {
    layers: [
      tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...' })
    ],
    zoom: 5,
    center: latLng(46.879966, -121.726909)
    }
  };

这是工作副本 - https://stackblitz.com/edit/angular-w3ugkr

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 2019-07-26
    • 2020-08-07
    • 2018-09-19
    • 2021-12-18
    相关资源
    最近更新 更多