pnpm i leaflet-minimap
引入 JS 和 CSS 檔案
import "leaflet-minimap/src/Control.MiniMap";
import "leaflet-minimap/src/Control.MiniMap.css";
因為小地圖的圖資跟主地圖一樣,這邊用個變數將圖資和圖資版權資訊裝起來,在 onMounted 建立小地圖。
const osmUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
const attribution = '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>';
const osm2 = new L.TileLayer(osmUrl, { attribution: attribution });
onMounted(() => {
const miniMap = new L.Control.MiniMap(osm2).addTo(map);
})
小地圖建立:
onMounted(() => {
const miniMap = new L.Control.MiniMap(osm2, {
width: "250",
height: "250",
toggleDisplay: true,
collapsedWidth: "30",
collapsedHeight: "30",
zoomAnimation: true,
minimized: true,
}).addTo(map);
});
如果 toggleDisplay 設定 true,小地圖會像以下出現 toggle
minimized 設定 true 初始化時地圖如以下顯示
參考資料 :
https://github.com/Norkart/Leaflet-MiniMap
https://blog.csdn.net/badao_liumang_qizhi/article/details/122451508
https://www.programminghunter.com/article/87322347902/