html
<!DOCTYPE html>
<html>
<head>
<title>澳門家庭行程地圖</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<style>
#map { height: 600px; }
.popup-content img { max-width: 200px; }
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script>
// 初始化地圖
var map = L.map('map').setView([22.19, 113.55], 14);
// 添加地圖圖層
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// 景點數據
const spots = [
{
name: "大三巴牌坊",
coords: [22.1975, 113.5491],
time: "第一天 09:00-10:30",
desc: "澳門地標,階梯平緩適合老人家",
img: "https://example.com/grandpa.jpg"
},
{
name: "議事亭前地",
coords: [22.1965, 113.5495],
time: "第一天 10:30-11:30",
desc: "葡式廣場平坦易走",
img: "https://example.com/quaresquare.jpg"
},
{
name: "葡京酒店",
coords: [22.1872, 113.5563],
time: "第一天 12:00-13:30",
desc: "葡國料理午餐",
img: "https://example.com/restaurant.jpg"
},
{
name: "澳門博物館",
coords: [22.1970, 113.5515],
time: "第一天 14:00-16:00",
desc: "室內展館有電梯",
img: "https://example.com/museum.jpg"
},
{
name: "金莲花广场",
coords: [22.1987, 113.5464],
time: "第一天 17:00-18:00",
desc: "傍晚散步好去處",
img: "https://example.com/goldenflower.jpg"
},
{
name: "澳門威尼斯人",
coords: [22.1488, 113.5551],
time: "第二天 10:00-12:00",
desc: "室內購物免曬太陽",
img: "https://example.com/venice.jpg"
},
{
name: "漁人碼頭",
coords: [22.1970, 113.5416],
time: "第二天 14:00-16:00",
desc: "平緩步道觀海景",
img: "https://example.com/fisherman.jpg"
},
{
name: "媽閣廟",
coords: [22.1889, 113.5318],
time: "第二天 16:30-18:00",
desc: "短階梯可扶手前行",
img: "https://example.com/macau.jpg"
}
];
// 添加景點標記
spots.forEach((spot, index) => {
const marker = L.marker(spot.coords)
.bindPopup(`
<div class="popup-content">
<h3>${spot.name}</h3>
<p>${spot.time}</p>
<img src="${spot.img}" alt="${spot.name}">
<p>${spot.desc}</p>
</div>
`)
.addTo(map);
// 第一天行程用藍線連接
if(index < 5 && index > 0) {
L.polyline([
spots[index-1].coords,
spot.coords
], {color: 'blue'}).addTo(map);
}
// 第二天行程用綠線連接
if(index >=5 && index > 5) {
L.polyline([
spots[index-1].coords,
spot.coords
], {color: 'green'}).addTo(map);
}
});
// 酒店位置
L.marker([22.1878, 113.5573]).bindPopup('澳門文華東方酒店').addTo(map);
</script>
</body>
</html>