cesium左侧列表定位目标
功能:根据左侧列表经纬度等信息的值,进行搜索定位。
列表:
1 点击清除按钮可以清空所有input的值
2 点击查找可以定位到位置,如果输入的值不在范围内,会有弹出框提示。
3 每个值,输入错误都有个弹出框,提示你。
记得在合适的位置调用这个locationClick()这个函数哦~~;页面就是普通的页面;自己写就行。如有疑问,请加群讨论
下面上代码
// 左侧定位查找
function locationClick() {
locationLon = $("#location_lon").val();
locationLat = $("#location_lat").val();
locationHeight = $("#location_height").val();
locationCenter = Cesium.Cartesian3.fromDegrees(Number(locationLon), Number(locationLat), Number(locationHeight));
locationHeading = Cesium.Math.toRadians($("#location_heading").val());
locationPitch = Cesium.Math.toRadians($("#location_pitch").val());
locationRange = $("#location_range").val();
if (locationLon) {
locationLon = Number(locationLon);
}
if (locationLat) {
locationLat = Number(locationLat);
}
if (locationHeight) {
locationHeight = Number(locationHeight);
} else {
locationHeight = Number(0);
}
if (locationHeading) {
locationHeading = Number(locationHeading);
} else {
locationHeading = Number(0);
}
if (locationPitch) {
locationPitch = Number(locationPitch);
} else {
locationPitch = Number(0);
}
if (locationRange) {
locationRange = Number(locationRange);
} else {
locationRange = Number(0);
}
if (locationLon && locationLat) {
locationLat = Number(locationLat);
locationLon = Number(locationLon);
$(".reminder_lat").hide();
} else {
alert("经纬度为必填项");
}
// 控制输入值的范围
if (locationLon > 180 || locationLon < -180) {
alert("经度,请输入请输入(-180,180)的值");
}
if (locationLat > 90 || locationLat < -90) {
alert("纬度,请输入请输入(-90,90)的值");
}
if (locationHeight < 0 || locationHeight > 100000) {
alert("高度,请输入请输入(0,100000)的值");
}
if (locationHeading < 0 || locationHeading > 360) {
alert("朝向角,请输入请输入(0,360)的值");
}
if (locationPitch < -90 || locationPitch > 90) {
alert("俯仰角,请输入请输入(-90,90)的值");
}
if (locationRange > 10000000 || locationRange < 0) {
alert("距离,请输入请输入(30000,10000000)的值");
}
viewer.camera.lookAt(locationCenter, new Cesium.HeadingPitchRange(Number(locationHeading), Number(locationPitch), Number(locationRange)));
}
// 定位数据清除
$(function () {
$('#location_clear').click(function () {
$("#location_lon").val("");
$("#location_lat").val("");
$("#location_height").val("");
$("#location_heading").val("");
$("#location_pitch").val("");
$("#location_range").val("");
});
});