跳到主要内容
版本:1.1.0

3DTiles坐标拾取

在地图中拾取3DTiles格式数据的坐标,需要3DTiles图层的pickable属性为true。

show
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>3DTiles坐标拾取</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
<style>
body {
margin: 0;
padding: 0;
}

#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}

.btn-group {
position: absolute;
top: 20px;
left: 20px;
}

#text {
color: #000000;
font-size: 20px;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/lite/v1.1.0/mapmost-lite-min.js"></script>
</head>
<body>
<div id="map"></div>
<div class="btn-group">
<div id="text">坐标:</div>
</div>
<script>
var map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.74449559193792, 31.30775326748954],
zoom: 16,
pitch: 60,
userId: '***', // 授权码,此参数务必添加
});

map.on('load', function () {

const TILESET_URL = "http://***/temp_data/Olympic/tileset.json";
map.add3dTilesLayer(
{
id: 'tile-3d-layer',
data: TILESET_URL,
pickable: true
}
)

map.on('click', e => {
let point = e.point;
let result = map.pick3dTilesCoordinate(point, "tile-3d-layer")
console.log(result);
document.getElementById("text").innerText = "坐标:" + result
});
})
</script>
</body>
</html>