我遇到了一个问题,其他人似乎都遇到了我的 ngx-leaflet 地图在我调整大小之前没有完全呈现的问题。我尝试以多种方式调用 map.invalidateSize(),例如在 ngOnInit、onMapReady 中,所有上述方法都带有超时。我在初始加载时得到了这个。我正在使用 ngx-leaflet 2.5,因为 3.0+ 不适用于 angular 4.4.5。
访问模式的按钮是
<app-map
(closeButtonClicked)="mapModal.hide()"
class="modal fade"
bsModal
#mapModal="bs-modal"
tabindex="-1"
role="dialog"
aria-labelledby="mySmallModalLabel"
aria-hidden="true"
[Service]="Service"></app-map>
CSS是:
@import '../../app';
#map {
color: white;
font: 1em 'Dosis', Arial, sans-serif;
width: 90vh;
margin: 30px auto;
button.close {
font-size: 30px;
opacity: .4;
}
.modal-dialog {
width: 100vw;
height: 50vw;
.devices-sm({
width: 90vh;
height: 70vh;
});
.modal-content {
height: 100%;
.modal-body {
height: 100%;
background-color: @accent-background-color;
padding: 0;
#map {
height: 100%;
width: 100%;
padding: 0;
}
}
}
}
}
这是实际地图的代码
googleHybrid = L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
detectRetina: true
});
options = {
layers: [
this.googleHybrid
],
zoom: 1.49,
center: L.latLng([180, -180]),
};