測量工具
此範例示範如何加入測量工具,包含以下功能:
- 加入測量工具:於
style.load後新增MeasureControl
info
詳細使用說明請參考「MeasureControl」。
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>測量工具</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://kw3dmap.localking.com.tw/openapi/loader/mapPlus-1.3.9.loader.js" crossorigin="anonymous" referrerpolicy="origin"></script>
<style>
body { margin: 0; padding: 0; }
#map { width: 100vw; height: 100vh; }
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
const map = await new mapPlus(document.getElementById("map"), {
accessKey: 'get_your_key', // 聯絡勤崴國際,取得專屬key
accessToken: 'get_your_token', // 聯絡勤崴國際,取得專屬token
style: 'https://kw3dmap.localking.com.tw/openapi/map/kwmap.etxt', // 樣式
center: [121.52251734614822, 25.026224105188575],
pitch: 0,
bearing: 0,
zoom: 15,
maxZoom: 18,
minZoom: 7,
});
/* ══════════════════════════════════════════════════════════════════════════
* 加入測量工具:
- 可調整 units,更改顯示的單位。
══════════════════════════════════════════════════════════════════════════ */
map.on("style.load", () => {
const measure = new mapPlus.MeasureControl({
// 使用單位,可設定 metric(公制)、imperial(英制)
units: 'metric',
});
// 添加測量工具到地圖
map.addControl(measure);
});
</script>
</body>
</html>
<script src="https://kw3dmap.localking.com.tw/openapi/loader/mapPlus-1.3.9.loader.js" crossorigin="anonymous" referrerpolicy="origin"></script>
<script type="module">
const map = await new mapPlus(document.getElementById("map"), {
accessKey: 'get_your_key', // 聯絡勤崴國際,取得專屬key
accessToken: 'get_your_token', // 聯絡勤崴國際,取得專屬token
style: 'https://kw3dmap.localking.com.tw/openapi/map/kwmap.etxt', // 樣式
center: [121.52251734614822, 25.026224105188575],
pitch: 0,
bearing: 0,
zoom: 15,
maxZoom: 18,
minZoom: 7,
});
/* ══════════════════════════════════════════════════════════════════════════
* 加入測量工具:
- 可調整 units,更改顯示的單位。
══════════════════════════════════════════════════════════════════════════ */
map.on("style.load", () => {
const measure = new mapPlus.MeasureControl({
// 使用單位,可設定 metric(公制)、imperial(英制)
units: 'metric',
});
// 添加測量工具到地圖
map.addControl(measure);
});
</script>
<style>
body { margin: 0; padding: 0; }
#map { width: 100vw; height: 100vh; }
</style>