一般在建立播放器時會使用 video 標籤建立播放器,在地圖上可以用 L.videoOverlay() 方式建立video
L.videoOverlay 參數:
L.videoOverlay(<String|Array|HTMLVideoElement> video, <LatLngBounds> bounds, <VideoOverlay options> options?)
onMounted(() => {
const map = L.map(mapContainer.value);
const tiles = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}).addTo(map);
});
const videoUrls = "https://www.mapbox.com/bites/00188/patricia_nasa.mp4";
const bounds = L.latLngBounds([
[32, -130],
[13, -100],
]);
const errorOverlayUrl = "https://cdn-icons-png.flaticon.com/512/110/110686.png";
let videoOverlay = {};
onMounted(() => {
map.fitBounds(bounds);
videoOverlay = L.videoOverlay(videoUrls, bounds, {
opacity: 1,
errorOverlayUrl: errorOverlayUrl,
interactive: true,
autoplay: true,
loop: false,
}).addTo(map);
});
建立的播放器:
<div class="mapContainer" ref="mapContainer">
<div class="absolute z-500 top-5 right-3 text-xl">
<div class="mb-2">⏸</div>
<div >▶️</div>
</div>
</div>
let videoOverlay = {};
onMounted(() => {
videoOverlay = L.videoOverlay(videoUrls, bounds, {
opacity: 1,
errorOverlayUrl: errorOverlayUrl,
interactive: true,
autoplay: true,
loop: false,
}).addTo(map);
});
const videoPause = () => {
videoOverlay.getElement().pause();
};
const videoPlay = () => {
videoOverlay.getElement().play();
};
除了前面講的在地圖上建立圖片和影片圖層,也可使用 L.SVGOverlay() 在地圖上建立svg圖層
L.svgOverlay 參數
L.svgOverlay(<String|SVGElement> svg, <LatLngBounds> bounds, <SVGOverlay options> options?)
svg: svg 節點
bounds : svg 的座標
options : svg 的狀態設定
<div class="mapContainer" ref="mapContainer">
<svg viewBox="0 0 200 200" ref="svg">
<rect width="200" height="200"></rect>
<rect x="75" y="23" width="50" height="50" fill="red"></rect>
<rect x="75" y="123" width="50" height="50" fill="#0013ff"></rect>
</svg>
</div>
<script setup>
const svg = ref(null);
</script>
const latLngBounds = L.latLngBounds([
[32, -130],
[13, -100],
]);
onMounted(() => {
const map = L.map(mapContainer.value);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}).addTo(map);
map.fitBounds(latLngBounds);
});
onMounted(() => {
L.svgOverlay(svg.value, latLngBounds, {
opacity: 0.7,
interactive: true,
}).addTo(map);
});
svg圖層: