Angular >6.x 中集成Leaflet

安装

npm install leaflet -S

npm install @types/leaflet -D

在tsconfig.json文件中添加

{
  ...,
  "compilerOptions": {
    ...,
+    "paths": {
+      "leaflet": ["node_modules/leaflet/dist/leaflet.js"]
+    }
  }
}

在angular.json文件中添加

"styles": [
 + "node_modules/leaflet/dist/leaflet.css",
  "src/styles.css"
]

在componet中导入模块

import {map, tileLayer, marker, polyline} from 'leaflet';

map('mapDiv', {
  attributionControl: false
}).setView([0,0], 16);

传统的js使用方法:

L.map('mapDiv', { attributionControl: false }).setView([0,0], 16);

 

转载自:https://blog.csdn.net/fengyekafei/article/details/84346742

You may also like...