1.点
let viewer = new Cesium.Viewer('cesiumContainer')
let point = [{
id: 'a',
name: "a",
type: "a",
state: "a",
position: {
x: 经度,
y: 维度
},
text: 'a'
}, {
id: 'b',
name: "b",
type: "b",
state: "b",
position: {
x: 经度,
y: 维度,
},
text: 'b'
}, {
id: 'c',
name: "c",
type: "c",
state: "c",
position: {
x: 经度,
y:维度,
},
text: 'c'
}]
data.map(res => {
viewer.entities.add({
id: res.id,
name: res.name,
position: Cesium.Cartesian3.fromDegrees(res.position.x, res.position.y),
point: {
color: Cesium.Color.RED,
pixelSize: 5
},
label: {
text: res.name,
font: '3pt Source Han Sans CN',
fillColor: Cesium.Color.BLACK,
style: Cesium.LabelStyle.FILL,
outlineWidth: 2,
verticalOrigin: Cesium.VerticalOrigin.CENTER,
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
pixelOffset: new Cesium.Cartesian2(10, 0)
},
monitoItems: {
data: res
}, `
})
})
2.两点间的直线
drawLine() {
let position = this.getPositionById("a", "c")
viewer.entities.add({
id: "ccc",
polyline: {
show: true,
positions: Cesium.Cartesian3.fromDegreesArray(position),
width: 2,
material: new Cesium.Color(0, 0, 1, 1)
}
})
},
getPositionById(id1, id2) {
var entity_1 = viewer.entities.getById(id1);
var position_1 = entity_1.position.getValue(viewer.clock.currentTime);
let cartographic_1 = Cesium.Cartographic.fromCartesian(position_1);
let x1 = parseFloat(Cesium.Math.toDegrees(cartographic_1.longitude).toFixed(6))
let y1 = parseFloat(Cesium.Math.toDegrees(cartographic_1.latitude).toFixed(6))
if (!id2) {
return [x1, y1]
} else {
var entity_2 = viewer.entities.getById(id2);
var position_2 = entity_2.position.getValue(viewer.clock.currentTime);
let cartographic_2 = Cesium.Cartographic.fromCartesian(position_2);
let x2 = parseFloat(Cesium.Math.toDegrees(cartographic_2.longitude).toFixed(6))
let y2 = parseFloat(Cesium.Math.toDegrees(cartographic_2.latitude).toFixed(6))
return [x1, y1, x2, y2,]
}
},
3.两点间的抛物线
drawArcLine() {
let position = this.getPositionById("a", "c")
const startPoint = [position[0], position[1], 0];
const step = 40;
const heightProportion = 0.125;
const dLon = (position[2] - startPoint[0]) / step;
const dLat = (position[3] - startPoint[1]) / step;
const deltaLon = dLon * Math.abs(111000 * Math.cos(position[1]));
const deltaLat = dLat * 111000;
const endPoint = [0, 0, 0];
const heigh = Math.floor(step * Math.sqrt(deltaLon * deltaLon + deltaLat * deltaLat) * heightProportion);
const x2 = (10000 * Math.sqrt(dLon * dLon + dLat * dLat));
const a = (heigh / (x2 * x2));
function y(x, height) { return Math.floor(height - a * x * x); }
for (let i = 1; i <= step; i++) {
endPoint[0] = startPoint[0] + dLon;
endPoint[1] = startPoint[1] + dLat;
const x = x2 * (2 * i / step - 1);
endPoint[2] = y(x, heigh);
viewer.entities.add({
polyline: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(startPoint.concat(endPoint)),
width: 4,
material: new Cesium.PolylineGlowMaterialProperty({
color: Cesium.Color.AQUA.withAlpha(0.9),
outlineWidth: 0.3,
glowPower: 0.3,
})
},
});
startPoint[0] = endPoint[0];
startPoint[1] = endPoint[1];
startPoint[2] = endPoint[2];
}
},