小编Moa*_*Moa的帖子

Angular Leaflet - 地图无法正确渲染

无论我在 Angular 7 中尝试哪种方式,我的 Leaflet 地图都无法正确加载。我得到一个块拼图,一半屏幕为灰色,另一半为随机脱节的地图块(见图)。

\n\n

地图块拼图:

\n\n

\n\n


\n我的 HTML 是:

\n\n
<div \n  leaflet \n  [leafletOptions]="options">\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者

\n\n
<div id="map" class="map"></div>\n
Run Code Online (Sandbox Code Playgroud)\n\n


\n我的组件是:

\n\n
import * as L from "leaflet";\n...\n@Component( {\n  styleUrls:  [ "../../../../node_modules/leaflet/dist/leaflet.css" ],\n  templateUrl:  "./map.html"\n} )\n...\nexport class Map implements OnInit {\n\n  map: any;\n\n  options = {\n    layers: [\n        L.tileLayer(\'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\', { maxZoom: 7, attribution: \'...\' })],\n        zoom: 5,\n        center: L.latLng([ 46.879966, -121.726909 ])};\n\n  async ngOnInit() {\n\n    this.map =  L.map(\'map\').setView( [37.8, -96], 4 );\n …
Run Code Online (Sandbox Code Playgroud)

leaflet typescript angular-leaflet-directive angular

8
推荐指数
1
解决办法
9603
查看次数