var sgworld = parent.sgworld;
|
var Viewer = sgworld._Viewer;
|
var tooltip = parent.TooltipCesium;
|
|
var num = 100;
|
var clickNum = 0;
|
var this_buff = null;
|
var type = null;
|
var buff_handel = null;
|
var positions = [];
|
|
if (!parent.AnalysisBuffs) {
|
parent.AnalysisBuffs = [];
|
}
|
var buffs = parent.AnalysisBuffs;
|
|
$('#area').on('input propertychange', function (event) {
|
if ($(this).val() == '') {
|
num = 0.0;
|
} else {
|
num = parseFloat($(this).val().replace(/[^\d\.]/g, ''));
|
}
|
if (this_buff) {
|
switch (type) {
|
case 'point':
|
setPointBuff(num);
|
break;
|
case 'polyline':
|
setPolylineBuff(num);
|
break;
|
case 'polygon':
|
setPolygonBuff(num);
|
break;
|
}
|
}
|
});
|
|
//画点
|
$('#DrawPoint').off('click').on('click', function () {
|
DrawPoint();
|
});
|
|
//画线
|
$('#DrawPolyline').off('click').on('click', function () {
|
DrawPolyline();
|
});
|
|
//画面
|
$('#DrawPolygon').off('click').on('click', function () {
|
DrawPolygon();
|
});
|
|
//画面
|
$('#clearBuff').off('click').on('click', function () {
|
clearBuff();
|
});
|
|
//画点
|
function DrawPoint() {
|
if (buff_handel) {
|
buff_handel.destroy();
|
buff_handel = null;
|
}
|
if (clickNum !== 0) {
|
clickNum = 0;
|
}
|
buff_handel = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas);
|
parent.setHandler(buff_handel);
|
this_buff = {
|
entity: null,
|
buff: null
|
};
|
type = 'point';
|
positions = [];
|
//鼠标左键单击
|
buff_handel.setInputAction(function (movement) {
|
var ray = Viewer.camera.getPickRay(movement.position);
|
var cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
|
positions.push(longitude, latitude);
|
this_buff.entity = Viewer.entities.add({
|
name: "新建缓冲点",
|
position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
|
point: {
|
pixelSize: 10,
|
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
|
}
|
});
|
buffs.push(this_buff.entity);
|
tooltip.setVisible(false);
|
buff_handel.destroy();
|
buff_handel = null;
|
setPointBuff(num);
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
//鼠标移动
|
buff_handel.setInputAction(function (movement) {
|
tooltip.showAt(movement.endPosition, "点击绘制点");
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}
|
|
function setPointBuff(radius) {
|
if (!this_buff.buff) {
|
this_buff.buff = Viewer.entities.add({
|
name: "点缓冲区",
|
position: Cesium.Cartesian3.fromDegrees(positions[0], positions[1]),
|
ellipse: {
|
semiMinorAxis: radius,
|
semiMajorAxis: radius,
|
material: new Cesium.ColorMaterialProperty(Cesium.Color.RED.withAlpha(0.4)),
|
//material: Cesium.Color.RED.withAlpha(0.4),
|
zIndex: 0
|
}
|
});
|
positions = null;
|
buffs.push(this_buff.buff);
|
} else {
|
this_buff && this_buff.buff && this_buff.buff.ellipse.semiMinorAxis.setValue(radius);
|
this_buff && this_buff.buff && this_buff.buff.ellipse.semiMajorAxis.setValue(radius);
|
}
|
}
|
|
//画线
|
function DrawPolyline() {
|
if (buff_handel) {
|
buff_handel.destroy();
|
buff_handel = null;
|
}
|
if (clickNum !== 0) {
|
clickNum = 0;
|
}
|
buff_handel = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas);
|
parent.setHandler(buff_handel);
|
this_buff = {
|
entity: null,
|
buff: []
|
};
|
type = 'polyline';
|
positions = [];
|
//鼠标左键单击
|
buff_handel.setInputAction(function (movement) {
|
var ray = Viewer.camera.getPickRay(movement.position);
|
var cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
|
positions.push(longitude, latitude);
|
if (clickNum === 0) {
|
positions.push(longitude, latitude);
|
this_buff.entity = Viewer.entities.add({
|
name: "新建缓冲线",
|
polyline: {
|
positions: Cesium.Cartesian3.fromDegreesArray(positions),
|
width: 2,
|
material: new Cesium.ColorMaterialProperty(Cesium.Color.YELLOW),
|
//material: Cesium.Color.YELLOW,
|
clampToGround: true,
|
zIndex: 1
|
}
|
});
|
this_buff.entity.polyline.positions = new Cesium.CallbackProperty(function () {
|
return Cesium.Cartesian3.fromDegreesArray(positions);
|
}, false);
|
}
|
clickNum++;
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
//鼠标右键单击
|
buff_handel.setInputAction(function (movement) {
|
tooltip.setVisible(false);
|
this_buff.entity.polyline.positions = Cesium.Cartesian3.fromDegreesArray(positions);
|
|
buffs.push(this_buff.entity);
|
buff_handel.destroy();
|
buff_handel = null;
|
setPolylineBuff(num);
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
//鼠标移动
|
buff_handel.setInputAction(function (movement) {
|
if (clickNum === 0) {
|
tooltip.showAt(movement.endPosition, "点击开始绘制第一个点");
|
return;
|
} else {
|
tooltip.showAt(movement.endPosition, "右击结束绘制");
|
}
|
var ray = Viewer.camera.getPickRay(movement.endPosition);
|
var cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
positions.splice(positions.length - 2, 2);
|
positions.push(longitude, latitude);
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}
|
|
function setPolylineBuff(radius) {
|
if (this_buff.buff.length === 0) {
|
for (var i = 0, entity = null; i < positions.length - 2; i += 2) {
|
entity = Viewer.entities.add({
|
name: "线缓冲区",
|
corridor: {
|
positions: Cesium.Cartesian3.fromDegreesArray([positions[i], positions[i + 1], positions[i + 2], positions[i + 3]]),
|
width: radius,
|
material: new Cesium.ColorMaterialProperty(Cesium.Color.RED.withAlpha(0.4)),
|
//material: Cesium.Color.RED.withAlpha(0.4),
|
zIndex: 0
|
}
|
});
|
this_buff.buff.push(entity);
|
buffs.push(entity);
|
}
|
positions = null;
|
} else {
|
this_buff && this_buff.buff && this_buff.buff.forEach(function (buff) {
|
buff.corridor.width.setValue(radius);
|
});
|
}
|
}
|
|
//画面
|
function DrawPolygon() {
|
if (buff_handel) {
|
buff_handel.destroy();
|
buff_handel = null;
|
}
|
if (clickNum !== 0) {
|
clickNum = 0;
|
}
|
buff_handel = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas);
|
parent.setHandler(buff_handel);
|
this_buff = {
|
entity: null,
|
buff: []
|
};
|
type = 'polygon';
|
positions = [];
|
//鼠标左键单击
|
buff_handel.setInputAction(function (movement) {
|
var ray = Viewer.camera.getPickRay(movement.position);
|
var cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
positions.push(longitude, latitude);
|
if (clickNum === 0) {
|
positions.push(longitude, latitude);
|
} else if (clickNum === 1) {
|
this_buff.entity = Viewer.entities.add({
|
name: "新建缓冲面",
|
polygon: {
|
hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions)),
|
material: new Cesium.ColorMaterialProperty(Cesium.Color.YELLOW.withAlpha(0.5)),
|
//material: Cesium.Color.YELLOW.withAlpha(0.5),
|
zIndex: 1
|
}
|
});
|
this_buff.entity.polygon.hierarchy = new Cesium.CallbackProperty(function () {
|
return new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions));
|
}, false);
|
}
|
clickNum++;
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
//鼠标右键单击
|
buff_handel.setInputAction(function (movement) {
|
tooltip.setVisible(false);
|
this_buff.entity.polygon.hierarchy = Cesium.Cartesian3.fromDegreesArray(positions);
|
|
buffs.push(this_buff.entity);
|
buff_handel.destroy();
|
buff_handel = null;
|
setPolygonBuff(num);
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
//鼠标移动
|
buff_handel.setInputAction(function (movement) {
|
if (clickNum === 0) {
|
tooltip.showAt(movement.endPosition, "点击开始绘制第一个点");
|
return;
|
} else {
|
tooltip.showAt(movement.endPosition, "右击结束绘制");
|
}
|
var ray = Viewer.camera.getPickRay(movement.endPosition);
|
var cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
positions.splice(positions.length - 2, 2);
|
positions.push(longitude, latitude);
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}
|
|
//设置面缓冲区
|
function setPolygonBuff(radius) {
|
if (this_buff.buff.length === 0) {
|
positions.push(positions[0], positions[1]);
|
for (var i = 0, entity = null; i < positions.length - 2; i += 2) {
|
entity = Viewer.entities.add({
|
name: "面缓冲区",
|
corridor: {
|
positions: Cesium.Cartesian3.fromDegreesArray([positions[i], positions[i + 1], positions[i + 2], positions[i + 3]]),
|
width: radius,
|
material: new Cesium.ColorMaterialProperty(Cesium.Color.RED.withAlpha(0.4)),
|
//material: Cesium.Color.RED.withAlpha(0.4),
|
zIndex: 0
|
}
|
});
|
this_buff.buff.push(entity);
|
buffs.push(entity);
|
}
|
positions = null;
|
} else {
|
this_buff && this_buff.buff && this_buff.buff.forEach(function (buff) {
|
buff.corridor.width.setValue(radius);
|
});
|
}
|
}
|
|
//清除
|
function clearBuff() {
|
if (buffs.length > 0) {
|
buffs.forEach(function (buff) {
|
Viewer.entities.remove(buff);
|
});
|
buffs.length = 0;
|
}
|
}
|