1c92db51 by 刘远

jikai commit

1 parent 157f001c
1
2 import { loadModules } from "esri-loader";
3 import mapManage from './towMapObjects';
4 export default class GraphicAttributeManager {
5 static getInstance() {
6 mapManage.graphicManager || (mapManage.graphicManager = new this());
7 }
8 constructor() {
9 this.view = mapManage.mapView;
10 this.initGraphicManager();
11 }
12 initGraphicManager() {
13
14 };
15 }
...\ No newline at end of file ...\ No newline at end of file
1 export default {
2 createPoint(opt) {
3 return this.viewer.entities.add({
4 position: opt.position,
5 point: opt.point || {
6 pixelSize: 5,
7 color: Cesium.Color.YELLOW,
8 outlineWidth: 2,
9 outlineColor: Cesium.Color.DARKRED,
10 disableDepthTestDistance: Number.POSITIVE_INFINITY
11 },
12 show: false
13 });
14 },
15 createPolyline(positions) {
16 let style = this.style || {};
17 var polyline = this.viewer.entities.add({
18 polyline: {
19 positions: new Cesium.CallbackProperty(() => {
20 return positions || this.positions
21 }, false),
22 show: true,
23 material: style.material || Cesium.Color.YELLOW,
24 width: style.width || 3,
25 clampToGround: style.clampToGround == undefined ? false : true
26 }
27 });
28 polyline.objId = this.objId;
29 return polyline;
30 },
31 createPolygon() {
32 return this.viewer.entities.add({
33 polygon: {
34 hierarchy: new Cesium.CallbackProperty(() => {
35 return new Cesium.PolygonHierarchy(this.positions)
36 }, false),
37 material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
38 perPositionHeight: true,
39 width: 3,
40 outlineColor: Cesium.Color.BLACK,
41 outlineWidth: 3,
42 outline: true
43 }
44 });
45 },
46 createRectangle() {
47 var that = this;
48 var rectangle = this.viewer.entities.add({
49 rectangle: {
50 coordinates: new Cesium.CallbackProperty(() => {
51 return Cesium.Rectangle.fromCartesianArray([this.leftup, this.rightdown])
52 }, false),
53 material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
54 perPositionHeight: true,
55 width: 3,
56 outlineColor: Cesium.Color.BLACK,
57 outlineWidth: 3,
58 outline: true
59 }
60 });
61 rectangle.objId = this.objId;
62 return rectangle;
63 },
64 createCircle() {
65 var ellipse = this.viewer.entities.add({
66 position: this.center,
67 ellipse: {
68 semiMajorAxis: new Cesium.CallbackProperty(() => {
69 return this.radius
70 }, false),
71 semiMinorAxis: new Cesium.CallbackProperty(() => {
72 return this.radius
73 }, false),
74 material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
75 perPositionHeight: true,
76 width: 3,
77 outlineColor: Cesium.Color.BLACK,
78 outlineWidth: 3,
79 outline: true
80 }
81 });
82 ellipse.objId = this.objId;
83 return ellipse;
84 }
85 }
...\ No newline at end of file ...\ No newline at end of file
1 import movePrompt from './MovePrompt';
2 export default class CreateBillboard {
3 constructor(viewer, style) {
4 this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
5 this.viewer = viewer;
6 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
7 this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
8 this.state = 0; //1为新增 2为编辑 0为清除
9 this.image = style.image || "content/images/map3d/mark1.png";
10 this.style = style;
11 this.billboardArg = {};
12 this.billboard = null;
13 this.openModify = false;
14 if (style) {
15 var haveImage = false;
16 for (var i in style) {
17 if (i == "image" && style[i]) {
18 haveImage = true;
19 }
20 if (style[i]) this.billboardArg[i] = style[i];
21 }
22 } else {
23 console.warn("未设置billboard的参数!");
24 return;
25 }
26 this.prompt = new movePrompt.movePrompt(viewer);
27 }
28 start(callBack) {
29 var that = this;
30 this.handler.setInputAction(function(evt) { //单机开始绘制
31 var cartesian = that.getCatesian3FromPX(evt.position, that.viewer,[]);
32 that.billboard = that.createBillboard(cartesian);
33 that.state = 1;
34 that.handler.destroy();
35 if (that.prompt) {
36 that.prompt.destroy();
37 that.prompt = null;
38 }
39 if (callBack) callBack(that.billboard);
40 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
41 this.handler.setInputAction(function(evt) { //单机开始绘制
42 that.prompt.updatePrompt(evt.endPosition, "单击新增");
43 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
44 }
45 createByPositions(lnglatArr, callBack) {
46 if (!lnglatArr) return;
47 var position = Cesium.Cartesian3.fromDegrees(lnglatArr[0], lnglatArr[1],lnglatArr[2]);
48 if (!position) return;
49 this.billboard = this.createBillboard(position);
50 callBack(this.billboard);
51 this.state = 1;
52 }
53 startModify() {
54 if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
55 if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
56 var that = this;
57 this.modifyHandler.setInputAction(function(evt) {
58
59 var pick = that.viewer.scene.pick(evt.position);
60 if (Cesium.defined(pick) && pick.id) {
61 if (!pick.id.objId)
62 that.forbidDrawWorld(true);
63 that.openModify = true;
64 that.forbidDrawWorld(true);
65 that.state = 2;
66 } else {
67 //if(that.modifyPrompt) that.modifyPrompt.destroy();
68 }
69
70 }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
71 this.modifyHandler.setInputAction(function(evt) { //移动时绘制线
72 if (!that.billboard || !that.openModify) return;
73 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer,[]);
74 if (that.billboard) {
75 //that.modifyPrompt.updatePrompt(evt.endPosition, "鼠标拖动修改");
76 that.billboard.position.setValue(cartesian);
77 }
78 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
79
80 this.modifyHandler.setInputAction(function(evt) { //移动时绘制线
81 if (!that.billboard || !that.openModify) return;
82 that.openModify = false;
83 that.forbidDrawWorld(false);
84 if (that.modifyHandler) {
85 that.modifyHandler.destroy();
86 that.modifyHandler = null;
87 }
88 }, Cesium.ScreenSpaceEventType.LEFT_UP);
89 }
90 endModify(callback) {
91 if (this.modifyHandler) {
92 this.modifyHandler.destroy();
93 this.modifyHandler = null;
94 if (callback) callback(this.billboard);
95 }
96 this.state = 2;
97 }
98 createBillboard(cartesian) {
99 if (!cartesian) return;
100 var billboard = this.viewer.entities.add({
101 position: cartesian,
102 billboard: {
103 image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABMElEQVRIS+2VO0oEQRCGv38RBdFDGQumgijeQFTMjDUQr6CRsgeQDfQCmoqBZkYeQF0f+Cop6AYfa8/UOGtkw8Aw0/19XVVNlxjyUIlvZlPAGjAn6brJXn4UmNk4cJeeDtAFtiWdR0QlgUNfgDzH35+BU2AT6El6q5JFBB9ZN8ADsAXslNLXVJBlnkKPdB9YkdT/GtFvBZnnqepI+sZrQ+C1GQEWJO21GcEr8AQcAquSLgcVvEkElgp8AixLOiudpKjAi3gBLEk6rjqi/r+uwMFXCXxUB5zn1BHcJ/BuBBwR+B00L6n3L/iUATMbAx7TxxlJB62myGFmtgjMAtOS/PyHR7HhhGkDFvy9wMw2UpscDUTgd5J3u/XKy87MboGJADxP7UuarCMYbgQNdl5c8g7JKYAZpEkyjAAAAABJRU5ErkJggg==',
104 heightReference: this.style.heightReference || Cesium.HeightReference.NONE,
105 disableDepthTestDistance:Number.MAX_VALUE,
106 color: Cesium.Color.RED
107 }
108 })
109 billboard.objId = this.objId;
110 return billboard;
111 }
112 getPositions() {
113 return this.billboard.position;
114 }
115 setStyle(obj) {}
116 remove() {
117 if (this.billboard) {
118 this.state = 0;
119 this.viewer.entities.remove(this.billboard);
120 this.billboard = null;
121 }
122 }
123 setVisible(vis) {
124 this.billboard.show = vis;
125 }
126 forbidDrawWorld(isForbid) {
127 this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
128 this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
129 this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
130 this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
131 }
132 destroy() {
133 this.openModify = false;
134 if (this.handler) {
135 this.handler.destroy();
136 this.handler = null;
137 }
138 if (this.modifyHandler) {
139 this.modifyHandler.destroy();
140 this.modifyHandler = null;
141 }
142 if (this.billboard) {
143 this.viewer.entities.remove(this.billboard);
144 this.billboard = null;
145 }
146 this.style = null;
147 if (this.prompt) {
148 that.prompt.destroy();
149 this.prompt = null;
150 }
151 }
152 getCatesian3FromPX(px, viewer, entitys) {
153 var picks = viewer.scene.drillPick(px);
154 this.viewer.scene.render();
155 var cartesian;
156 var isOn3dtiles = false;
157 for (var i = 0; i < picks.length; i++) {
158 var isContinue = false;
159 for (var step = 0; step < entitys.length; step++) {
160 if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
161 isContinue = true;
162 break;
163 }
164 }
165 if (isContinue) continue;
166 if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
167 isOn3dtiles = true;
168 }
169 }
170 if (isOn3dtiles) {
171 cartesian = viewer.scene.pickPosition(px);
172 } else {
173 var ray = viewer.camera.getPickRay(px);
174 if (!ray) return null;
175 cartesian = viewer.scene.globe.pick(ray, viewer.scene);
176 }
177 return cartesian;
178 }
179 }
...\ No newline at end of file ...\ No newline at end of file
1 import movePrompt from './MovePrompt';
2 import addCompany from './addCompany';
3 export default class CreateCircle {
4 constructor(viewer, style) {
5 this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
6 this.viewer = viewer;
7 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
8 this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
9 this.circle = null;
10 this.screenSpaceCameraController = [];
11 this.style = style;
12 this.floatPoint = null;
13 this.centerPoint = null;
14 this.center = null;
15 this.float = null;
16 this.radius = 0;
17 this.modifyPoint = null;
18 this.state = 0;
19 this.pointArr = [];
20 this.prompt = new movePrompt.movePrompt(viewer);
21 }
22 start(callBack) {
23 var that = this;
24 this.handler.setInputAction(function (evt) { //单机开始绘制
25 var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.circle]);
26 if (!that.centerPoint) {
27 that.center = cartesian;
28 that.centerPoint = addCompany.createPoint.call(that, {position: cartesian});
29 that.centerPoint.typeAttr = "center";
30 that.floatPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
31 that.float = cartesian.clone();
32 that.floatPoint.typeAttr = "float";
33 that.circle = addCompany.createCircle.call(that);
34 } else {
35 return;
36 }
37 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
38 this.handler.setInputAction(function (evt) { //移动时绘制线
39 if (!that.centerPoint) {
40 that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
41 return;
42 }
43 that.prompt.updatePrompt(evt.endPosition, "右键结束");
44 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.circle]);
45 if (that.floatPoint) {
46 that.floatPoint.position.setValue(cartesian);
47 that.float = cartesian.clone();
48 }
49 that.radius = Cesium.Cartesian3.distance(cartesian, that.center);
50 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
51 this.handler.setInputAction(function () { //单机开始绘制
52 if (!that.circle) {
53 return;
54 }
55 that.state = 1;
56 that.handler.destroy();
57 if (that.floatPoint) that.floatPoint.show = false;
58 if (that.centerPoint) that.centerPoint.show = false;
59 if (that.prompt) {
60 that.prompt.destroy();
61 that.prompt = null;
62 }
63 if (callBack) callBack(that.circle);
64 }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
65 }
66 startModify(callback) {
67 if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
68 if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
69 var that = this;
70 if (that.floatPoint) that.floatPoint.show = true;
71 if (that.centerPoint) that.centerPoint.show = true;
72 this.modifyHandler.setInputAction(function (evt) {
73 if (!that.circle) return;
74 var pick = that.viewer.scene.pick(evt.position);
75 if (Cesium.defined(pick) && pick.id) {
76 if (!pick.id.objId)
77 that.modifyPoint = pick.id;
78 that.forbidDrawWorld(true);
79 } else {
80 if (that.floatPoint) that.floatPoint.show = false;
81 if (that.centerPoint) that.centerPoint.show = false;
82 if (that.modifyHandler) {
83 that.modifyHandler.destroy();
84 that.modifyHandler = null;
85 if (callback) callback(that.circle);
86 }
87 that.state = 2;
88 }
89 }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
90 this.modifyHandler.setInputAction(function (evt) {
91 if (!that.modifyPoint) return;
92 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.circle]);
93 if (!cartesian) {
94 return;
95 }
96 if (that.modifyPoint.typeAttr == "center") {
97 that.center = cartesian
98 that.centerPoint.position.setValue(that.center);
99 that.circle.position.setValue(that.center);
100 } else {
101 that.float = cartesian
102 that.floatPoint.position.setValue(that.float);
103 }
104 that.radius = Cesium.Cartesian3.distance(that.float, that.center);
105 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
106
107 this.modifyHandler.setInputAction(function (evt) {
108 if (!that.modifyPoint) return;
109 that.modifyPoint = null;
110 that.forbidDrawWorld(false);
111 }, Cesium.ScreenSpaceEventType.LEFT_UP);
112 }
113 endModify(callback) {
114 if (this.floatPoint) this.floatPoint.show = false;
115 if (this.centerPoint) this.centerPoint.show = false;
116 if (this.modifyHandler) {
117 this.modifyHandler.destroy();
118 this.modifyHandler = null;
119 if (callback) callback(this.circle);
120 }
121 this.state = 2;
122 }
123 getCenter() {
124 return this.center;
125 }
126 getAttr() {
127 return obj;
128 }
129 setStyle(obj) {}
130 remove() {
131 if (this.circle) {
132 this.state = 0;
133 this.viewer.entities.remove(this.circle);
134 this.circle = null;
135 }
136 }
137 setVisible(vis) {
138 this.circle.show = vis;
139 }
140 forbidDrawWorld(isForbid) {
141 this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
142 this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
143 this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
144 this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
145 }
146 destroy() {
147 if (this.handler) {
148 this.handler.destroy();
149 this.handler = null;
150 }
151 if (this.modifyHandler) {
152 this.modifyHandler.destroy();
153 this.modifyHandler = null;
154 }
155 if (this.circle) {
156 this.viewer.entities.remove(this.circle);
157 this.circle = null;
158 }
159 if (this.floatPoint) {
160 this.viewer.entities.remove(this.floatPoint);
161 this.floatPoint = null;
162 }
163 if (this.centerPoint) {
164 this.viewer.entities.remove(this.centerPoint);
165 this.centerPoint = null;
166 }
167 this.style = null;
168 this.modifyPoint = null;
169 if (this.prompt) this.prompt.destroy();
170 }
171 getCatesian3FromPX(px, viewer, entitys) {
172 var picks = viewer.scene.drillPick(px);
173 this.viewer.scene.render();
174 var cartesian;
175 var isOn3dtiles = false;
176 for (var i = 0; i < picks.length; i++) {
177 var isContinue = false;
178 for (var step = 0; step < entitys.length; step++) {
179 if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
180 isContinue = true;
181 break;
182 }
183 }
184 if (isContinue) continue;
185 if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
186 isOn3dtiles = true;
187 }
188 }
189 if (isOn3dtiles) {
190 cartesian = viewer.scene.pickPosition(px);
191 } else {
192 var ray = viewer.camera.getPickRay(px);
193 if (!ray) return null;
194 cartesian = viewer.scene.globe.pick(ray, viewer.scene);
195 }
196 return cartesian;
197 }
198 }
...\ No newline at end of file ...\ No newline at end of file
1 import movePrompt from './MovePrompt';
2 import addCompany from './addCompany';
3 export default class CreatePolyline {
4 constructor(viewer, style) {
5 this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
6 this.viewer = viewer;
7 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
8 this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
9 this.polyline = null;
10 this.positions = [];
11 this.style = style;
12 this.floatPoint = null;
13 this.linePointArr = [];
14 this.modifyPoint = null;
15 this.state = 0;
16 //初始化鼠标提示框
17 this.prompt = new movePrompt.movePrompt(viewer);
18 // this.prompt.updatePrompt({x: 495, y: 407}, "单击开始绘制");
19 }
20 start(callBack) {
21 var that = this;
22 this.handler.setInputAction(function (evt) { //单机开始绘制
23 var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline]);
24 if (that.positions.length == 0) {
25 that.positions.push(cartesian.clone());
26 that.floatPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
27 }
28 that.positions.push(cartesian);
29 var point = addCompany.createPoint.call(that, {position: cartesian});
30 point.wz = that.linePointArr.length;
31 that.linePointArr.push(point);
32 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
33 this.handler.setInputAction(function (evt) { //移动时绘制线
34 if (that.positions.length < 1) {
35 that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
36 return;
37 }
38 that.prompt.updatePrompt(evt.endPosition, "单击新增,右键结束");
39 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polyline]);
40 if (that.floatPoint) that.floatPoint.position.setValue(cartesian);
41 if (that.positions.length == 2) {
42 if (!Cesium.defined(that.polyline)) {
43 that.polyline = addCompany.createPolyline.call(that);
44 }
45 }
46 if (that.polyline) {
47 that.positions.pop();
48 that.positions.push(cartesian);
49 }
50 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
51 this.handler.setInputAction(function (evt) { //单机开始绘制
52 if (!that.polyline) {
53 return;
54 }
55 var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline]);
56 that.state = 1;
57 that.handler.destroy();
58 if (that.floatPoint) {
59 if (that.floatPoint) that.floatPoint.show = false;
60 that.floatPoint = null;
61 }
62 that.positions.pop();
63 that.positions.push(cartesian);
64 var point = addCompany.createPoint.call(that, {position: cartesian});
65 point.wz = that.linePointArr.length;
66 that.linePointArr.push(point);
67 if(that.prompt){
68 that.prompt.destroy();
69 that.prompt = null;
70 }
71 if (callBack) callBack(that.polyline);
72 }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
73 }
74 startModify(callback) {
75 if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
76 if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
77 var that = this;
78 for (var i = 0; i < that.linePointArr.length; i++) {
79 var point = that.linePointArr[i];
80 if (point) point.show = true;
81 }
82 this.modifyHandler.setInputAction(function (evt) {
83 if(!that.polyline) return ;
84 var pick = that.viewer.scene.pick(evt.position);
85 if (Cesium.defined(pick) && pick.id) {
86 if (!pick.id.objId)
87 that.modifyPoint = pick.id;
88 that.forbidDrawWorld(true);
89 } else {
90 for (var i = 0; i < that.linePointArr.length; i++) {
91 var point = that.linePointArr[i];
92 if (point) point.show = false;
93 }
94 if (that.modifyHandler) {
95 that.modifyHandler.destroy();
96 that.modifyHandler = null;
97 if(callback) callback(that.polyline);
98 }
99 that.state = 2;
100 }
101 }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
102 this.modifyHandler.setInputAction(function (evt) {
103 if (that.positions.length < 1 || !that.modifyPoint) return;
104 //that.modifyPrompt.updatePrompt(evt.endPosition, "鼠标拖动修改");
105 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polyline, that.modifyPoint]);
106 if (cartesian) {
107 that.modifyPoint.position.setValue(cartesian);
108 that.positions[that.modifyPoint.wz] = cartesian;
109 }
110 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
111
112 this.modifyHandler.setInputAction(function (evt) {
113 if (!that.modifyPoint) return;
114 var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline, that.modifyPoint]);
115 that.modifyPoint.position.setValue(cartesian);
116 that.positions[that.modifyPoint.wz] = cartesian;
117 that.modifyPoint = null;
118 that.forbidDrawWorld(false);
119 }, Cesium.ScreenSpaceEventType.LEFT_UP);
120 }
121 endModify(callback) {
122 for (var i = 0; i < this.linePointArr.length; i++) {
123 var point = this.linePointArr[i];
124 if (point) point.show = false;
125 }
126 if (this.modifyHandler) {
127 this.modifyHandler.destroy();
128 this.modifyHandler = null;
129 if(callback) callback(this.polyline);
130 }
131 this.state = 2;
132 }
133 getPositions() {
134 return this.positions;
135 }
136 getAttr() {
137 if (!this.polyline) return;
138 var obj = {};
139 var line = this.polyline.polyline;
140 obj.width = line.width._value;
141 obj.clampToGround = line.clampToGround._value;
142 obj.color = line.material.color._value;
143 obj.lineType = "solid";
144 return obj;
145 }
146 setStyle(obj) {}
147 remove() {
148 if (this.polyline) {
149 this.state = 0;
150 this.viewer.entities.remove(this.polyline);
151 this.polyline = null;
152 }
153 }
154 setVisible(vis) {
155 this.polyline.show = vis;
156 }
157 forbidDrawWorld(isForbid) {
158 this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
159 this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
160 this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
161 this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
162 }
163 destroy() {
164 this.linePointArr = [];
165 if (this.handler) {
166 this.handler.destroy();
167 this.handler = null;
168 }
169 if (this.modifyHandler) {
170 this.modifyHandler.destroy();
171 this.modifyHandler = null;
172 }
173 if (this.polyline) {
174 this.viewer.entities.remove(this.polyline);
175 this.polyline = null;
176 }
177 if (this.floatPoint) {
178 this.viewer.entities.remove(this.floatPoint);
179 this.floatPoint = null;
180 }
181 this.positions = [];
182 this.style = null;
183 for (var i = 0; i < this.linePointArr.length; i++) {
184 var point = this.linePointArr[i];
185 this.viewer.entities.remove(point);
186 }
187 this.linePointArr = [];
188 this.modifyPoint = null;
189 if (this.prompt) this.prompt.destroy();
190 //if (this.modifyPrompt) this.modifyPrompt.destroy();
191 }
192 getCatesian3FromPX(px, viewer, entitys) {
193 var picks = viewer.scene.drillPick(px);
194 this.viewer.scene.render();
195 var cartesian;
196 var isOn3dtiles = false;
197 for (var i = 0; i < picks.length; i++) {
198 var isContinue = false;
199 for (var step = 0; step < entitys.length; step++) {
200 if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
201 isContinue = true;
202 break;
203 }
204 }
205 if (isContinue) continue;
206 if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
207 isOn3dtiles = true;
208 }
209 }
210 if (isOn3dtiles) {
211 cartesian = viewer.scene.pickPosition(px);
212 } else {
213 var ray = viewer.camera.getPickRay(px);
214 if (!ray) return null;
215 cartesian = viewer.scene.globe.pick(ray, viewer.scene);
216 }
217 return cartesian;
218 }
219 }
...\ No newline at end of file ...\ No newline at end of file
1 import movePrompt from './MovePrompt';
2 import addCompany from './addCompany';
3 export default class CreateRectangle {
4 constructor(viewer, style) {
5 this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
6 this.viewer = viewer;
7 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
8 this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
9 this.rectangle = null;
10 this.screenSpaceCameraController = [];
11 this.style = style;
12 this.rightdownPoint = null;
13 this.leftupPoint = null;
14 this.leftup = null;
15 this.rightdown = null;
16 this.radius = 0;
17 this.modifyPoint = null;
18 this.state = 0;
19 this.pointArr = [];
20 this.prompt = new movePrompt.movePrompt(viewer);
21 }
22 start(callBack) {
23 var that = this;
24 this.handler.setInputAction(function (evt) { //单机开始绘制
25 var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, []);
26 if (!that.leftupPoint) {
27 that.leftup = cartesian;
28 that.leftupPoint = addCompany.createPoint.call(that, {position: cartesian});
29 that.leftupPoint.typeAttr = "leftup";
30 that.rightdownPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
31 that.rightdown = cartesian.clone();
32 that.rightdownPoint.typeAttr = "rightdown";
33 that.rectangle = addCompany.createRectangle.call(that);
34 } else {
35 return;
36 }
37 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
38 this.handler.setInputAction(function (evt) { //移动时绘制线
39 if (!that.leftupPoint) {
40 that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
41 return;
42 }
43 that.prompt.updatePrompt(evt.endPosition, "右键结束");
44 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, []);
45 if (that.rightdownPoint) {
46 that.rightdownPoint.position.setValue(cartesian);
47 that.rightdown = cartesian.clone();
48 }
49 that.radius = Cesium.Cartesian3.distance(cartesian, that.leftup);
50 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
51 this.handler.setInputAction(function () { //单机开始绘制
52 if (!that.rectangle) {
53 return;
54 }
55 that.state = 1;
56 that.handler.destroy();
57 if (that.rightdownPoint) that.rightdownPoint.show = false;
58 if (that.leftupPoint) that.leftupPoint.show = false;
59 if (that.prompt) {
60 that.prompt.destroy();
61 that.prompt = null;
62 }
63 if (callBack) callBack(that.rectangle);
64 }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
65 }
66 startModify(callback) {
67 if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
68 if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
69 var that = this;
70 if (that.rightdownPoint) that.rightdownPoint.show = true;
71 if (that.leftupPoint) that.leftupPoint.show = true;
72 this.modifyHandler.setInputAction(function (evt) {
73 if (!that.rectangle) return;
74 var pick = that.viewer.scene.pick(evt.position);
75 if (Cesium.defined(pick) && pick.id) {
76 if (!pick.id.objId)
77 that.modifyPoint = pick.id;
78 that.forbidDrawWorld(true);
79 } else {
80 if (that.rightdownPoint) that.rightdownPoint.show = false;
81 if (that.leftupPoint) that.leftupPoint.show = false;
82 if (that.modifyHandler) {
83 that.modifyHandler.destroy();
84 that.modifyHandler = null;
85 if (callback) callback(that.rectangle);
86 }
87 that.state = 2;
88 }
89 }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
90 this.modifyHandler.setInputAction(function (evt) {
91 if (!that.modifyPoint) return;
92 var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.rectangle, that.modifyPoint]);
93 if (!cartesian) {
94 return;
95 }
96 if (that.modifyPoint.typeAttr == "leftup") {
97 that.leftup = cartesian
98 that.leftupPoint.position.setValue(that.leftup);
99 that.rectangle.position.setValue(that.leftup);
100 } else {
101 that.rightdown = cartesian
102 that.rightdownPoint.position.setValue(that.rightdown);
103 }
104 that.radius = Cesium.Cartesian3.distance(that.rightdown, that.leftup);
105 }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
106
107 this.modifyHandler.setInputAction(function (evt) {
108 if (!that.modifyPoint) return;
109 that.modifyPoint = null;
110 that.forbidDrawWorld(false);
111 }, Cesium.ScreenSpaceEventType.LEFT_UP);
112 }
113 endModify(callback) {
114 if (this.rightdownPoint) this.rightdownPoint.show = false;
115 if (this.leftupPoint) this.leftupPoint.show = false;
116 if (this.modifyHandler) {
117 this.modifyHandler.destroy();
118 this.modifyHandler = null;
119 if (callback) callback(this.rectangle);
120 }
121 this.state = 2;
122 }
123 getPositions() {
124 return [this.leftup, this.rightdown]
125 }
126 getAttr() {
127 return obj;
128 }
129 setStyle(obj) {}
130 remove() {
131 if (this.rectangle) {
132 this.state = 0;
133 this.viewer.entities.remove(this.rectangle);
134 this.rectangle = null;
135 }
136 }
137 setVisible(vis) {
138 this.rectangle.show = vis;
139 }
140 forbidDrawWorld(isForbid) {
141 this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
142 this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
143 this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
144 this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
145 }
146 destroy() {
147 if (this.handler) {
148 this.handler.destroy();
149 this.handler = null;
150 }
151 if (this.modifyHandler) {
152 this.modifyHandler.destroy();
153 this.modifyHandler = null;
154 }
155 if (this.rectangle) {
156 this.viewer.entities.remove(this.rectangle);
157 this.rectangle = null;
158 }
159 if (this.rightdownPoint) {
160 this.viewer.entities.remove(this.rightdownPoint);
161 this.rightdownPoint = null;
162 }
163 if (this.leftupPoint) {
164 this.viewer.entities.remove(this.leftupPoint);
165 this.leftupPoint = null;
166 }
167 this.style = null;
168 this.modifyPoint = null;
169 if (this.prompt) this.prompt.destroy();
170 }
171 getCatesian3FromPX(px, viewer, entitys) {
172 var picks = viewer.scene.drillPick(px);
173 this.viewer.scene.render();
174 var cartesian;
175 var isOn3dtiles = false;
176 for (var i = 0; i < picks.length; i++) {
177 var isContinue = false;
178 for (var step = 0; step < entitys.length; step++) {
179 if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
180 isContinue = true;
181 break;
182 }
183 }
184 if (isContinue) continue;
185 if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
186 isOn3dtiles = true;
187 }
188 }
189 if (isOn3dtiles) {
190 cartesian = viewer.scene.pickPosition(px);
191 } else {
192 var ray = viewer.camera.getPickRay(px);
193 if (!ray) return null;
194 cartesian = viewer.scene.globe.pick(ray, viewer.scene);
195 }
196 return cartesian;
197 }
198 }
...\ No newline at end of file ...\ No newline at end of file
1 import createBillboard from './createBillboard'; 1 import { loadModules } from "esri-loader";
2 import createPolyline from './createPolyline'; 2 import mapManage from './towMapObjects';
3 import createPolygon from './createPolygon'; 3 export default class DrawTool {
4 import createCircle from './createCircle'; 4 static getInstance() {
5 import createRectangle from './createRectangle'; 5 mapManage.drawTool || (mapManage.drawTool = new this());
6 export default { 6 }
7 drawTool: class DrawTool { 7 constructor() {
8 constructor(obj) { 8 this.view = mapManage.mapView;
9 if (!obj.viewer || !obj) { 9 this.map = mapManage.mapView.map;
10 console.warn("缺少必要参数!--viewer"); 10 this.active = !1;
11 return; 11 this.polygon = null;
12 } 12 this.guids = [];
13 this.viewer = obj.viewer; 13 loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then(([w, z, d]) => {
14 this.hasEdit = obj.hasEdit; 14 this.options1 || (this.options1 = {}, this.options1.pm = new w({
15 this.toolArr = []; 15 url: "", width: "", height: "", xoffset: 0, yoffset: 0
16 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); 16 }));
17 this.show = obj.drawEndShow; 17 this.map.add(this.graphicsLayer = new z({ id: "drawtool" }));
18 // this.lastSelectEntity = null; 18 this.draw = new Draw({ view: this.view });
19 } 19 });
20 startDraw(opt) { 20 }
21 var that = this; 21 activate(c, b) {
22 if (opt.type == "polyline") { 22 this.active = !0;
23 var polyline = new createPolyline(this.viewer, opt.style); 23 this.drawType = c.toUpperCase();
24 polyline.start(function (evt) { 24 this.callback = b;
25 if (that.hasEdit) { 25 this.guids = [];
26 that.unbindEdit(); 26 this.downCount = 0;
27 polyline.startModify(opt.modifySuccess); 27 this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1);
28 that.lastSelectEntity = polyline; 28 switch (this.drawType) {
29 } 29
30 if (opt.success) opt.success(evt); 30 case "POINT1":
31 if (that.show == false) polyline.setVisible(false); 31 loadModules(["esri/Graphic"]).then(([h, f]) => {
32 }); 32 this.downCount = 0;
33 this.toolArr.push(polyline); 33 this.view.container.addEventListener('mousedown', b => {
34 } 34 var a = new h(b.offsetX, b.offsetY), a = this.view.toMap(a);
35 if (opt.type == "polygon") { 35 console.log(a);
36 var polygon = new createPolygon(this.viewer, opt.style); 36 // this.graphic = new f(a, this.options1.pm, null);
37 polygon.start(function () { 37 // this.graphicsLayer.add(this.graphic);
38 if (that.hasEdit) { 38 // console.log('OKOKOK');
39 that.unbindEdit(); 39 // b.stopPropagation()
40 polygon.startModify();
41 that.lastSelectEntity = polygon;
42 }
43 if (opt.success) opt.success(polygon);
44 if (that.show == false) polygon.setVisible(false);
45 });
46 this.toolArr.push(polygon);
47 }
48 if (opt.type == "billboard") {
49 var billboard = new createBillboard(this.viewer, opt.style);
50 billboard.start(function () {
51 if (that.hasEdit) {
52 that.unbindEdit();
53 billboard.startModify();
54 that.lastSelectEntity = billboard;
55 }
56 if (opt.success) opt.success(billboard);
57 if (that.show == false) billboard.setVisible(false);
58 });
59 this.toolArr.push(billboard);
60 }
61 if (opt.type == "circle") {
62 var circle = new createCircle(this.viewer, opt.style);
63 circle.start(function () {
64 if (that.hasEdit) {
65 that.unbindEdit();
66 circle.startModify();
67 that.lastSelectEntity = circle;
68 }
69 if (opt.success) opt.success(circle);
70 if (that.show == false) circle.setVisible(false);
71 });
72 this.toolArr.push(circle);
73 }
74 if (opt.type == "rectangle") {
75 var rectangle = new createRectangle(this.viewer, opt.style);
76 rectangle.start(function () {
77 if (that.hasEdit) {
78 that.unbindEdit();
79 rectangle.startModify();
80 that.lastSelectEntity = rectangle;
81 }
82 if (opt.success) opt.success(rectangle);
83 if (that.show == false) rectangle.setVisible(false);
84 });
85 this.toolArr.push(rectangle);
86 }
87 //重写材质
88 if (opt.type == "flowPolyline") {
89 var polyline = new CreatePolyline(this.viewer, opt.style);
90 polyline.start(function () {
91 if (that.hasEdit) {
92 that.unbindEdit();
93 polyline.startModify();
94 }
95 if (opt.success) opt.success(polyline);
96 });
97 this.toolArr.push(polyline);
98 }
99 }
100 createByPositions(opt) {
101 if (this.hasEdit) {
102 this.bindEdit();
103 }
104 if (!opt) opt = {};
105 if (opt.type == "polyline") {
106 var polyline = new CreatePolyline(this.viewer, opt.style);
107 polyline.createByPositions(opt.positions, opt.success);
108 this.toolArr.push(polyline);
109 }
110 if (opt.type == "polygon") {
111 var polygon = new CreatePolygon(this.viewer, opt.style);
112 polygon.createByPositions(opt.positions, opt.success);
113 this.toolArr.push(polygon);
114 }
115 if (opt.type == "billboard") {
116 var billboard = new CreateBillboard(this.viewer, opt.style);
117 billboard.createByPositions(opt.positions, function(){
118 if(opt.success) opt.success(billboard)
119 }); 40 });
120 this.toolArr.push(billboard); 41 });
121 } 42
122 } 43 break;
123 destroy() {
124 for (var i = 0; i < this.toolArr.length; i++) {
125 var obj = this.toolArr[i];
126 obj.destroy();
127 }
128 }
129 bindEdit() {
130 var that = this;
131 this.handler.setInputAction(function (evt) { //单机开始绘制
132 var pick = that.viewer.scene.pick(evt.position);
133 if (Cesium.defined(pick) && pick.id) {
134 for (var i = 0; i < that.toolArr.length; i++) {
135 if (pick.id.objId == that.toolArr[i].objId && (that.toolArr[i].state == 1||that.toolArr[i].state == 2)) {
136 if (that.lastSelectEntity) {
137 that.lastSelectEntity.endModify();
138 }
139 that.toolArr[i].startModify();
140 that.lastSelectEntity = that.toolArr[i];
141 break;
142 }
143 }
144 }
145 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
146 }
147 unbindEdit() {
148 for (var i = 0; i < this.toolArr.length; i++) {
149 this.toolArr[i].endModify();
150 }
151 }
152 getCatesian3FromPX(px, viewer, entitys) {
153 var picks = viewer.scene.drillPick(px);
154 this.viewer.scene.render();
155 var cartesian;
156 var isOn3dtiles = false;
157 for (var i = 0; i < picks.length; i++) {
158 var isContinue = false;
159 for (var step = 0; step < entitys.length; step++) {
160 if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
161 isContinue = true;
162 break;
163 }
164 }
165 if (isContinue) continue;
166 if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
167 isOn3dtiles = true;
168 }
169 }
170 if (isOn3dtiles) {
171 cartesian = viewer.scene.pickPosition(px);
172 } else {
173 var ray = viewer.camera.getPickRay(px);
174 if (!ray) return null;
175 cartesian = viewer.scene.globe.pick(ray, viewer.scene);
176 }
177 return cartesian;
178 } 44 }
179 } 45 }
46 deactivate() {
47 this.active = !1;
48 this.drawType = "";
49 this.downCount = 0;
50 }
180 } 51 }
...\ No newline at end of file ...\ No newline at end of file
......
1 export default { 1 export default {
2 map: undefined 2 viewer: undefined
3 } 3 }
...\ No newline at end of file ...\ No newline at end of file
......
1 export default {
2 pageIndex: '',
3 pageSize: '',
4 id: 't0101_4028d839708bbb6d0170946760781016',
5 data: undefined
6 }
...\ No newline at end of file ...\ No newline at end of file
1 import objectManage from './maputils'; 1 import objectManage from './maputils';
2 export default class shadow { 2 export default class shadow {
3 constructor() { 3 constructor(opt) {
4 this.points = []; 4 this.points = [];
5 this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene); 5 this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene);
6 this.shadowQuery.build(); 6 this.shadowQuery.build();
7 // this.options = opt;
7 this.setCurrentTime(); 8 this.setCurrentTime();
8 this.init(); 9 this.init();
9 } 10 }
10 setCurrentTime() { 11 setCurrentTime() {
11 let d = new Date(); 12 objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
12 d.setHours(20)
13 objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(d);
14 objectManage.viewer.clock.multiplier = 1; 13 objectManage.viewer.clock.multiplier = 1;
15 objectManage.viewer.clock.shouldAnimate = true; 14 objectManage.viewer.clock.shouldAnimate = true;
16 } 15 }
...@@ -45,24 +44,24 @@ export default class shadow { ...@@ -45,24 +44,24 @@ export default class shadow {
45 } 44 }
46 //设置分析对象的开始结束时间 45 //设置分析对象的开始结束时间
47 // var dateValue = $("#selDate").val(); 46 // var dateValue = $("#selDate").val();
48 var startTime = new Date(); 47 // var startTime = new Date();
49 startTime.setHours(8); 48 // startTime.setHours(18);
50 this.shadowQuery.startTime = Cesium.JulianDate.fromDate(startTime); 49 this.shadowQuery.startTime = Cesium.JulianDate.fromDate(this.anslysisTime);
51 50
52 var endTime = new Date(); 51 var endTime = new Date();
53 endTime.setHours(22); 52 endTime.setHours(0);
54 this.shadowQuery.endTime = Cesium.JulianDate.fromDate(endTime); 53 this.shadowQuery.endTime = Cesium.JulianDate.fromDate(endTime);
55 54
56 this.setCurrentTime(); 55 // this.setCurrentTime();
57 this.shadowQuery.spacing = 10; 56 this.shadowQuery.spacing = 10;
58 this.shadowQuery.timeInterval = 60; 57 this.shadowQuery.timeInterval = 60;
59 58
60 //设置分析区域、底部高程和拉伸高度 59 //设置分析区域、底部高程和拉伸高度
61 var bh = 20, eh = 20; 60 // var bh = 20, eh = 20;
62 this.shadowQuery.qureyRegion({ 61 this.shadowQuery.qureyRegion({
63 position : this.points, 62 position : this.points,
64 bottom : bh, 63 bottom: this.bottomHeight,
65 extend : eh 64 extend: this.extrudeHeight
66 }); 65 });
67 }); 66 });
68 } 67 }
......
1 export default {
2 mapView: undefined
3 }
...\ No newline at end of file ...\ No newline at end of file