1. 初始化测量工具
var result = document.getElementById('result');
var measure = new Motor.MeasureEditor({
viewer: viewer,//Motor.Viewer实例化对象
mode: Motor.MeasureMode.POINTDISTANCE,//测量角度或者长度,默认为角度
callback: measureCallback
});
function measureCallback(obj){
result.innerHTML='';
for (let key in obj) {
if(key==="angle"){
result.innerHTML+=`<span style="padding-left:15px;">角度: ${obj[key].toFixed(2)} °</span>`;
}
else if(key==="distance"){
result.innerHTML+=`<span style="padding-left:15px;">长度: ${obj[key].toFixed(2)} 米</span>`;
}
else if(key==="x"){
result.innerHTML+=`<span style="padding-left:15px;color:red;">x: ${obj[key].toFixed(2)} 米</span>`;
}
else if(key==="y"){
result.innerHTML+=`<span style="padding-left:15px;color:#2e2;">y: ${obj[key].toFixed(2)} 米</span>`;
}
else if(key==="z"){
result.innerHTML+=`<span style="padding-left:15px;color:blue;">z: ${obj[key].toFixed(2)} 米</span>`;
}
}
}
2. 测量模式切换
//测量角度
measure.mode = Motor.MeasureMode.ANGLE;
//测量两点之间长度
measure.mode = Motor.MeasureMode.POINTDISTANCE;
//测量多点之间长度
measure.mode = Motor.MeasureMode.POINTSDISTANCE;