typescript - 传单地图,未正确渲染图块
问题描述
我正在为我的应用程序的地图功能使用leafletjs。安装好了,写了一些简单的代码,看看地图。虽然瓷砖没有正确渲染
即使我拖到另一个地方,它仍然缺少一些瓷砖。这是我的代码
HTML
<div #map style="width:100%; height:100%;"
leaflet
(leafletMapReady)="onMapReady($event)"
[leafletOptions]="options">
</div>
TS
import { Component, OnInit } from '@angular/core';
import { latLng, MapOptions, tileLayer } from 'leaflet';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
options: MapOptions;
constructor() { }
ngOnInit(): void {
this.options = {
layers: [
tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '...', minZoom: 5 })
],
zoom: 5,
center: latLng(46.879966, -121.726909)
};
}
onMapReady(map) {
console.log("SHITS HERE DUMBAASS");
setTimeout(() => {map.invalidateSize(true)}, 1000);
// map.invalidateSize(true);
}
}
如您所见,我还拥有在其他帖子中看到的 onMapReady() 函数。我帮助正确加载地图,但是当我切换到不同的组件时,我又回到了不稳定状态。
更新: 缩小浏览器页面,使地图加载一段时间正常.. prolly 问题出在 CSS 上,仍将调查更多
更新2: 所以我这样做了
ngAfterViewChecked(): void {
this.map.invalidateSize(true);
//this.map.center = this.center;
}
这使得瓷砖加载。但我想知道为什么 (leafletMapReady) 没有“触发”地图无效?
谢谢!!!
解决方案
推荐阅读
- java - 使用 DateTimeFormatter 将字符串解析为 LocalDateTime 失败
- java - 原因:java.lang.IllegalArgumentException:::0 切入点中的正式未绑定错误
- android-studio - 大屏幕上的闪屏共享元素过渡
- pandas - 用第一行值替换每个组中的行。Pandas Groupby
- python - 如何声明具有用户定义维度的 numpy 矩阵 np.zeros?
- r - 使用 eval(parse(text=...))) 将对象保存到 RData
- php - 更改 Apache 配置文件后的 Symfony 路由问题
- c# - Scriptable Object 实例的空引用异常,但它真的有效吗?
- python - 使用 docopt 和 unittest 测试 CLI
- java - 如何在 Spring Boot 中将 HttpServletRequest 标头转发到另一个 REST API