IT筆記 :Leaflet開源JavaScript地圖學習篇(3)
使用 L.polygon繪畫連接四間酒店的多邊形,四間酒店的名稱及坐標如下:
香港尖沙咀凱悅酒店 : 22.297696623540645, 114.17403305500363
九龍香格里拉 : 22.297349192568806, 114.17705858671009
九龍酒店 : 22.29592967990824, 114.17179072831338
半島酒店 : 22.295344002650047, 114.17183364365674
例子如下:
var polygon = L.polygon([[22.297696623540645, 114.17403305500363],[22.297349192568806, 114.17705858671009],[22.29592967990824, 114.17179072831338], [22.295344002650047, 114.17183364365674]], {color: 'red',weight:8,fillColor:'blue',fillOpacity:1}).addTo(map);
Source code modified from Leaflet.Js Essentials by Paul Crickard III:
<html>
<head><title>Leaflet.js Essentials</title>
<<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
</head>
<body>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
<div id="map" style="width: 800px; height: 600px"></div>
<script>
var map = L.map('map',
{
center: [22.29760728423041, 114.17219842407526],
zoom: 16
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
var polygon = L.polygon([[22.297696623540645, 114.17403305500363],[22.297349192568806, 114.17705858671009],[22.29592967990824, 114.17179072831338], [22.295344002650047, 114.17183364365674]], {color: 'red',weight:8,fillColor:'blue',fillOpacity:1}).addTo(map);
</script>
</body>
</html>
Comments