diff --git a/leaflet/d6/index.html b/leaflet/d6/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7d0926ae41d878e8a57a2b2ac6eb888cc068aac7 --- /dev/null +++ b/leaflet/d6/index.html @@ -0,0 +1,19 @@ + + + + + + + + + + leaflet学习 + + +
+ + + + \ No newline at end of file diff --git a/leaflet/d6/index.js b/leaflet/d6/index.js new file mode 100644 index 0000000000000000000000000000000000000000..3217fe2e18401d12d675a22f9e93a55f5d341448 --- /dev/null +++ b/leaflet/d6/index.js @@ -0,0 +1,35 @@ + +// 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() diff --git a/leaflet/d6/style.css b/leaflet/d6/style.css new file mode 100644 index 0000000000000000000000000000000000000000..0f8a0c62eeb7a2d5cceb75b334d39fd84751e035 --- /dev/null +++ b/leaflet/d6/style.css @@ -0,0 +1,28 @@ + +html, +body { + width: 100%; + height: 100%; + margin: 0px; +} + +h1, +h2 { + font-family: Lato; +} + +#map { + width: 100%; + height: 100%; +} + +.panel { + position: absolute; + top: 70px; + right: 10px; + z-index: 1000; + padding: 5px 10px; + background-color: rgba(255, 255, 255, 1); + border: 2px solid rgba(0, 0, 0, 0.2); + width: 56px; +} diff --git a/leaflet/d7/index.html b/leaflet/d7/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7d0926ae41d878e8a57a2b2ac6eb888cc068aac7 --- /dev/null +++ b/leaflet/d7/index.html @@ -0,0 +1,19 @@ + + + + + + + + + + leaflet学习 + + +
+ + + + \ No newline at end of file diff --git a/leaflet/d7/index.js b/leaflet/d7/index.js new file mode 100644 index 0000000000000000000000000000000000000000..61781d0b9146bbcb8f1c7b7e6ee720259cef0e66 --- /dev/null +++ b/leaflet/d7/index.js @@ -0,0 +1,35 @@ + +// 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 MapX extends MyMap { + + run() { + + // 7. 根据YPE设置不同的图标;marker绑定提示信息:bindTooltip + const glayer = new GeoJSON(dataCommon.geoHospitalSchool, { + pointToLayer: (geoJsonPoint, latlng) => { + switch (geoJsonPoint.properties['TYPE']) { + case '医院': + return new Marker(latlng, { + // icon指定为 医院 的图标 + icon: this.iconHospital + }).bindTooltip(geoJsonPoint.properties['NAME'], { permanent: true }); + case '学校': + return new Marker(latlng, { + // icon指定为 学校 的图标 + icon: this.iconSchool + }).bindTooltip(geoJsonPoint.properties['NAME'], { permanent: false }); + } + } + }); + + glayer.addTo(this.map); + + } +} + +let map = new MapX() +map.run() diff --git a/leaflet/d7/style.css b/leaflet/d7/style.css new file mode 100644 index 0000000000000000000000000000000000000000..0f8a0c62eeb7a2d5cceb75b334d39fd84751e035 --- /dev/null +++ b/leaflet/d7/style.css @@ -0,0 +1,28 @@ + +html, +body { + width: 100%; + height: 100%; + margin: 0px; +} + +h1, +h2 { + font-family: Lato; +} + +#map { + width: 100%; + height: 100%; +} + +.panel { + position: absolute; + top: 70px; + right: 10px; + z-index: 1000; + padding: 5px 10px; + background-color: rgba(255, 255, 255, 1); + border: 2px solid rgba(0, 0, 0, 0.2); + width: 56px; +}