好的..
首先安装传单及其类型
npm install leaflet --save
npm install @types/leaflet --save
然后将 leaflet 导入到您的组件或其他任何东西中
import 'leaflet';
在 html 文件中添加一个带有 id="map" 和预设大小的 div(最好通过 css 完成)。
<div style="height: 180px" id="map"></div>
由于styleUrls: [] 在 Ionic2 中仍然存在问题,您还必须将传单样式添加到您的 html 文件中:
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
准备好之后,您可以像这样从leaflet tutorial 开始:
ngOnInit(): void {
var map = L.map('map')
.setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/mapbox.streets-basic/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
accessToken: 'xxx'
}).addTo(this.map);
}