跳到主要内容
版本:9.1.0

模型平移

可自定义控制模型的平移方向与距离。

show
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>模型平移</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;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.1.0/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<div class="btn-group">
x: <input type="text" id="xValue" value="100"/>
y: <input type="text" id="yValue" value="0"/>
z: <input type="text" id="zValue" value="0"/>
<button onClick="moveModel()">移动模型</button>
</div>
<script>
let map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.67400351817594, 31.321374251251726],
zoom: 15.310035105070947,
pitch: 59.48725112156901,
bearing: -54.10626584095007,
userId: '***', // 授权码
env3D: {
defaultLight: true,
exposure: 2.8,
envMap: '../example_data/hdr/WhiteBG_Ref_1K.hdr'
}
});

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

let models_obj = ["../example_data/jinji_plaza_eastern_door_building.glb"].map(item => ({
type: 'glb',
url: item
}));

let options = {
id: 'model_id',
type: 'model',
models: models_obj,
center: [120.67727020663829, 31.31997024841401],
callback: function (group, layer) {
modelGroup = group;
}
};
map.addLayer(options);
})

function moveModel() {
if (modelGroup) {
let x = parseFloat(document.getElementById("xValue").value)
let y = parseFloat(document.getElementById("yValue").value)
let z = parseFloat(document.getElementById("zValue").value)
modelGroup.setTranslate({x: x, y: y, z: z})
}
}
</script>
</body>
</html>