1c92db51 by 刘远

jikai commit

1 parent 157f001c
import { loadModules } from "esri-loader";
import mapManage from './towMapObjects';
export default class GraphicAttributeManager {
static getInstance() {
mapManage.graphicManager || (mapManage.graphicManager = new this());
}
constructor() {
this.view = mapManage.mapView;
this.initGraphicManager();
}
initGraphicManager() {
};
}
\ No newline at end of file
export default {
createPoint(opt) {
return this.viewer.entities.add({
position: opt.position,
point: opt.point || {
pixelSize: 5,
color: Cesium.Color.YELLOW,
outlineWidth: 2,
outlineColor: Cesium.Color.DARKRED,
disableDepthTestDistance: Number.POSITIVE_INFINITY
},
show: false
});
},
createPolyline(positions) {
let style = this.style || {};
var polyline = this.viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(() => {
return positions || this.positions
}, false),
show: true,
material: style.material || Cesium.Color.YELLOW,
width: style.width || 3,
clampToGround: style.clampToGround == undefined ? false : true
}
});
polyline.objId = this.objId;
return polyline;
},
createPolygon() {
return this.viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return new Cesium.PolygonHierarchy(this.positions)
}, false),
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
},
createRectangle() {
var that = this;
var rectangle = this.viewer.entities.add({
rectangle: {
coordinates: new Cesium.CallbackProperty(() => {
return Cesium.Rectangle.fromCartesianArray([this.leftup, this.rightdown])
}, false),
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
rectangle.objId = this.objId;
return rectangle;
},
createCircle() {
var ellipse = this.viewer.entities.add({
position: this.center,
ellipse: {
semiMajorAxis: new Cesium.CallbackProperty(() => {
return this.radius
}, false),
semiMinorAxis: new Cesium.CallbackProperty(() => {
return this.radius
}, false),
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
ellipse.objId = this.objId;
return ellipse;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
export default class CreateBillboard {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.state = 0; //1为新增 2为编辑 0为清除
this.image = style.image || "content/images/map3d/mark1.png";
this.style = style;
this.billboardArg = {};
this.billboard = null;
this.openModify = false;
if (style) {
var haveImage = false;
for (var i in style) {
if (i == "image" && style[i]) {
haveImage = true;
}
if (style[i]) this.billboardArg[i] = style[i];
}
} else {
console.warn("未设置billboard的参数!");
return;
}
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function(evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer,[]);
that.billboard = that.createBillboard(cartesian);
that.state = 1;
that.handler.destroy();
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.billboard);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function(evt) { //单机开始绘制
that.prompt.updatePrompt(evt.endPosition, "单击新增");
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
createByPositions(lnglatArr, callBack) {
if (!lnglatArr) return;
var position = Cesium.Cartesian3.fromDegrees(lnglatArr[0], lnglatArr[1],lnglatArr[2]);
if (!position) return;
this.billboard = this.createBillboard(position);
callBack(this.billboard);
this.state = 1;
}
startModify() {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
this.modifyHandler.setInputAction(function(evt) {
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.forbidDrawWorld(true);
that.openModify = true;
that.forbidDrawWorld(true);
that.state = 2;
} else {
//if(that.modifyPrompt) that.modifyPrompt.destroy();
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function(evt) { //移动时绘制线
if (!that.billboard || !that.openModify) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer,[]);
if (that.billboard) {
//that.modifyPrompt.updatePrompt(evt.endPosition, "鼠标拖动修改");
that.billboard.position.setValue(cartesian);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function(evt) { //移动时绘制线
if (!that.billboard || !that.openModify) return;
that.openModify = false;
that.forbidDrawWorld(false);
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
}
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if (callback) callback(this.billboard);
}
this.state = 2;
}
createBillboard(cartesian) {
if (!cartesian) return;
var billboard = this.viewer.entities.add({
position: cartesian,
billboard: {
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABMElEQVRIS+2VO0oEQRCGv38RBdFDGQumgijeQFTMjDUQr6CRsgeQDfQCmoqBZkYeQF0f+Cop6AYfa8/UOGtkw8Aw0/19XVVNlxjyUIlvZlPAGjAn6brJXn4UmNk4cJeeDtAFtiWdR0QlgUNfgDzH35+BU2AT6El6q5JFBB9ZN8ADsAXslNLXVJBlnkKPdB9YkdT/GtFvBZnnqepI+sZrQ+C1GQEWJO21GcEr8AQcAquSLgcVvEkElgp8AixLOiudpKjAi3gBLEk6rjqi/r+uwMFXCXxUB5zn1BHcJ/BuBBwR+B00L6n3L/iUATMbAx7TxxlJB62myGFmtgjMAtOS/PyHR7HhhGkDFvy9wMw2UpscDUTgd5J3u/XKy87MboGJADxP7UuarCMYbgQNdl5c8g7JKYAZpEkyjAAAAABJRU5ErkJggg==',
heightReference: this.style.heightReference || Cesium.HeightReference.NONE,
disableDepthTestDistance:Number.MAX_VALUE,
color: Cesium.Color.RED
}
})
billboard.objId = this.objId;
return billboard;
}
getPositions() {
return this.billboard.position;
}
setStyle(obj) {}
remove() {
if (this.billboard) {
this.state = 0;
this.viewer.entities.remove(this.billboard);
this.billboard = null;
}
}
setVisible(vis) {
this.billboard.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
this.openModify = false;
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.billboard) {
this.viewer.entities.remove(this.billboard);
this.billboard = null;
}
this.style = null;
if (this.prompt) {
that.prompt.destroy();
this.prompt = null;
}
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreateCircle {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.circle = null;
this.screenSpaceCameraController = [];
this.style = style;
this.floatPoint = null;
this.centerPoint = null;
this.center = null;
this.float = null;
this.radius = 0;
this.modifyPoint = null;
this.state = 0;
this.pointArr = [];
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.circle]);
if (!that.centerPoint) {
that.center = cartesian;
that.centerPoint = addCompany.createPoint.call(that, {position: cartesian});
that.centerPoint.typeAttr = "center";
that.floatPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
that.float = cartesian.clone();
that.floatPoint.typeAttr = "float";
that.circle = addCompany.createCircle.call(that);
} else {
return;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if (!that.centerPoint) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.circle]);
if (that.floatPoint) {
that.floatPoint.position.setValue(cartesian);
that.float = cartesian.clone();
}
that.radius = Cesium.Cartesian3.distance(cartesian, that.center);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function () { //单机开始绘制
if (!that.circle) {
return;
}
that.state = 1;
that.handler.destroy();
if (that.floatPoint) that.floatPoint.show = false;
if (that.centerPoint) that.centerPoint.show = false;
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.circle);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
startModify(callback) {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
if (that.floatPoint) that.floatPoint.show = true;
if (that.centerPoint) that.centerPoint.show = true;
this.modifyHandler.setInputAction(function (evt) {
if (!that.circle) return;
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
if (that.floatPoint) that.floatPoint.show = false;
if (that.centerPoint) that.centerPoint.show = false;
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
if (callback) callback(that.circle);
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.circle]);
if (!cartesian) {
return;
}
if (that.modifyPoint.typeAttr == "center") {
that.center = cartesian
that.centerPoint.position.setValue(that.center);
that.circle.position.setValue(that.center);
} else {
that.float = cartesian
that.floatPoint.position.setValue(that.float);
}
that.radius = Cesium.Cartesian3.distance(that.float, that.center);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
if (this.floatPoint) this.floatPoint.show = false;
if (this.centerPoint) this.centerPoint.show = false;
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if (callback) callback(this.circle);
}
this.state = 2;
}
getCenter() {
return this.center;
}
getAttr() {
return obj;
}
setStyle(obj) {}
remove() {
if (this.circle) {
this.state = 0;
this.viewer.entities.remove(this.circle);
this.circle = null;
}
}
setVisible(vis) {
this.circle.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.circle) {
this.viewer.entities.remove(this.circle);
this.circle = null;
}
if (this.floatPoint) {
this.viewer.entities.remove(this.floatPoint);
this.floatPoint = null;
}
if (this.centerPoint) {
this.viewer.entities.remove(this.centerPoint);
this.centerPoint = null;
}
this.style = null;
this.modifyPoint = null;
if (this.prompt) this.prompt.destroy();
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreatePolyline {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.polyline = null;
this.positions = [];
this.style = style;
this.floatPoint = null;
this.linePointArr = [];
this.modifyPoint = null;
this.state = 0;
//初始化鼠标提示框
this.prompt = new movePrompt.movePrompt(viewer);
// this.prompt.updatePrompt({x: 495, y: 407}, "单击开始绘制");
}
start(callBack) {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline]);
if (that.positions.length == 0) {
that.positions.push(cartesian.clone());
that.floatPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
}
that.positions.push(cartesian);
var point = addCompany.createPoint.call(that, {position: cartesian});
point.wz = that.linePointArr.length;
that.linePointArr.push(point);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if (that.positions.length < 1) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "单击新增,右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polyline]);
if (that.floatPoint) that.floatPoint.position.setValue(cartesian);
if (that.positions.length == 2) {
if (!Cesium.defined(that.polyline)) {
that.polyline = addCompany.createPolyline.call(that);
}
}
if (that.polyline) {
that.positions.pop();
that.positions.push(cartesian);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function (evt) { //单机开始绘制
if (!that.polyline) {
return;
}
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline]);
that.state = 1;
that.handler.destroy();
if (that.floatPoint) {
if (that.floatPoint) that.floatPoint.show = false;
that.floatPoint = null;
}
that.positions.pop();
that.positions.push(cartesian);
var point = addCompany.createPoint.call(that, {position: cartesian});
point.wz = that.linePointArr.length;
that.linePointArr.push(point);
if(that.prompt){
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.polyline);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
startModify(callback) {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
for (var i = 0; i < that.linePointArr.length; i++) {
var point = that.linePointArr[i];
if (point) point.show = true;
}
this.modifyHandler.setInputAction(function (evt) {
if(!that.polyline) return ;
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
for (var i = 0; i < that.linePointArr.length; i++) {
var point = that.linePointArr[i];
if (point) point.show = false;
}
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
if(callback) callback(that.polyline);
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function (evt) {
if (that.positions.length < 1 || !that.modifyPoint) return;
//that.modifyPrompt.updatePrompt(evt.endPosition, "鼠标拖动修改");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polyline, that.modifyPoint]);
if (cartesian) {
that.modifyPoint.position.setValue(cartesian);
that.positions[that.modifyPoint.wz] = cartesian;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline, that.modifyPoint]);
that.modifyPoint.position.setValue(cartesian);
that.positions[that.modifyPoint.wz] = cartesian;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
for (var i = 0; i < this.linePointArr.length; i++) {
var point = this.linePointArr[i];
if (point) point.show = false;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if(callback) callback(this.polyline);
}
this.state = 2;
}
getPositions() {
return this.positions;
}
getAttr() {
if (!this.polyline) return;
var obj = {};
var line = this.polyline.polyline;
obj.width = line.width._value;
obj.clampToGround = line.clampToGround._value;
obj.color = line.material.color._value;
obj.lineType = "solid";
return obj;
}
setStyle(obj) {}
remove() {
if (this.polyline) {
this.state = 0;
this.viewer.entities.remove(this.polyline);
this.polyline = null;
}
}
setVisible(vis) {
this.polyline.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
this.linePointArr = [];
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.polyline) {
this.viewer.entities.remove(this.polyline);
this.polyline = null;
}
if (this.floatPoint) {
this.viewer.entities.remove(this.floatPoint);
this.floatPoint = null;
}
this.positions = [];
this.style = null;
for (var i = 0; i < this.linePointArr.length; i++) {
var point = this.linePointArr[i];
this.viewer.entities.remove(point);
}
this.linePointArr = [];
this.modifyPoint = null;
if (this.prompt) this.prompt.destroy();
//if (this.modifyPrompt) this.modifyPrompt.destroy();
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreateRectangle {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.rectangle = null;
this.screenSpaceCameraController = [];
this.style = style;
this.rightdownPoint = null;
this.leftupPoint = null;
this.leftup = null;
this.rightdown = null;
this.radius = 0;
this.modifyPoint = null;
this.state = 0;
this.pointArr = [];
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, []);
if (!that.leftupPoint) {
that.leftup = cartesian;
that.leftupPoint = addCompany.createPoint.call(that, {position: cartesian});
that.leftupPoint.typeAttr = "leftup";
that.rightdownPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
that.rightdown = cartesian.clone();
that.rightdownPoint.typeAttr = "rightdown";
that.rectangle = addCompany.createRectangle.call(that);
} else {
return;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if (!that.leftupPoint) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, []);
if (that.rightdownPoint) {
that.rightdownPoint.position.setValue(cartesian);
that.rightdown = cartesian.clone();
}
that.radius = Cesium.Cartesian3.distance(cartesian, that.leftup);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function () { //单机开始绘制
if (!that.rectangle) {
return;
}
that.state = 1;
that.handler.destroy();
if (that.rightdownPoint) that.rightdownPoint.show = false;
if (that.leftupPoint) that.leftupPoint.show = false;
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.rectangle);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
startModify(callback) {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
if (that.rightdownPoint) that.rightdownPoint.show = true;
if (that.leftupPoint) that.leftupPoint.show = true;
this.modifyHandler.setInputAction(function (evt) {
if (!that.rectangle) return;
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
if (that.rightdownPoint) that.rightdownPoint.show = false;
if (that.leftupPoint) that.leftupPoint.show = false;
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
if (callback) callback(that.rectangle);
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.rectangle, that.modifyPoint]);
if (!cartesian) {
return;
}
if (that.modifyPoint.typeAttr == "leftup") {
that.leftup = cartesian
that.leftupPoint.position.setValue(that.leftup);
that.rectangle.position.setValue(that.leftup);
} else {
that.rightdown = cartesian
that.rightdownPoint.position.setValue(that.rightdown);
}
that.radius = Cesium.Cartesian3.distance(that.rightdown, that.leftup);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
if (this.rightdownPoint) this.rightdownPoint.show = false;
if (this.leftupPoint) this.leftupPoint.show = false;
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if (callback) callback(this.rectangle);
}
this.state = 2;
}
getPositions() {
return [this.leftup, this.rightdown]
}
getAttr() {
return obj;
}
setStyle(obj) {}
remove() {
if (this.rectangle) {
this.state = 0;
this.viewer.entities.remove(this.rectangle);
this.rectangle = null;
}
}
setVisible(vis) {
this.rectangle.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.rectangle) {
this.viewer.entities.remove(this.rectangle);
this.rectangle = null;
}
if (this.rightdownPoint) {
this.viewer.entities.remove(this.rightdownPoint);
this.rightdownPoint = null;
}
if (this.leftupPoint) {
this.viewer.entities.remove(this.leftupPoint);
this.leftupPoint = null;
}
this.style = null;
this.modifyPoint = null;
if (this.prompt) this.prompt.destroy();
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import createBillboard from './createBillboard';
import createPolyline from './createPolyline';
import createPolygon from './createPolygon';
import createCircle from './createCircle';
import createRectangle from './createRectangle';
export default {
drawTool: class DrawTool {
constructor(obj) {
if (!obj.viewer || !obj) {
console.warn("缺少必要参数!--viewer");
return;
}
this.viewer = obj.viewer;
this.hasEdit = obj.hasEdit;
this.toolArr = [];
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.show = obj.drawEndShow;
// this.lastSelectEntity = null;
}
startDraw(opt) {
var that = this;
if (opt.type == "polyline") {
var polyline = new createPolyline(this.viewer, opt.style);
polyline.start(function (evt) {
if (that.hasEdit) {
that.unbindEdit();
polyline.startModify(opt.modifySuccess);
that.lastSelectEntity = polyline;
}
if (opt.success) opt.success(evt);
if (that.show == false) polyline.setVisible(false);
});
this.toolArr.push(polyline);
}
if (opt.type == "polygon") {
var polygon = new createPolygon(this.viewer, opt.style);
polygon.start(function () {
if (that.hasEdit) {
that.unbindEdit();
polygon.startModify();
that.lastSelectEntity = polygon;
}
if (opt.success) opt.success(polygon);
if (that.show == false) polygon.setVisible(false);
import { loadModules } from "esri-loader";
import mapManage from './towMapObjects';
export default class DrawTool {
static getInstance() {
mapManage.drawTool || (mapManage.drawTool = new this());
}
constructor() {
this.view = mapManage.mapView;
this.map = mapManage.mapView.map;
this.active = !1;
this.polygon = null;
this.guids = [];
loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then(([w, z, d]) => {
this.options1 || (this.options1 = {}, this.options1.pm = new w({
url: "", width: "", height: "", xoffset: 0, yoffset: 0
}));
this.map.add(this.graphicsLayer = new z({ id: "drawtool" }));
this.draw = new Draw({ view: this.view });
});
this.toolArr.push(polygon);
}
if (opt.type == "billboard") {
var billboard = new createBillboard(this.viewer, opt.style);
billboard.start(function () {
if (that.hasEdit) {
that.unbindEdit();
billboard.startModify();
that.lastSelectEntity = billboard;
}
if (opt.success) opt.success(billboard);
if (that.show == false) billboard.setVisible(false);
activate(c, b) {
this.active = !0;
this.drawType = c.toUpperCase();
this.callback = b;
this.guids = [];
this.downCount = 0;
this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1);
switch (this.drawType) {
case "POINT1":
loadModules(["esri/Graphic"]).then(([h, f]) => {
this.downCount = 0;
this.view.container.addEventListener('mousedown', b => {
var a = new h(b.offsetX, b.offsetY), a = this.view.toMap(a);
console.log(a);
// this.graphic = new f(a, this.options1.pm, null);
// this.graphicsLayer.add(this.graphic);
// console.log('OKOKOK');
// b.stopPropagation()
});
this.toolArr.push(billboard);
}
if (opt.type == "circle") {
var circle = new createCircle(this.viewer, opt.style);
circle.start(function () {
if (that.hasEdit) {
that.unbindEdit();
circle.startModify();
that.lastSelectEntity = circle;
}
if (opt.success) opt.success(circle);
if (that.show == false) circle.setVisible(false);
});
this.toolArr.push(circle);
}
if (opt.type == "rectangle") {
var rectangle = new createRectangle(this.viewer, opt.style);
rectangle.start(function () {
if (that.hasEdit) {
that.unbindEdit();
rectangle.startModify();
that.lastSelectEntity = rectangle;
}
if (opt.success) opt.success(rectangle);
if (that.show == false) rectangle.setVisible(false);
});
this.toolArr.push(rectangle);
}
//重写材质
if (opt.type == "flowPolyline") {
var polyline = new CreatePolyline(this.viewer, opt.style);
polyline.start(function () {
if (that.hasEdit) {
that.unbindEdit();
polyline.startModify();
}
if (opt.success) opt.success(polyline);
});
this.toolArr.push(polyline);
}
}
createByPositions(opt) {
if (this.hasEdit) {
this.bindEdit();
}
if (!opt) opt = {};
if (opt.type == "polyline") {
var polyline = new CreatePolyline(this.viewer, opt.style);
polyline.createByPositions(opt.positions, opt.success);
this.toolArr.push(polyline);
}
if (opt.type == "polygon") {
var polygon = new CreatePolygon(this.viewer, opt.style);
polygon.createByPositions(opt.positions, opt.success);
this.toolArr.push(polygon);
}
if (opt.type == "billboard") {
var billboard = new CreateBillboard(this.viewer, opt.style);
billboard.createByPositions(opt.positions, function(){
if(opt.success) opt.success(billboard)
});
this.toolArr.push(billboard);
}
}
destroy() {
for (var i = 0; i < this.toolArr.length; i++) {
var obj = this.toolArr[i];
obj.destroy();
}
}
bindEdit() {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
for (var i = 0; i < that.toolArr.length; i++) {
if (pick.id.objId == that.toolArr[i].objId && (that.toolArr[i].state == 1||that.toolArr[i].state == 2)) {
if (that.lastSelectEntity) {
that.lastSelectEntity.endModify();
}
that.toolArr[i].startModify();
that.lastSelectEntity = that.toolArr[i];
break;
}
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}
unbindEdit() {
for (var i = 0; i < this.toolArr.length; i++) {
this.toolArr[i].endModify();
}
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
deactivate() {
this.active = !1;
this.drawType = "";
this.downCount = 0;
}
}
\ No newline at end of file
......
export default {
map: undefined
viewer: undefined
}
\ No newline at end of file
......
export default {
pageIndex: '',
pageSize: '',
id: 't0101_4028d839708bbb6d0170946760781016',
data: undefined
}
\ No newline at end of file
import objectManage from './maputils';
export default class shadow {
constructor() {
constructor(opt) {
this.points = [];
this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene);
this.shadowQuery.build();
// this.options = opt;
this.setCurrentTime();
this.init();
}
setCurrentTime() {
let d = new Date();
d.setHours(20)
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(d);
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
objectManage.viewer.clock.multiplier = 1;
objectManage.viewer.clock.shouldAnimate = true;
}
......@@ -45,24 +44,24 @@ export default class shadow {
}
//设置分析对象的开始结束时间
// var dateValue = $("#selDate").val();
var startTime = new Date();
startTime.setHours(8);
this.shadowQuery.startTime = Cesium.JulianDate.fromDate(startTime);
// var startTime = new Date();
// startTime.setHours(18);
this.shadowQuery.startTime = Cesium.JulianDate.fromDate(this.anslysisTime);
var endTime = new Date();
endTime.setHours(22);
endTime.setHours(0);
this.shadowQuery.endTime = Cesium.JulianDate.fromDate(endTime);
this.setCurrentTime();
// this.setCurrentTime();
this.shadowQuery.spacing = 10;
this.shadowQuery.timeInterval = 60;
//设置分析区域、底部高程和拉伸高度
var bh = 20, eh = 20;
// var bh = 20, eh = 20;
this.shadowQuery.qureyRegion({
position : this.points,
bottom : bh,
extend : eh
bottom: this.bottomHeight,
extend: this.extrudeHeight
});
});
}
......
export default {
mapView: undefined
}
\ No newline at end of file