import store from "@/store";
|
import { none } from "ol/centerconstraint";
|
var temporaryTool = {
|
isedit: false,
|
removeTemporaryLayer(res) {
|
var entities = window.Viewer.entities._entities._array;
|
for (var i in entities) {
|
if (entities[i].id == res.id && entities[i]._shpType == res.shpType) {
|
window.Viewer.entities.remove(entities[i])
|
}
|
}
|
},
|
addTemporaryTool(res) {
|
switch (res.type) {
|
case "point":
|
this.addTemporaryPointLayer(res);
|
break;
|
case "label":
|
this.addTemporaryLabelLayer(res);
|
break;
|
case "polygon":
|
this.addTemporaryPolygonLayer(res);
|
break;
|
case "polyline":
|
this.addTemporaryPolylineLayer(res);
|
break;
|
case "rectangle":
|
this.addTemporaryRectangleLayer(res);
|
break;
|
}
|
},
|
addTemporaryLabelLayer(res) {
|
var heightReference;
|
if (res.heightReference) {
|
heightReference = null;
|
} else {
|
heightReference = Number.POSITIVE_INFINITY;
|
}
|
var style;
|
if (res.outline) {
|
style = Cesium.LabelStyle.FILL_AND_OUTLINE
|
} else {
|
style = Cesium.LabelStyle.FILL
|
}
|
|
window.Viewer.entities.add({
|
name: res.cnName,
|
id: res.id,
|
shpType: res.shpType,
|
position: Cesium.Cartesian3.fromDegrees(
|
res.geometry.lng,
|
res.geometry.lat
|
),
|
label: {
|
text: res.text,
|
font: res.font,
|
fillColor: Cesium.Color.fromCssColorString(res.material).withAlpha(
|
res.materialAlpha
|
),
|
backgroundColor: Cesium.Color.fromCssColorString(
|
res.backColor
|
).withAlpha(res.backColor),
|
showBackground: res.showBackground,
|
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
res.near,
|
res.far
|
),
|
outlineColor: Cesium.Color.fromCssColorString(
|
res.outlineColor
|
).withAlpha(res.outlineAlpha),
|
|
outlineWidth: res.width,
|
scale: res.scale,
|
style: style,
|
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,//对齐方式
|
verticalOrigin: Cesium.VerticalOrigin.CENTER,
|
disableDepthTestDistance: heightReference // 被遮挡是否可见(也就是将这个Entity在场景中置顶)
|
},
|
});
|
},
|
addTemporaryPointLayer(res) {
|
var heightReference;
|
if (res.heightReference) {
|
heightReference = null;
|
} else {
|
heightReference = Number.POSITIVE_INFINITY;
|
}
|
window.Viewer.entities.add({
|
name: res.cnName,
|
id: res.id,
|
shpType: res.shpType,
|
position: Cesium.Cartesian3.fromDegrees(
|
res.geometry.lng,
|
res.geometry.lat,
|
res.geometry.alt
|
),
|
point: {
|
color: Cesium.Color.fromCssColorString(res.material).withAlpha(
|
res.materialAlpha
|
),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
res.near,
|
res.far
|
),
|
outlineColor: Cesium.Color.fromCssColorString(
|
res.outlineColor
|
).withAlpha(res.outlineAlpha),
|
outlineWidth: res.outlineWidth,
|
pixelSize: res.size,
|
|
disableDepthTestDistance: heightReference // 被遮挡是否可见(也就是将这个Entity在场景中置顶)
|
},
|
});
|
},
|
addTemporaryPolygonLayer(res) {
|
window.Viewer.entities.add({
|
name: res.cnName,
|
id: res.id,
|
shpType: res.shpType,
|
polygon: {
|
hierarchy: {
|
positions: Cesium.Cartesian3.fromDegreesArray(res.geometry),
|
},
|
material: Cesium.Color.fromCssColorString(res.material).withAlpha(
|
res.materialAlpha
|
),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
res.near,
|
res.far
|
),
|
outline: true,
|
outlineWidth: res.width,
|
outlineColor: Cesium.Color.fromCssColorString(
|
res.outlineColor
|
).withAlpha(res.outlineAlpha),
|
},
|
});
|
},
|
addTemporaryPolylineLayer(res) {
|
var outlinewidth = 0
|
if (res.outline) {
|
outlinewidth = res.width
|
}
|
|
window.Viewer.entities.add({
|
name: res.cnName,
|
id: res.id,
|
shpType: res.shpType,
|
outline: res.outline,
|
polyline: {
|
outline: res.outline,
|
positions: Cesium.Cartesian3.fromDegreesArray(res.geometry),
|
width: res.width,
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
res.near,
|
res.far
|
),
|
|
material: new Cesium.PolylineOutlineMaterialProperty({
|
color: Cesium.Color.fromCssColorString(res.material).withAlpha(
|
res.materialAlpha
|
|
),
|
outlineWidth: outlinewidth,
|
outlineColor: Cesium.Color.fromCssColorString(res.outlineColor).withAlpha(
|
res.outlineAlpha
|
),
|
}),
|
|
clampToGround: res.heightReference,
|
},
|
});
|
},
|
addTemporaryRectangleLayer(res) {
|
window.Viewer.entities.add({
|
name: res.cnName,
|
id: res.id,
|
shpType: res.shpType,
|
rectangle: {
|
coordinates: Cesium.Rectangle.fromDegrees(res.geometry[0],
|
res.geometry[1],
|
res.geometry[2],
|
res.geometry[3]),
|
material: Cesium.Color.fromCssColorString(res.material).withAlpha(
|
res.materialAlpha
|
),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
res.near,
|
res.far
|
),
|
outlineColor: Cesium.Color.fromCssColorString(
|
res.outlineColor
|
).withAlpha(res.outlineAlpha),
|
outlineWidth: res.width,
|
outline: res.outline
|
}
|
})
|
},
|
|
getEntityObj(res) {
|
var entity = null;
|
var entities = window.Viewer.entities._entities._array;
|
for (var i in entities) {
|
if (entities[i].id == res && entities[i].shpType == 'temporaryLayer') {
|
entity = entities[i];
|
}
|
}
|
var obj = null;
|
if (entity) {
|
this.isedit = true;
|
switch (entity.GeoType) {
|
case "point":
|
obj = this.getPointEntityObj(entity);
|
break;
|
case 'label':
|
obj = this.getLabelEntityObj(entity);
|
break;
|
case 'polyline':
|
obj = this.getPolylineEntityObj(entity);
|
break;
|
case 'rectangle':
|
obj = this.getRectangleEntityObj(entity);
|
break;
|
case 'polygon':
|
obj = this.getPolygonEntityObj(entity);
|
break;
|
}
|
}
|
return obj;
|
},
|
setInsertEntityObj(type, res) {
|
var obj = null;
|
this.isedit = false;
|
store.state.temporaryLayer = null;
|
switch (type) {
|
case 'point':
|
obj = this.getPointEntityObj(res);
|
break;
|
case 'label':
|
obj = this.getLabelEntityObj(res);
|
break;
|
case 'polyline':
|
obj = this.getPolylineEntityObj(res);
|
break;
|
case 'rectangle':
|
obj = this.getRectangleEntityObj(res);
|
break;
|
case 'polygon':
|
obj = this.getPolygonEntityObj(res);
|
break;
|
}
|
|
store.state.temporaryLayer = obj;
|
sgworld.Creator.SimpleGraphic.clear();
|
},
|
getPolygonEntityObj(res) {
|
var mataColor = res.polygon.material.color._value;
|
var outlineColor = res.polygon.outlineColor._value;
|
var val = res.polygon.hierarchy.getValue().positions;
|
var geom = [];
|
for (var i in val) {
|
var coord = this.setCartesianToEightFour(val[i])
|
geom.push(coord.lng, coord.lat)
|
}
|
return {
|
id: this.isedit ? res.id : (new Date()).getTime(),
|
cnName: res.name,
|
materialAlpha: mataColor.alpha,
|
outlineAlpha: outlineColor.alpha,
|
material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
|
outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
|
near: res.polygon._distanceDisplayCondition._value.near,
|
far: res.polygon._distanceDisplayCondition._value.far,
|
geometry: geom,
|
type: 'polygon',
|
shpType: 'temporaryLayer',
|
layerType: '多边形',
|
outline: res.outline != null ? res.outline : false,
|
width: res.polygon.outlineWidth ? res.polygon.outlineWidth._value : 1,
|
}
|
},
|
|
|
|
|
getRectangleEntityObj(res) {
|
var mataColor = res.rectangle.material.color._value;
|
var outlineColor = res.rectangle.outlineColor._value;
|
var west = Cesium.Math.toDegrees(
|
res.rectangle._coordinates.getValue().west
|
); // 根据弧度获取到经度
|
var east = Cesium.Math.toDegrees(
|
res.rectangle._coordinates.getValue().east
|
); // 根据弧度获取到纬度
|
var north = Cesium.Math.toDegrees(
|
res.rectangle._coordinates.getValue().north
|
); // 根据弧度获取到经度
|
var south = Cesium.Math.toDegrees(
|
res.rectangle._coordinates.getValue().south
|
); // 根据弧度获取到纬度
|
var geom = [west, south, east, north];
|
return {
|
id: this.isedit ? res.id : (new Date()).getTime(),
|
cnName: res.name,
|
material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
|
outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
|
near: res.rectangle._distanceDisplayCondition._value.near,
|
far: res.rectangle._distanceDisplayCondition._value.far,
|
materialAlpha: mataColor.alpha,
|
outlineAlpha: outlineColor.alpha,
|
outline: res.outline != null ? res.outline : false,
|
width: res.rectangle.outlineWidth._value,
|
geometry: geom,
|
rotation: res.rectangle.rotation ? res.rectangle.rotation : 0,
|
type: 'rectangle',
|
shpType: 'temporaryLayer',
|
layerType: '矩形',
|
|
}
|
|
},
|
|
|
getPolylineEntityObj(res) {
|
var mataColor = res.polyline.material.color._value;
|
var outlineColor = res.polyline.material.outlineColor._value;
|
var val = res.polyline.positions.getValue();
|
var geom = [];
|
for (var i in val) {
|
var coord = this.setCartesianToEightFour(val[i])
|
geom.push(coord.lng, coord.lat)
|
}
|
return {
|
id: this.isedit ? res.id : (new Date()).getTime(),
|
cnName: res.name,
|
type: 'polyline',
|
shpType: 'temporaryLayer',
|
layerType: '线',
|
geometry: geom,
|
heightReference: res.polyline.clampToGround._value,
|
outline: res.outline != null ? res.outline : false,
|
width: res.polyline.width._value,
|
material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
|
outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
|
materialAlpha: mataColor.alpha,
|
outlineAlpha: outlineColor.alpha,
|
near: res.polyline._distanceDisplayCondition._value.near,
|
far: res.polyline._distanceDisplayCondition._value.far,
|
}
|
},
|
getLabelEntityObj(res) {
|
var mataColor = res.label.fillColor._value;
|
var outlineColor = res.label.outlineColor._value;
|
var backColor = res.label.backgroundColor._value;
|
var outline = false;
|
if (res.label.style && res.label.style > 0) {
|
outline = true
|
}
|
var width = 0;
|
if (res.label.outlineWidth && res.label.outlineWidth._value) {
|
width = res.label.outlineWidth._value
|
}
|
|
return {
|
id: this.isedit ? res.id : (new Date()).getTime(),
|
cnName: res.name,
|
text: res.label.text._value,
|
font: res.label.font._value,
|
materialAlpha: mataColor.alpha,
|
outlineAlpha: outlineColor.alpha,
|
backAlpha: backColor.alpha,
|
backColor: this.colorRgbToHex('rgb(' + (backColor.red * 255) + ',' + (backColor.green * 255) + ',' + (backColor.blue * 255) + ')'),
|
material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
|
outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
|
scale: res.label.scale._value,
|
heightReference: res.label.disableDepthTestDistance != null ? false : true,
|
width: width,
|
showBackground: false,
|
outline: outline,
|
near: res.label._distanceDisplayCondition._value.near,
|
far: res.label._distanceDisplayCondition._value.far,
|
geometry: this.setCartesianToEightFour(res.position.getValue()),
|
type: 'label',
|
shpType: 'temporaryLayer',
|
layerType: '文本点',
|
}
|
},
|
|
getPointEntityObj(res) {
|
var mataColor = res.point.color._value;
|
var outlineColor = res.point.outlineColor._value;
|
return {
|
id: this.isedit ? res.id : (new Date()).getTime(),
|
cnName: res.name,
|
materialAlpha: mataColor.alpha,
|
material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
|
outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
|
outlineAlpha: outlineColor.alpha,
|
outlineWidth: res.point.outlineWidth._value,
|
near: res.point._distanceDisplayCondition._value.near,
|
far: res.point._distanceDisplayCondition._value.far,
|
geometry: this.setCartesianToEightFour(res.position.getValue()),
|
width: res.point.outlineWidth._value != null ? res.point.outlineWidth._value : 0,
|
outline: res.point.outlineWidth._value != null ? true : false,
|
type: 'point',
|
shpType: 'temporaryLayer',
|
layerType: '基本点',
|
heightReference: res.point.disableDepthTestDistance != null ? false : true,
|
size: res.point.pixelSize._value,
|
}
|
},
|
|
colorRgbToHex(str) {
|
|
let reg = /^(rgb|RGB)/;
|
if (!reg.test(str)) { return; }
|
var rgb = str.slice(4, str.length - 1).split(",")
|
// 将RGB色号拆分为红、绿、蓝三个通道的值
|
var r = parseInt(rgb[0]);
|
var g = parseInt(rgb[1]);
|
var b = parseInt(rgb[2]);
|
return "#" + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0');
|
},
|
|
setCartesianToEightFour(res) {
|
var std = {}
|
let ellipsoid = Viewer.scene.globe.ellipsoid
|
let cartographic = ellipsoid.cartesianToCartographic(res)
|
std.lat = Cesium.Math.toDegrees(cartographic.latitude)
|
std.lng = Cesium.Math.toDegrees(cartographic.longitude)
|
std.alt = cartographic.height
|
return std
|
},
|
};
|
export default temporaryTool;
|