leaflet.fullscreen 可以控制地圖是否進入全屏模式,還有提供其他 option 設定按鈕元件。
我用 pnpm i @bepo65/leaflet.fullscreen 將套件載入,vue 檔分別引入底下兩個 JS 和 CSS 檔案。
import "@bepo65/leaflet.fullscreen/Control.FullScreen";
import "@bepo65/leaflet.fullscreen/Control.FullScreen.css";
fullscreen 的按鈕也是在 onMounted 階段建立並且放在地圖上。
onMounted(() => {
new L.Map(mapContent.value, {
fullscreenControl: true,
fullscreenControlOptions: {
position: "topleft",
title: "進入全螢幕",
titleCancel: "離開全螢幕",
content: null,
forceSeparateButton: true,
forcePseudoFullscreen: false,
},
});
}
fullscreenControl : 設定全螢幕按鈕是否顯示在地圖上。
fullscreenControlOptions : 用來設定全螢幕按鈕的狀態
當點擊全螢幕按鈕地圖就會被撐開,但網址列還看的到
false : 設定地圖佔滿整個螢幕
這時候地圖會佔滿整個螢幕連網址列都看不到
map 物件可以監聽 enterFullscreen 和 exitFullscreen 事件。
map.on("enterFullscreen", function () {
console.log("entered fullscreen");
});
or
map.on('exitFullscreen', function(){
console.log('exited fullscreen');
});
https://github.com/BePo65/leaflet.fullscreen
https://www.letswrite.tw/leaflet-plugins/#%e5%85%a8%e8%9e%a2%e5%b9%95%ef%bc%9aleafletcontrolfullscreen