无论我在 Angular 7 中尝试哪种方式,我的 Leaflet 地图都无法正确加载。我得到一个块拼图,一半屏幕为灰色,另一半为随机脱节的地图块(见图)。
\n\n地图块拼图:
\n\n
\n我的 HTML 是:
<div \n leaflet \n [leafletOptions]="options">\n</div>\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\n<div id="map" class="map"></div>\nRun Code Online (Sandbox Code Playgroud)\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)