0
我試圖在div標籤內顯示小冊子地圖。不幸的是它被移出標籤。小冊子地圖被移出div標籤
這是我的角度指令:
import L from 'leaflet';
import esri from 'esri-leaflet';
import 'leaflet/dist/leaflet.css';
class MapDirective {
constructor() {
this.resctrict = 'E';
this.controller = MapController;
}
link(scope, element) {
let map = L.map(element[0]).setView([51.505, -0.09], 8);
esri.tiledMapLayer({
url: "https://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer"
}).addTo(map);
}
/**
* @returns {MapDirective}
*/
static directiveFactory() {
return new MapDirective();
}
}
這是我的HTML模板代碼:
<h1>Leaflet Map Integration</h1>
<div style="width: 500px; height: 500px">
<map></map>
</div>
我已經嘗試過加入
map.invalidateSize();
這裏提到Leaflet Map not showing in bootstrap div但這並沒有幫助。
完整的項目代碼可在github找到。
您需要將'map' id添加到您的div。 – Ale
@Ale無需爲此引用[Leaflet文檔](http://leafletjs.com/reference.html#map-l.map):'L.Map( id,