<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) {
}
答案 0 :(得分:2)
将吸气剂用于options
。
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)
}
};