//地形开挖
|
function digEarth(drawCartesian, unionClippingRegions, buildings, isCircle,iscutearth) {
|
if (isCircle == undefined) {
|
isCircle = true;
|
}
|
var points = [
|
];
|
var latLngArr = [];
|
for (var i = 0; i < drawCartesian.length; i++) {
|
var cartographic = Cesium.Cartographic.fromCartesian(drawCartesian[i]);
|
latLngArr.push({ lng: cartographic.longitude, lat: cartographic.latitude });
|
var p = Cesium.Cartesian3.clone(drawCartesian[i]);
|
points.push(p);
|
}
|
var clockWise = isClockWise(latLngArr);
|
if(iscutearth==1){
|
viewer.scene.globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
|
planes: buildClippingPlanes1(points, unionClippingRegions != clockWise),
|
edgeWidth: 1.0,
|
edgeColor: Cesium.Color.WHITE,
|
unionClippingRegions: unionClippingRegions
|
})
|
if (!isCircle) {
|
viewer.scene.globe.clippingPlanes._planes.length = 1;
|
}
|
}
|
for (var i in buildings) {
|
if (buildings[i].clippingPlanes == undefined) {
|
buildings[i].clippingPlanes = new Cesium.ClippingPlaneCollection({
|
planes: buildClippingPlanes2(points, unionClippingRegions != clockWise, getInverseTransform(buildings[i])),
|
edgeWidth: 1.0,
|
edgeColor: Cesium.Color.WHITE,
|
unionClippingRegions: unionClippingRegions
|
});
|
} else {
|
buildings[i].clippingPlanes._planes = buildClippingPlanes2(points, unionClippingRegions != clockWise, getInverseTransform(buildings[i]));
|
buildings[i].clippingPlanes.unionClippingRegions = unionClippingRegions;
|
}
|
if (!isCircle) {
|
buildings[i].clippingPlanes._planes.length = 1;
|
}
|
}
|
}
|
|
function getInverseTransform(tileSet) {
|
let transform;
|
let tmp = tileSet.root.transform
|
console.log(tmp);
|
// if ((tmp && tmp.equals(Cesium.Matrix4.IDENTITY)) || !tmp) {
|
// 如果root.transform不存在,则3DTiles的原点变成了boundingSphere.center
|
transform = Cesium.Transforms.eastNorthUpToFixedFrame(tileSet.boundingSphere.center)
|
// } else {
|
// transform = Cesium.Matrix4.fromArray(tileSet.root.transform)
|
// }
|
return Cesium.Matrix4.inverseTransformation(transform, new Cesium.Matrix4())
|
}
|
function getOriginCoordinateSystemPoint(point, inverseTransform) {
|
return Cesium.Matrix4.multiplyByPoint(
|
inverseTransform, point, new Cesium.Cartesian3(0, 0, 0))
|
}
|
function buildClippingPlanes1(points, invert) {
|
var pointsLength = points.length;
|
var clippingPlanes = []; // 存储ClippingPlane集合
|
for (var i = 0; i < pointsLength; ++i) {
|
var nextIndex = (i + 1) % pointsLength;
|
var midpoint = Cesium.Cartesian3.add(points[i], points[nextIndex], new Cesium.Cartesian3());
|
midpoint = Cesium.Cartesian3.multiplyByScalar(midpoint, 0.5, midpoint);
|
var right = Cesium.Cartesian3.subtract(invert ? points[i] : points[nextIndex], midpoint, new Cesium.Cartesian3());
|
var up = Cesium.Cartesian3.normalize(midpoint, new Cesium.Cartesian3());
|
right = Cesium.Cartesian3.normalize(right, right);
|
|
var normal = Cesium.Cartesian3.cross(right, up, new Cesium.Cartesian3());
|
normal = Cesium.Cartesian3.normalize(normal, normal);
|
var originCenteredPlane = new Cesium.Plane(normal, 0.0);
|
var distance = Cesium.Plane.getPointDistance(originCenteredPlane, midpoint);
|
clippingPlanes.push(new Cesium.ClippingPlane(normal, distance));
|
}
|
return clippingPlanes;
|
}
|
|
function buildClippingPlanes2(points, invert, inverseTransform) {
|
var pointsLength = points.length;
|
var clippingPlanes = []; // 存储ClippingPlane集合
|
for (var i = 0; i < pointsLength; ++i) {
|
var nextIndex = (i + 1) % pointsLength;
|
clippingPlanes.push(invert ? createPlane(points[nextIndex], points[i], inverseTransform) : createPlane(points[i], points[nextIndex], inverseTransform));
|
}
|
return clippingPlanes;
|
}
|
function createPlane(p1, p2, inverseTransform) {
|
|
// 将仅包含经纬度信息的p1,p2,转换为相应坐标系的cartesian3对象
|
let p1C3 = getOriginCoordinateSystemPoint(p1, inverseTransform)
|
let p2C3 = getOriginCoordinateSystemPoint(p2, inverseTransform)
|
|
// 定义一个垂直向上的向量up
|
let up = new Cesium.Cartesian3(0, 0, 10)
|
// right 实际上就是由p1指向p2的向量
|
let right = Cesium.Cartesian3.subtract(p2C3, p1C3, new Cesium.Cartesian3())
|
|
// 计算normal, right叉乘up,得到平面法向量,这个法向量指向right的右侧
|
let normal = Cesium.Cartesian3.cross(right, up, new Cesium.Cartesian3())
|
normal = Cesium.Cartesian3.normalize(normal, normal)
|
|
//由于已经获得了法向量和过平面的一点,因此可以直接构造Plane,并进一步构造ClippingPlane
|
let planeTmp = Cesium.Plane.fromPointNormal(p1C3, normal)
|
return Cesium.ClippingPlane.fromPlane(planeTmp)
|
}
|
//判断点序
|
function isClockWise(latLngArr) {
|
// if (latLngArr.length < 3) {
|
// return null
|
// }
|
if (latLngArr[0] === latLngArr[latLngArr.length - 1]) {
|
latLngArr = latLngArr.slice(0, latLngArr.length - 1)
|
}
|
let latMin = { i: -1, val: 90 }
|
for (let i = 0; i < latLngArr.length; i++) {
|
let { lat } = latLngArr[i]
|
if (lat < latMin.val) {
|
latMin.val = lat
|
latMin.i = i
|
}
|
}
|
let i1 = (latMin.i + latLngArr.length - 1) % latLngArr.length
|
let i2 = latMin.i
|
let i3 = (latMin.i + 1) % latLngArr.length
|
|
let v2_1 = {
|
lat: latLngArr[i2].lat - latLngArr[i1].lat,
|
lng: latLngArr[i2].lng - latLngArr[i1].lng
|
}
|
let v3_2 = {
|
lat: latLngArr[i3].lat - latLngArr[i2].lat,
|
lng: latLngArr[i3].lng - latLngArr[i2].lng
|
}
|
let result = v3_2.lng * v2_1.lat - v2_1.lng * v3_2.lat
|
// result>0 3-2在2-1的顺时针方向 result<0 3-2在2-1的逆时针方向 result==0 3-2和2-1共线,可能同向也可能反向
|
return result === 0 ? (latLngArr[i3].lng < latLngArr[i1].lng) : (result > 0)
|
}
|
function clip2(options) {
|
// var projectinfo;
|
|
layui.use('layer', function () {
|
layer.load(1, { shade: [0.5, '#000'] });
|
// layer.open({
|
// type: 1
|
// , title: false //不显示标题栏
|
// , closeBtn: false
|
// , area: '300px;'
|
// , shade: 0.8
|
// , id: 'WaitLayer' //设定一个id,防止重复弹出
|
// , btnAlign: 'c'
|
// , moveType: 1 //拖拽模式,0或者1
|
// , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">请稍后</div>'
|
// });
|
|
var pid = currentProjectId;
|
var node = getNodeById(pid, layerMenu);
|
var buildings = [];
|
for (let i in node.children) {
|
if (node.children[i].ext.tilesType == "building") {
|
var model = getprimitiveModel(node.children[i].id);
|
if (model != undefined) {
|
buildings.push(model);
|
}
|
}
|
}
|
|
//查询项目下模型的偏移量
|
var modeloffsetx = 0;
|
var modeloffsety = 0;
|
var modeloffsetz = 0;
|
$.ajax({
|
type: "get",
|
async: false,
|
url: httpConfig.webApiUrl + "landstamp/front/3dtileList?id=" + pid,
|
contentType: "application/json;charset=utf-8",
|
timeout: 3000,
|
success: function (data) {
|
if (data == null || data.length == 0) {
|
layer.msg('未查询到数据!');
|
return;
|
}
|
for (var i = 0; i < data.length; i++) {
|
if (data[i].status == "0") {//禁用的模型
|
continue;
|
}
|
var tiletype = data[i].tilesType;
|
if (tiletype == "layer") {
|
modeloffsetx = data[i].tilesX;
|
modeloffsety = data[i].tilesY;
|
modeloffsetz = data[i].tilesZ;
|
}
|
}
|
},
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
console.log("ajax请求失败!");
|
},
|
});
|
|
if (node != undefined) {
|
let projectinfo = node.ext;
|
var lon = projectinfo.lng;
|
var lat = projectinfo.lat;
|
var Ox = projectinfo.dcartX;
|
var Oy = projectinfo.dcartY;
|
var Oz = projectinfo.dcartZ;
|
var positionOnEllipsoid = Cesium.Cartesian3.fromDegrees(lon, lat);
|
var translateMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);
|
var a = options.drawPositions;
|
var list = a.split(";");
|
var newpoints = "";
|
for (var i = 0; i < list.length; i++) {
|
var p = list[i].split(",");
|
if (p.length == 3) {
|
var x = (p[0] - translateMatrix[12]) * translateMatrix[0] +
|
(p[1] - translateMatrix[13]) * translateMatrix[1] +
|
(p[2] - translateMatrix[14]) * translateMatrix[2] + Ox;
|
var y = (p[0] - translateMatrix[12]) * translateMatrix[4] +
|
(p[1] - translateMatrix[13]) * translateMatrix[5] +
|
(p[2] - translateMatrix[14]) * translateMatrix[6] + Oy;
|
var z = (p[0] - translateMatrix[12]) * translateMatrix[8] +
|
(p[1] - translateMatrix[13]) * translateMatrix[9] +
|
(p[2] - translateMatrix[14]) * translateMatrix[10] + Oz;
|
newpoints = newpoints + x;
|
newpoints = newpoints + ",";
|
newpoints = newpoints + y;
|
newpoints = newpoints + ",";
|
newpoints = newpoints + z;
|
newpoints = newpoints + ";";
|
}
|
}
|
newpoints = newpoints.substr(0, newpoints.length - 1);
|
var iscliptube = options.iscliptube;
|
var isinvert = options.isinvert;
|
var depth = options.depth;
|
var isclip = options.type == 'clip' ? 1 : (options.type == 'dig' ? 0 : 2);
|
var iscutearth=options.iscutearth?options.iscutearth:0;
|
var url = httpConfig.webApiUrl + "/landstamp/front/clipping?position=" + newpoints + "&projectId="
|
+ parent.currentProjectId + "&depth=" + depth + "&iscliptube=" + iscliptube + "&isinvert=" + isinvert
|
+ "&isclip=" + isclip +
|
"&userId=1&userName=admin";
|
$.ajax({
|
type: "GET",
|
contentType: "application/json;charset=utf-8",
|
url: url,
|
async: true,
|
dataType: 'json',
|
success: function (result) {
|
if (isclip != 1) {
|
digEarth(options.drawCartesian, isinvert == 1, buildings, isclip == 0,iscutearth);
|
}
|
var tileset = new Cesium.Cesium3DTileset({
|
url: httpConfig.nginxUrl + result.msg,
|
});
|
tileset.modelMatrix[12] = modeloffsetx;
|
tileset.modelMatrix[13] = modeloffsety;
|
tileset.modelMatrix[14] = modeloffsetz;
|
tileset.readyPromise.then(function (tileset) {
|
viewer.scene.primitives.add(tileset);
|
tileset._id = options.type + new Date().format("yyyyMMddhhmmss")
|
var node = {
|
"title": (options.type == 'clip' ? "剖面" : (options.type == 'dig' ? "开挖" : "切块")) + new Date().format("yyyyMMddhhmmss"),
|
"id": tileset._id,
|
"field": "Primitive",
|
"checked": true,
|
"spread": true,
|
"children": [],
|
"ext": {
|
"lng": lon,
|
"lat": lat
|
}
|
};
|
addTreeNode(node, node.id);//将剖切后的模型挂载到当前项目节点下:zzf
|
}).otherwise(function (error) {
|
console.log(error);
|
});
|
}
|
}).then(function (responseText) {
|
//提示以及关闭图层:zzf
|
//changeChildrenChecked(false,)
|
if(responseText.msg.indexOf("json")){
|
for (let i in node.children) {
|
if (node.children[i].ext.tilesType != "building") {
|
changeParentChecked(false,node.children[i])
|
changeChildrenChecked(false,node.children[i])
|
}
|
}
|
layer.closeAll('loading'); //关闭loading
|
let tip=options.type == 'clip'? "剖切" : (options.type == 'dig' ? "开挖" : "切块")
|
layer.msg(tip+"完成")
|
}
|
else{
|
layer.msg(responseText.msg)
|
}
|
});
|
}
|
})
|
}
|
|
//关闭图层和控制树勾选:zzf
|
function changeParentChecked(ischeck, data) {
|
var parentOfData = parent.getParentByChildrenId(data.id);
|
if (parentOfData != null && parentOfData != undefined) {
|
parentOfData.checked = ischeck;
|
changeParentChecked(ischeck, parentOfData);
|
}
|
}
|
function changeChildrenChecked(ischeck, tdata) {
|
tdata.checked = false;
|
var N = new Array();
|
N.push(tdata);
|
while (N.length > 0) {
|
var data = N.shift();
|
if (data.children != null && data.children != undefined) {
|
for (var i in data.children) {
|
N.push(data.children[i]);
|
}
|
}
|
data.checked = ischeck;
|
var model = undefined;
|
switch (data.field) {
|
case 'Primitive': {
|
model = parent.getprimitiveModel(data.id);
|
if (model != undefined) {
|
model.show = ischeck;
|
}
|
break;
|
}
|
case 'Entity': {
|
model = parent.getentityModel(data.id);
|
if (model != undefined) {
|
model.show = ischeck;
|
}
|
break;
|
}
|
case '3DTile': {
|
if (ischeck == true) {
|
model = parent.getprimitiveModel(data.parentId);
|
if (model != undefined) {
|
model.show = ischeck;
|
}
|
}
|
var tile = parent.get3DTile(data.ext.tilesId, data.url);
|
if (tile != undefined) {
|
// tile.children[0]._content._batchTable.setAllShow(ischeck);
|
tile.children[0]._content._model.show = ischeck;
|
}
|
break;
|
}
|
}
|
}
|
}
|
|
function clip() {
|
var objpath = "C:/Users/QT/Desktop/layer";
|
var pa = 547425;
|
var pb = 4207432;
|
var pc = 0;
|
var lon = 114.53966;
|
var lat = 37.99802;
|
var xlsxpath = "C:/Users/QT/Desktop/地层属性.xlsx";
|
var outpath = "D:/Software/Cesium-1.82/Apps/SampleData/my3Dtiles/poumian";
|
var clip = "";
|
for (var i = 0; i < clickpos.length; i++) {
|
for (var j = 0; j < 3; j++) {
|
clip = clip + clickpos[i][j];
|
clip = clip + ",";
|
}
|
clip = clip.substr(0, clip.length - 1);
|
clip = clip + ";";
|
}
|
clip = clip.substr(0, clip.length - 1);
|
var depth = 20;
|
var isclip = 1;
|
var isinvert = 1;
|
var iscliptube = document.getElementById("clip_tube").checked ? 1 : 0;
|
var tubepath = "C:/Users/QT/Desktop/tube";
|
var tubexlsx = "C:/Users/QT/Desktop/管线属性.xlsx";
|
var mydata = "{objpath:'" + objpath + "',";
|
mydata = mydata + "x:" + pa + ",";
|
mydata = mydata + "y:" + pb + ",";
|
mydata = mydata + "z:" + pc + ",";
|
mydata = mydata + "lon:" + lon + ",";
|
mydata = mydata + "lat:" + lat + ",";
|
mydata = mydata + "propertypath:'" + xlsxpath + "',";
|
mydata = mydata + "outpath:'" + outpath + "',";
|
mydata = mydata + "pos:'" + clip + "',";
|
mydata = mydata + "depth:" + depth + ",";
|
mydata = mydata + "isclip:" + isclip + ",";
|
mydata = mydata + "isinvert:" + isinvert + ",";
|
mydata = mydata + "iscliptube:" + iscliptube + ",";
|
mydata = mydata + "tubepath:'" + tubepath + "',";
|
mydata = mydata + "tubexlsx:'" + tubexlsx + "'}";
|
console.log(mydata);
|
|
$.ajax({
|
type: "POST",
|
contentType: "application/json",
|
url: "http://127.0.0.1:801/WebService1.asmx/clipDig", //这里跟上面的情况一样
|
// data:"{x:0,y:0,z:5,r:5,name:'1.obj'}",
|
data: mydata,
|
dataType: 'json',
|
success: function (result) {
|
// alert(result.d);
|
console.log(result);
|
var baseurl = "../../SampleData/my3Dtiles/poumian" + result.d;
|
viewer.scene.primitives.remove(tileset3);
|
tileset3 = new Cesium.Cesium3DTileset({
|
url: baseurl,
|
});
|
viewer.scene.primitives.add(tileset3);
|
tileset3.show = true;
|
}
|
});
|
}
|
function dig() {
|
var objpath = "C:/Users/QT/Desktop/layer";
|
var pa = 547425;
|
var pb = 4207432;
|
var pc = 0;
|
var lon = 114.53966;
|
var lat = 37.99802;
|
var xlsxpath = "C:/Users/QT/Desktop/地层属性.xlsx";
|
var outpath = "D:/Software/Cesium-1.82/Apps/SampleData/my3Dtiles/kaiwa";
|
var clip = "";
|
for (var i = 0; i < clickpos.length; i++) {
|
for (var j = 0; j < 3; j++) {
|
clip = clip + clickpos[i][j];
|
clip = clip + ",";
|
}
|
clip = clip.substr(0, clip.length - 1);
|
clip = clip + ";";
|
}
|
clip = clip.substr(0, clip.length - 1);
|
var depth = document.getElementById("dig_depth").value;
|
var isclip = 0;
|
var isinvert = document.getElementById("dig_invert").checked ? 1 : 0;
|
var iscliptube = document.getElementById("clip_tube").checked ? 1 : 0;
|
var tubepath = "C:/Users/QT/Desktop/tube";
|
var tubexlsx = "C:/Users/QT/Desktop/管线属性.xlsx";
|
var mydata = "{objpath:'" + objpath + "',";
|
mydata = mydata + "x:" + pa + ",";
|
mydata = mydata + "y:" + pb + ",";
|
mydata = mydata + "z:" + pc + ",";
|
mydata = mydata + "lon:" + lon + ",";
|
mydata = mydata + "lat:" + lat + ",";
|
mydata = mydata + "propertypath:'" + xlsxpath + "',";
|
mydata = mydata + "outpath:'" + outpath + "',";
|
mydata = mydata + "pos:'" + clip + "',";
|
mydata = mydata + "depth:" + depth + ",";
|
mydata = mydata + "isclip:" + isclip + ",";
|
mydata = mydata + "isinvert:" + isinvert + ",";
|
mydata = mydata + "iscliptube:" + iscliptube + ",";
|
mydata = mydata + "tubepath:'" + tubepath + "',";
|
mydata = mydata + "tubexlsx:'" + tubexlsx + "'}";
|
console.log(mydata);
|
|
$.ajax({
|
type: "POST",
|
contentType: "application/json",
|
url: "http://127.0.0.1:801/WebService1.asmx/clipDig", //这里跟上面的情况一样
|
// data:"{x:0,y:0,z:5,r:5,name:'1.obj'}",
|
data: mydata,
|
dataType: 'json',
|
success: function (result) {
|
// alert(result.d);
|
console.log(result);
|
var baseurl = "../../SampleData/my3Dtiles/kaiwa" + result.d;
|
viewer.scene.primitives.remove(tileset3);
|
tileset3 = new Cesium.Cesium3DTileset({
|
url: baseurl,
|
});
|
viewer.scene.primitives.add(tileset3);
|
tileset3.show = true;
|
}
|
});
|
}
|
|
function terrainDraw(options) {
|
console.log(options);
|
options.viewer = viewer;
|
options.polylinecolor = new Cesium.Color.fromBytes(255, 124, 0, 255);
|
options.pointcolor = Cesium.Color.WHITE;
|
if (options.drawMarkArr == undefined) {
|
options.drawMarkArr = [];
|
}
|
switch (options.type) {
|
case 'clip': {
|
drawClipPolyline(options);
|
break;
|
}
|
case 'cut': {
|
drawCutPolyline(options);
|
break;
|
}
|
case 'dig': {
|
drawDigtPolygon(options);
|
break;
|
}
|
}
|
}
|
|
function terrainDrawClean(options) {
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
if ((options.viewer.entities.getById('measureDigPolygonEntity') !== undefined)) {
|
options.viewer.entities.removeById('measureDigPolygonEntity');
|
}
|
if ((options.viewer.entities.getById('dynamicClipLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('dynamicClipLineEntity');
|
}
|
if ((options.viewer.entities.getById('measureClipLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('measureClipLineEntity');
|
}
|
if ((options.viewer.entities.getById('dynamicCutLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('dynamicCutLineEntity');
|
}
|
if ((options.viewer.entities.getById('measureCutLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('measureCutLineEntity');
|
}
|
for (var i = 0; i < options.drawMarkArr.length; i++) {
|
options.viewer.entities.remove(options.drawMarkArr[i]);
|
}
|
}
|
|
function terrainRecovery() {
|
viewer.scene.globe.clippingPlanes = undefined;
|
var node = getNodeById(currentProjectId, layerMenu);
|
var buildings = [];
|
for (let i in node.children) {
|
if (node.children[i].ext.tilesType == "building") {
|
var model = getprimitiveModel(node.children[i].id);
|
if (model != undefined) {
|
buildings.push(model);
|
}
|
}
|
}
|
for (var i in buildings) {
|
buildings[i].clippingPlanes.removeAll();
|
}
|
}
|
/**
|
* 绘制剖切路径
|
* options{
|
* 'viewer':viewer, //Cesim.Viewer
|
* 'polylinecolor': Cesium.Color.YELLOW, //线颜色
|
* 'pointcolor': Cesium.Color.RED.withAlpha(0.8), //端点颜色
|
* 'printId': 'textid', //显示路径点坐标的前端elem的id
|
* 'drawMarkArr': //端点entity数组
|
* 'drawHandler': //屏幕控制处理,无需传递
|
* 'drawPositions': //路径端点坐标存储,无需传递,剖切时取用(字符串类型,逗号分隔,需要自行分割)
|
* }
|
*/
|
function drawClipPolyline(options) {
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
if ((options.viewer.entities.getById('dynamicClipLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('dynamicClipLineEntity');
|
}
|
if ((options.viewer.entities.getById('measureClipLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('measureClipLineEntity');
|
}
|
for (var i = 0; i < options.drawMarkArr.length; i++) {
|
options.viewer.entities.remove(options.drawMarkArr[i]);
|
}
|
options.drawMarkArr = [];
|
var isFirst = true;//是否为第一个点
|
var previousPosition;//前一个点的坐标
|
var currentPosition;//当前点坐标
|
var dynamicPositions = [];
|
var dynamicClipLineEntity = options.viewer.entities.add({
|
id: 'dynamicClipLineEntity',
|
polyline: {
|
clampToGround: true,
|
width: 2,
|
material: options.pointcolor,
|
}
|
});
|
dynamicClipLineEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
return dynamicPositions;
|
}, false)
|
//已输入的线段的entity
|
var measureLinePositonsArray = [];//存储已量测的线段的折点
|
var measureClipLineEntity = options.viewer.entities.add({
|
id: 'measureClipLineEntity',
|
polyline: {
|
clampToGround: true,
|
width: 1,
|
material: options.polylinecolor,
|
}
|
});
|
measureClipLineEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
return measureLinePositonsArray;
|
}, false)
|
//节点添加标签
|
function addPin(carPoi) {
|
options.drawMarkArr.push(options.viewer.entities.add({
|
position: carPoi,
|
point: {
|
pixelSize: 5,
|
color: options.pointcolor,
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
outlineWidth: 2,
|
outlineColor: options.polylinecolor
|
},
|
}));
|
}
|
function popPin() {
|
options.viewer.entities.remove(options.drawMarkArr[options.drawMarkArr.length - 1]);
|
measureLinePositonsArray.pop();
|
options.drawMarkArr.pop();
|
if (measureLinePositonsArray.length > 0) {
|
previousPosition = measureLinePositonsArray[measureLinePositonsArray.length - 1];
|
dynamicPositions = [previousPosition, currentPosition];
|
} else {
|
previousPosition = undefined;
|
isFirst = true;
|
dynamicPositions = [];
|
}
|
}
|
options.drawHandler = new Cesium.ScreenSpaceEventHandler(options.viewer.scene.canvas);
|
//左键事件
|
options.drawHandler.setInputAction(function (movement) {
|
console.log(movement);
|
entityMouseClickListenerIsEnable = false;
|
if (isFirst) {
|
previousPosition = options.viewer.scene.pickPosition(movement.position);
|
var cartographic = Cesium.Cartographic.fromCartesian(previousPosition);
|
var height = cartographic.height;//模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.position);
|
previousPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (previousPosition && previousPosition.x) {
|
var tmp1 = previousPosition.clone();
|
measureLinePositonsArray.push(tmp1);
|
isFirst = false;
|
addPin(tmp1);
|
}
|
} else {
|
currentPosition = options.viewer.scene.pickPosition(movement.position);
|
var cartographic = Cesium.Cartographic.fromCartesian(currentPosition);
|
var height = cartographic.height;//模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.position);
|
currentPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (currentPosition && currentPosition.x) {
|
if (Math.abs(previousPosition.x - currentPosition.x) > 0.000001 || Math.abs(previousPosition.y - currentPosition.y) > 0.000001) {
|
var tmp2 = currentPosition.clone();
|
measureLinePositonsArray.push(tmp2);
|
previousPosition = currentPosition.clone();
|
dynamicPositions = [previousPosition, currentPosition];
|
addPin(tmp2);
|
}
|
}
|
}
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
//鼠标移动事件(停下时触发)
|
options.drawHandler.setInputAction(function (movement) {
|
if (!isFirst) {
|
//获取当前点的坐标
|
currentPosition = options.viewer.scene.pickPosition(movement.endPosition);
|
var cartographic = Cesium.Cartographic.fromCartesian(currentPosition);
|
var height = cartographic.height;//模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.endPosition);
|
currentPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (currentPosition && currentPosition.x) {
|
dynamicPositions = [previousPosition, currentPosition];
|
}
|
}
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
//右键事件
|
options.drawHandler.setInputAction(function () {
|
if (!isFirst) {
|
popPin();
|
}
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
//双击事件
|
options.drawHandler.setInputAction(function () {
|
if (!isFirst) {
|
options.viewer.entities.remove(dynamicClipLineEntity);
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
if (options.drawMarkArr.length < 2) {
|
popPin();
|
options.viewer.entities.remove(measureClipLineEntity);
|
} else {
|
let tempPointsStr = '';
|
for (var i = 0; i < measureLinePositonsArray.length; i++) {
|
tempPointsStr += measureLinePositonsArray[i].x + "," + measureLinePositonsArray[i].y + "," + measureLinePositonsArray[i].z + ";";
|
}
|
options.drawPositions = tempPointsStr.substring(0, tempPointsStr.length - 1);
|
terrainDrawPage.update();
|
}
|
for (var i = 0; i < options.drawMarkArr.length; i++) {
|
options.viewer.entities.remove(options.drawMarkArr[i]);
|
}
|
}
|
entityMouseClickListenerIsEnable = true;
|
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
}
|
|
/**
|
* 绘制切块路径
|
* options{
|
* 'viewer':viewer, //Cesim.Viewer
|
* 'polylinecolor': Cesium.Color.YELLOW, //线颜色
|
* 'pointcolor': Cesium.Color.RED.withAlpha(0.8), //端点颜色
|
* 'printId': 'textid', //显示路径点坐标的前端elem的id
|
* 'drawMarkArr': //端点entity数组
|
* 'drawHandler': //屏幕控制处理,无需传递
|
* 'drawPositions': //路径端点坐标存储,无需传递,剖切时取用(字符串类型,逗号分隔,需要自行分割)
|
* }
|
*/
|
function drawCutPolyline(options) {
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
if ((options.viewer.entities.getById('dynamicCutLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('dynamicCutLineEntity');
|
}
|
if ((options.viewer.entities.getById('measureCutLineEntity') !== undefined)) {
|
options.viewer.entities.removeById('measureCutLineEntity');
|
}
|
for (var i = 0; i < options.drawMarkArr.length; i++) {
|
options.viewer.entities.remove(options.drawMarkArr[i]);
|
}
|
options.drawMarkArr = [];
|
var isFirst = true;//是否为第一个点
|
var previousPosition;//前一个点的坐标
|
var currentPosition;//当前点坐标
|
var dynamicPositions = [];
|
var dynamicCutLineEntity = options.viewer.entities.add({
|
id: 'dynamicCutLineEntity',
|
polyline: {
|
clampToGround: true,
|
width: 2,
|
material: Cesium.Color.RED,
|
}
|
});
|
dynamicCutLineEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
return dynamicPositions;
|
}, false);
|
//已输入的线段的entity
|
var measureLinePositonsArray = [];//存储已量测的线段的折点
|
var measureCutLineEntity = options.viewer.entities.add({
|
id: 'measureCutLineEntity',
|
polyline: {
|
clampToGround: true,
|
width: 1,
|
material: options.polylinecolor,
|
}
|
});
|
measureCutLineEntity.polyline.positions = new Cesium.CallbackProperty(function () {
|
return measureLinePositonsArray;
|
}, false);
|
//节点添加标签
|
function addPin(carPoi) {
|
options.drawMarkArr.push(options.viewer.entities.add({
|
position: carPoi,
|
point: {
|
pixelSize: 5,
|
color: options.pointcolor,
|
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
outlineWidth: 2,
|
outlineColor: Cesium.Color.WHITE.withAlpha(1)
|
},
|
}));
|
}
|
function popPin() {
|
options.viewer.entities.remove(options.drawMarkArr[options.drawMarkArr.length - 1]);
|
measureLinePositonsArray.pop();
|
options.drawMarkArr.pop();
|
if (measureLinePositonsArray.length > 0) {
|
previousPosition = measureLinePositonsArray[measureLinePositonsArray.length - 1];
|
dynamicPositions = [previousPosition, currentPosition];
|
} else {
|
previousPosition = undefined;
|
isFirst = true;
|
dynamicPositions = [];
|
}
|
}
|
options.drawHandler = new Cesium.ScreenSpaceEventHandler(options.viewer.scene.canvas);
|
//左键事件
|
options.drawHandler.setInputAction(function (movement) {
|
console.log(movement);
|
if (isFirst) {
|
entityMouseClickListenerIsEnable = false;
|
previousPosition = options.viewer.scene.pickPosition(movement.position);
|
var cartographic = Cesium.Cartographic.fromCartesian(previousPosition);
|
var height = cartographic.height;//模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.position);
|
previousPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (previousPosition && previousPosition.x) {
|
var tmp1 = previousPosition.clone();
|
measureLinePositonsArray.push(tmp1);
|
isFirst = false;
|
addPin(tmp1);
|
}
|
} else {
|
currentPosition = options.viewer.scene.pickPosition(movement.position);
|
var cartographic = Cesium.Cartographic.fromCartesian(currentPosition);
|
var height = cartographic.height;//模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.position);
|
currentPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (currentPosition && currentPosition.x) {
|
if (Math.abs(previousPosition.x - currentPosition.x) > 0.000001 || Math.abs(previousPosition.y - currentPosition.y) > 0.000001) {
|
var tmp2 = currentPosition.clone();
|
measureLinePositonsArray.push(tmp2);
|
previousPosition = currentPosition.clone();
|
dynamicPositions = [previousPosition, currentPosition];
|
addPin(tmp2);
|
}
|
}
|
let tempPointsStr = '';
|
var coordinates = '';
|
for (var i = 0; i < measureLinePositonsArray.length; i++) {
|
tempPointsStr += measureLinePositonsArray[i].x + "," + measureLinePositonsArray[i].y + "," + measureLinePositonsArray[i].z + ";";
|
}
|
options.drawCartesian = JSON.parse(JSON.stringify(measureLinePositonsArray));
|
options.drawPositions = tempPointsStr.substring(0, tempPointsStr.length - 1);
|
terrainDrawPage.update();
|
for (var i = 0; i < options.drawMarkArr.length; i++) {
|
options.viewer.entities.remove(options.drawMarkArr[i]);
|
}
|
viewer.entities.remove(dynamicCutLineEntity);
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
entityMouseClickListenerIsEnable = true;
|
}
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
//鼠标移动事件(停下时触发)
|
options.drawHandler.setInputAction(function (movement) {
|
if (!isFirst) {
|
//获取当前点的坐标
|
currentPosition = options.viewer.scene.pickPosition(movement.endPosition);
|
var cartographic = Cesium.Cartographic.fromCartesian(currentPosition);
|
var height = cartographic.height;//模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.endPosition);
|
currentPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (currentPosition && currentPosition.x) {
|
dynamicPositions = [previousPosition, currentPosition];
|
}
|
}
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
//右键事件
|
options.drawHandler.setInputAction(function () {
|
if (!isFirst) {
|
popPin();
|
}
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
}
|
|
|
/*
|
* options = {
|
* 'viewer':viewer, //Cesim.Viewer
|
* 'polygoncolor':Cesium.Color.YELLOW, //线颜色
|
* 'pointcolor':Cesium.Color.RED.withAlpha(0.8), //端点颜色
|
* 'printId':'textid', //显示路径点坐标的前端elem的id
|
* 'type':'net',
|
* 'drawMarkArr': //端点entity数组,无需传递
|
* 'drawHandler': //屏幕控制处理,无需传递
|
* 'drawPositions': //路径端点坐标存储,无需传递,剖切时取用(字符串类型,逗号分隔,需要自行分割)
|
* };
|
* */
|
//绘制多边形面
|
function drawDigtPolygon(options) {
|
if ((options.viewer.entities.getById('measureDigPolygonEntity') !== undefined)) {
|
options.viewer.entities.removeById('measureDigPolygonEntity');
|
}
|
|
for (var i = 0; i < options.drawMarkArr.length; i++) {
|
options.viewer.entities.remove(options.drawMarkArr[i]);
|
}
|
options.drawMarkArr = [];
|
var polygon = new Cesium.PolygonHierarchy();
|
var measureDigPolygonEntity = options.viewer.entities.add({
|
id: 'measureDigPolygonEntity',
|
polygon: {
|
material: new Cesium.ColorMaterialProperty(Cesium.Color.RED.withAlpha(0.3)),
|
classificationType: Cesium.ClassificationType.BOTH,
|
outline: true,
|
outlineColor: Cesium.Color.WHITE,
|
hierarchy: new Cesium.CallbackProperty(function () {
|
return polygon;
|
}, false)
|
}
|
});
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
options.drawHandler = new Cesium.ScreenSpaceEventHandler(options.viewer.scene.canvas);
|
options.drawHandler.setInputAction(function (movement) {
|
entityMouseClickListenerIsEnable = false;
|
var earthPosition = options.viewer.scene.pickPosition(movement.position);
|
var cartographic = Cesium.Cartographic.fromCartesian(earthPosition);
|
var height = cartographic.height; //模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.position);
|
earthPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
console.log(earthPosition);
|
if (earthPosition && earthPosition.x) {
|
if (polygon.positions.length > 1) {
|
let last = polygon.positions[polygon.positions.length - 2];
|
if (Math.abs(earthPosition.x - last.x) > 0.000001 && Math.abs(earthPosition.y - last.y) > 0.000001) {
|
polygon.positions.push(earthPosition);
|
createPoint(earthPosition);
|
}
|
} else {
|
polygon.positions.push(earthPosition);
|
createPoint(earthPosition);
|
}
|
if (polygon.positions.length > 2) {
|
measureDigPolygonEntity.show = true;
|
}
|
}
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
options.drawHandler.setInputAction(function (movement) {
|
var newPosition = options.viewer.scene.pickPosition(movement.endPosition);
|
var cartographic = Cesium.Cartographic.fromCartesian(newPosition);
|
var height = cartographic.height; //模型高度
|
if (Number(height) < 0) {
|
var ray = options.viewer.camera.getPickRay(movement.endPosition);
|
newPosition = options.viewer.scene.globe.pick(ray, options.viewer.scene);
|
}
|
if (newPosition && newPosition.x) {
|
polygon.positions.pop();
|
polygon.positions.push(newPosition);
|
}
|
if (polygon.positions.length > 2) {
|
measureDigPolygonEntity.show = true;
|
}
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
options.drawHandler.setInputAction(function (movement) {
|
if (polygon.positions.length > 1) {
|
polygon.positions.splice(polygon.positions.length - 2, 1);
|
}
|
if (polygon.positions.length < 3) {
|
measureDigPolygonEntity.show = false;
|
}
|
options.viewer.entities.remove(options.drawMarkArr[options.drawMarkArr.length - 1]);
|
options.drawMarkArr.pop();
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
options.drawHandler.setInputAction(function (movement) {
|
polygon.positions.pop();
|
options.drawHandler = options.drawHandler && options.drawHandler.destroy();
|
if (polygon.positions.length < 3) {
|
options.viewer.entities.remove(measureDigPolygonEntity);
|
} else {
|
var tempPointsStr = '';
|
for (var pindex = 0; pindex < polygon.positions.length; pindex++) {
|
tempPointsStr += polygon.positions[pindex].x + "," + polygon.positions[pindex].y + "," + polygon.positions[pindex].z + ";";
|
|
}
|
options.drawCartesian = JSON.parse(JSON.stringify(polygon.positions));
|
options.drawPositions = tempPointsStr.substring(0, tempPointsStr.length - 1);
|
terrainDrawPage.update();
|
}
|
for (let i in options.drawpointArr) {
|
options.viewer.entities.remove(options.drawpointArr[i]);
|
}
|
entityMouseClickListenerIsEnable = true;
|
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
function createPoint(worldPosition) {
|
options.drawMarkArr.push(options.viewer.entities.add({
|
position: worldPosition,
|
point: {
|
color: Cesium.Color.RED,
|
pixelSize: 5,
|
outlineWidth: 2,
|
outlineColor: Cesium.Color.WHITE,
|
disableDepthTestDistance: Number.POSITIVE_INFINITY
|
}
|
}));
|
}
|
};
|