// 0. 引入使用到的leaflet类 import { Marker, GeoJSON } from '../lib/leaflet/leaflet-src.esm.js'; import { MyMap } from '../common/myMap.js'; import dataCommon from '../common/data.js' class Map6 extends MyMap { run() { // 6. 根据YPE设置不同的图标 const glayer = new GeoJSON(dataCommon.geoHospitalSchool, { pointToLayer: (geoJsonPoint, latlng) => { switch (geoJsonPoint.properties['TYPE']) { case '医院': return new Marker(latlng, { // icon指定为 医院 的图标 icon: this.iconHospital }); case '学校': return new Marker(latlng, { // icon指定为 学校 的图标 icon: this.iconSchool }); } } }); glayer.addTo(this.map); } } let map = new Map6() map.run()