111111
Showing
10 changed files
with
1934 additions
and
0 deletions
src/assets/js/map/MeasureTools.js
0 → 100644
| 1 | export default { | ||
| 2 | measureTools(viewer) { | ||
| 3 | var entityCollection = []; | ||
| 4 | |||
| 5 | this.getCollection = function () { | ||
| 6 | return entityCollection; | ||
| 7 | }; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * 清除 | ||
| 11 | */ | ||
| 12 | this.destroy = function () { | ||
| 13 | for (var i = 0; i < entityCollection.length; i++) { | ||
| 14 | viewer.entities.remove(entityCollection[i]); | ||
| 15 | } | ||
| 16 | entityCollection = []; | ||
| 17 | }; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 测距 | ||
| 21 | */ | ||
| 22 | this.measurePolyLine = function () { | ||
| 23 | |||
| 24 | var positions = []; | ||
| 25 | var labelEntity = null; // 标签实体 | ||
| 26 | |||
| 27 | // 注册鼠标左击事件 | ||
| 28 | viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) { | ||
| 29 | var cartesian = viewer.scene.pickPosition(clickEvent.position); // 坐标 | ||
| 30 | |||
| 31 | // 存储第一个点 | ||
| 32 | if (positions.length == 0) { | ||
| 33 | positions.push(cartesian.clone()); | ||
| 34 | |||
| 35 | addPoint(cartesian); | ||
| 36 | |||
| 37 | // 注册鼠标移动事件 | ||
| 38 | viewer.screenSpaceEventHandler.setInputAction(function (moveEvent) { | ||
| 39 | var movePosition = viewer.scene.pickPosition(moveEvent.endPosition); // 鼠标移动的点 | ||
| 40 | if (positions.length == 2) { | ||
| 41 | positions.pop(); | ||
| 42 | positions.push(movePosition); | ||
| 43 | |||
| 44 | // 绘制label | ||
| 45 | if (labelEntity) { | ||
| 46 | viewer.entities.remove(labelEntity); | ||
| 47 | entityCollection.splice(entityCollection.indexOf(labelEntity), 1); | ||
| 48 | } | ||
| 49 | |||
| 50 | // 计算中点 | ||
| 51 | var centerPoint = Cesium.Cartesian3.midpoint(positions[0], positions[1], new Cesium.Cartesian3()); | ||
| 52 | // 计算距离 | ||
| 53 | var lengthText = "距离:" + getLengthText(positions[0], positions[1]); | ||
| 54 | |||
| 55 | labelEntity = addLabel(centerPoint, lengthText); | ||
| 56 | entityCollection.push(labelEntity); | ||
| 57 | |||
| 58 | } else { | ||
| 59 | positions.push(movePosition); | ||
| 60 | // 绘制线 | ||
| 61 | addLine(positions); | ||
| 62 | } | ||
| 63 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 64 | } else { | ||
| 65 | // 存储第二个点 | ||
| 66 | positions.pop(); | ||
| 67 | positions.push(cartesian); | ||
| 68 | addPoint(cartesian); | ||
| 69 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 70 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 71 | } | ||
| 72 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 73 | }; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * 测面积 | ||
| 77 | */ | ||
| 78 | this.measurePolygon = function () { | ||
| 79 | |||
| 80 | var positions = []; | ||
| 81 | var clickStatus = false; | ||
| 82 | var labelEntity = null; | ||
| 83 | |||
| 84 | viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) { | ||
| 85 | |||
| 86 | clickStatus = true; | ||
| 87 | // var cartesian = viewer.scene.pickPosition(clickEvent.position); | ||
| 88 | var cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(clickEvent.position), viewer.scene); | ||
| 89 | if (positions.length == 0) { | ||
| 90 | positions.push(cartesian.clone()); //鼠标左击 添加第1个点 | ||
| 91 | addPoint(cartesian); | ||
| 92 | |||
| 93 | viewer.screenSpaceEventHandler.setInputAction(function (moveEvent) { | ||
| 94 | // var movePosition = viewer.scene.pickPosition(moveEvent.endPosition); | ||
| 95 | var movePosition = viewer.scene.globe.pick(viewer.camera.getPickRay(moveEvent.endPosition), viewer.scene); | ||
| 96 | if (positions.length == 1) { | ||
| 97 | positions.push(movePosition); | ||
| 98 | addLine(positions); | ||
| 99 | } else { | ||
| 100 | if (clickStatus) { | ||
| 101 | positions.push(movePosition); | ||
| 102 | } else { | ||
| 103 | positions.pop(); | ||
| 104 | positions.push(movePosition); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | if (positions.length >= 3) { | ||
| 109 | // 绘制label | ||
| 110 | if (labelEntity) { | ||
| 111 | viewer.entities.remove(labelEntity); | ||
| 112 | entityCollection.splice(entityCollection.indexOf(labelEntity), 1); | ||
| 113 | } | ||
| 114 | |||
| 115 | var text = "面积:" + getArea(positions); | ||
| 116 | var centerPoint = getCenterOfGravityPoint(positions); | ||
| 117 | labelEntity = addLabel(centerPoint, text); | ||
| 118 | |||
| 119 | entityCollection.push(labelEntity); | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | clickStatus = false; | ||
| 124 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 125 | |||
| 126 | |||
| 127 | } else if (positions.length == 2) { | ||
| 128 | positions.pop(); | ||
| 129 | positions.push(cartesian.clone()); // 鼠标左击 添加第2个点 | ||
| 130 | |||
| 131 | addPoint(cartesian); | ||
| 132 | |||
| 133 | addPolyGon(positions); | ||
| 134 | |||
| 135 | // 右击结束 | ||
| 136 | viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) { | ||
| 137 | |||
| 138 | // var clickPosition = viewer.scene.pickPosition(clickEvent.position); | ||
| 139 | var clickPosition = viewer.scene.globe.pick(viewer.camera.getPickRay(clickEvent.position), viewer.scene); | ||
| 140 | // console.log(clickPosition); | ||
| 141 | |||
| 142 | positions.pop(); | ||
| 143 | positions.push(clickPosition); | ||
| 144 | positions.push(positions[0]); // 闭合 | ||
| 145 | addPoint(clickPosition); | ||
| 146 | |||
| 147 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 148 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 149 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK); | ||
| 150 | |||
| 151 | }, Cesium.ScreenSpaceEventType.RIGHT_CLICK); | ||
| 152 | |||
| 153 | |||
| 154 | } else if (positions.length >= 3) { | ||
| 155 | positions.pop(); | ||
| 156 | positions.push(cartesian.clone()); // 鼠标左击 添加第3个点 | ||
| 157 | addPoint(cartesian); | ||
| 158 | } | ||
| 159 | |||
| 160 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 161 | }; | ||
| 162 | |||
| 163 | /** | ||
| 164 | * 测高 | ||
| 165 | */ | ||
| 166 | this.measureHeight = function () { | ||
| 167 | var positions = []; | ||
| 168 | var labelEntity_1 = null; // 标签实体 | ||
| 169 | var labelEntity_2 = null; // 标签实体 | ||
| 170 | var labelEntity_3 = null; // 标签实体 | ||
| 171 | |||
| 172 | // 注册鼠标左击事件 | ||
| 173 | viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) { | ||
| 174 | var cartesian = viewer.scene.pickPosition(clickEvent.position); // 坐标 | ||
| 175 | |||
| 176 | // 存储第一个点 | ||
| 177 | if (positions.length == 0) { | ||
| 178 | positions.push(cartesian.clone()); | ||
| 179 | addPoint(cartesian); | ||
| 180 | |||
| 181 | // 注册鼠标移动事件 | ||
| 182 | viewer.screenSpaceEventHandler.setInputAction(function (moveEvent) { | ||
| 183 | var movePosition = viewer.scene.pickPosition(moveEvent.endPosition); // 鼠标移动的点 | ||
| 184 | if (positions.length >= 2) { | ||
| 185 | positions.pop(); | ||
| 186 | positions.pop(); | ||
| 187 | positions.pop(); | ||
| 188 | |||
| 189 | var cartographic = Cesium.Cartographic.fromCartesian(movePosition); | ||
| 190 | var height = Cesium.Cartographic.fromCartesian(positions[0]).height; | ||
| 191 | |||
| 192 | var verticalPoint = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), height); | ||
| 193 | positions.push(verticalPoint); | ||
| 194 | positions.push(movePosition); | ||
| 195 | positions.push(positions[0]); | ||
| 196 | |||
| 197 | // 绘制label | ||
| 198 | if (labelEntity_1) { | ||
| 199 | viewer.entities.remove(labelEntity_1); | ||
| 200 | entityCollection.splice(entityCollection.indexOf(labelEntity_1), 1); | ||
| 201 | viewer.entities.remove(labelEntity_2); | ||
| 202 | entityCollection.splice(entityCollection.indexOf(labelEntity_2), 1); | ||
| 203 | viewer.entities.remove(labelEntity_3); | ||
| 204 | entityCollection.splice(entityCollection.indexOf(labelEntity_3), 1); | ||
| 205 | } | ||
| 206 | |||
| 207 | // 计算中点 | ||
| 208 | var centerPoint_1 = Cesium.Cartesian3.midpoint(positions[0], positions[1], new Cesium.Cartesian3()); | ||
| 209 | // 计算距离 | ||
| 210 | var lengthText_1 = "水平距离:" + getLengthText(positions[0], positions[1]); | ||
| 211 | |||
| 212 | labelEntity_1 = addLabel(centerPoint_1, lengthText_1); | ||
| 213 | entityCollection.push(labelEntity_1); | ||
| 214 | |||
| 215 | // 计算中点 | ||
| 216 | var centerPoint_2 = Cesium.Cartesian3.midpoint(positions[1], positions[2], new Cesium.Cartesian3()); | ||
| 217 | // 计算距离 | ||
| 218 | var lengthText_2 = "垂直距离:" + getLengthText(positions[1], positions[2]); | ||
| 219 | |||
| 220 | labelEntity_2 = addLabel(centerPoint_2, lengthText_2); | ||
| 221 | entityCollection.push(labelEntity_2); | ||
| 222 | |||
| 223 | // 计算中点 | ||
| 224 | var centerPoint_3 = Cesium.Cartesian3.midpoint(positions[2], positions[3], new Cesium.Cartesian3()); | ||
| 225 | // 计算距离 | ||
| 226 | var lengthText_3 = "直线距离:" + getLengthText(positions[2], positions[3]); | ||
| 227 | |||
| 228 | labelEntity_3 = addLabel(centerPoint_3, lengthText_3); | ||
| 229 | entityCollection.push(labelEntity_3); | ||
| 230 | |||
| 231 | } else { | ||
| 232 | var verticalPoint = new Cesium.Cartesian3(movePosition.x, movePosition.y, positions[0].z); | ||
| 233 | positions.push(verticalPoint); | ||
| 234 | positions.push(movePosition); | ||
| 235 | positions.push(positions[0]); | ||
| 236 | // 绘制线 | ||
| 237 | addLine(positions); | ||
| 238 | } | ||
| 239 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 240 | } else { | ||
| 241 | // 存储第二个点 | ||
| 242 | positions.pop(); | ||
| 243 | positions.pop(); | ||
| 244 | positions.pop(); | ||
| 245 | var cartographic = Cesium.Cartographic.fromCartesian(cartesian); | ||
| 246 | var height = Cesium.Cartographic.fromCartesian(positions[0]).height; | ||
| 247 | |||
| 248 | var verticalPoint = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), height); | ||
| 249 | positions.push(verticalPoint); | ||
| 250 | positions.push(cartesian); | ||
| 251 | positions.push(positions[0]); | ||
| 252 | addPoint(cartesian); | ||
| 253 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 254 | viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 255 | } | ||
| 256 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 257 | }; | ||
| 258 | |||
| 259 | /** | ||
| 260 | * 添加点 | ||
| 261 | * @param position | ||
| 262 | */ | ||
| 263 | var addPoint = function (position) { | ||
| 264 | entityCollection.push(viewer.entities.add(new Cesium.Entity({ | ||
| 265 | position: position, | ||
| 266 | point: { | ||
| 267 | // color: Cesium.Color.SKYBLUE, | ||
| 268 | // pixelSize: 8, | ||
| 269 | // outlineColor: Cesium.Color.YELLOW, | ||
| 270 | // outlineWidth: 2, | ||
| 271 | // disableDepthTestDistance: Number.POSITIVE_INFINITY | ||
| 272 | pixelSize: 5, | ||
| 273 | color: Cesium.Color.YELLOW, | ||
| 274 | outlineWidth: 2, | ||
| 275 | outlineColor: Cesium.Color.DARKRED, | ||
| 276 | disableDepthTestDistance: Number.POSITIVE_INFINITY | ||
| 277 | } | ||
| 278 | }))); | ||
| 279 | }; | ||
| 280 | |||
| 281 | /** | ||
| 282 | * 添加线 | ||
| 283 | * @param positions | ||
| 284 | */ | ||
| 285 | var addLine = function (positions) { | ||
| 286 | entityCollection.push(viewer.entities.add(new Cesium.Entity({ | ||
| 287 | polyline: { | ||
| 288 | positions: new Cesium.CallbackProperty(function () { | ||
| 289 | return positions | ||
| 290 | }, false), | ||
| 291 | perPositionHeight: true, | ||
| 292 | show: true, | ||
| 293 | material: Cesium.Color.YELLOW, | ||
| 294 | width: 3, | ||
| 295 | clampToGround: true | ||
| 296 | } | ||
| 297 | }))); | ||
| 298 | }; | ||
| 299 | |||
| 300 | /** | ||
| 301 | * 添加面 | ||
| 302 | * @param positions | ||
| 303 | */ | ||
| 304 | var addPolyGon = function (positions) { | ||
| 305 | var dynamicPositions = new Cesium.CallbackProperty(function () { | ||
| 306 | return new Cesium.PolygonHierarchy(positions); | ||
| 307 | }, false); | ||
| 308 | entityCollection.push(viewer.entities.add(new Cesium.Entity({ | ||
| 309 | polygon: { | ||
| 310 | hierarchy: dynamicPositions, | ||
| 311 | material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2), | ||
| 312 | perPositionHeight: true, | ||
| 313 | width: 3, | ||
| 314 | outlineColor: Cesium.Color.BLACK, | ||
| 315 | outlineWidth: 3, | ||
| 316 | outline: true | ||
| 317 | // material: Cesium.Color.RED.withAlpha(0.6), | ||
| 318 | // classificationType: Cesium.ClassificationType.BOTH // 贴地表和贴模型,如果设置了,这不能使用挤出高度 | ||
| 319 | } | ||
| 320 | }))); | ||
| 321 | }; | ||
| 322 | |||
| 323 | /** | ||
| 324 | * 添加标签 | ||
| 325 | * @param position | ||
| 326 | * @param text | ||
| 327 | */ | ||
| 328 | var addLabel = function (centerPoint, text) { | ||
| 329 | return viewer.entities.add(new Cesium.Entity({ | ||
| 330 | position: centerPoint, | ||
| 331 | label: { | ||
| 332 | text: text, | ||
| 333 | font: '12pt sans-serif', | ||
| 334 | style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL FILL_AND_OUTLINE OUTLINE | ||
| 335 | fillColor: Cesium.Color.YELLOW, | ||
| 336 | showBackground: true,//指定标签后面背景的可见性 | ||
| 337 | backgroundColor: new Cesium.Color(0.165, 0.165, 0.165, 0.8), // 背景颜色 | ||
| 338 | backgroundPadding: new Cesium.Cartesian2(6, 6),//指定以像素为单位的水平和垂直背景填充padding | ||
| 339 | pixelOffset: new Cesium.Cartesian2(0, -25) | ||
| 340 | } | ||
| 341 | })); | ||
| 342 | }; | ||
| 343 | |||
| 344 | /** | ||
| 345 | * 计算两点距离 | ||
| 346 | * @param firstPoint | ||
| 347 | * @param secondPoint | ||
| 348 | */ | ||
| 349 | var getLengthText = function (firstPoint, secondPoint) { | ||
| 350 | // 计算距离 | ||
| 351 | var length = Cesium.Cartesian3.distance(firstPoint, secondPoint); | ||
| 352 | if (length > 1000) { | ||
| 353 | length = (length / 1000).toFixed(2) + " 公里"; | ||
| 354 | } else { | ||
| 355 | length = length.toFixed(2) + " 米"; | ||
| 356 | } | ||
| 357 | return length; | ||
| 358 | }; | ||
| 359 | |||
| 360 | //计算多边形面积 | ||
| 361 | var getArea = function (points) { | ||
| 362 | |||
| 363 | var radiansPerDegree = Math.PI / 180.0;//角度转化为弧度(rad) | ||
| 364 | var degreesPerRadian = 180.0 / Math.PI;//弧度转化为角度 | ||
| 365 | |||
| 366 | /*角度*/ | ||
| 367 | function Angle(p1, p2, p3) { | ||
| 368 | var bearing21 = Bearing(p2, p1); | ||
| 369 | var bearing23 = Bearing(p2, p3); | ||
| 370 | var angle = bearing21 - bearing23; | ||
| 371 | if (angle < 0) { | ||
| 372 | angle += 360; | ||
| 373 | } | ||
| 374 | return angle; | ||
| 375 | } | ||
| 376 | |||
| 377 | /*方向*/ | ||
| 378 | function Bearing(from, to) { | ||
| 379 | from = Cesium.Cartographic.fromCartesian(from); | ||
| 380 | to = Cesium.Cartographic.fromCartesian(to); | ||
| 381 | |||
| 382 | var lat1 = from.latitude; | ||
| 383 | var lon1 = from.longitude; | ||
| 384 | var lat2 = to.latitude; | ||
| 385 | var lon2 = to.longitude; | ||
| 386 | var angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2)); | ||
| 387 | if (angle < 0) { | ||
| 388 | angle += Math.PI * 2.0; | ||
| 389 | } | ||
| 390 | angle = angle * degreesPerRadian;//角度 | ||
| 391 | return angle; | ||
| 392 | } | ||
| 393 | |||
| 394 | function distance(point1, point2) { | ||
| 395 | var point1cartographic = Cesium.Cartographic.fromCartesian(point1); | ||
| 396 | var point2cartographic = Cesium.Cartographic.fromCartesian(point2); | ||
| 397 | /**根据经纬度计算出距离**/ | ||
| 398 | var geodesic = new Cesium.EllipsoidGeodesic(); | ||
| 399 | geodesic.setEndPoints(point1cartographic, point2cartographic); | ||
| 400 | var s = geodesic.surfaceDistance; | ||
| 401 | //console.log(Math.sqrt(Math.pow(distance, 2) + Math.pow(endheight, 2))); | ||
| 402 | //返回两点之间的距离 | ||
| 403 | s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2)); | ||
| 404 | return s; | ||
| 405 | } | ||
| 406 | |||
| 407 | var res = 0; | ||
| 408 | //拆分三角曲面 | ||
| 409 | |||
| 410 | for (var i = 0; i < points.length - 2; i++) { | ||
| 411 | var j = (i + 1) % points.length; | ||
| 412 | var k = (i + 2) % points.length; | ||
| 413 | var totalAngle = Angle(points[i], points[j], points[k]); | ||
| 414 | |||
| 415 | |||
| 416 | var dis_temp1 = distance(points[j], points[0]); | ||
| 417 | var dis_temp2 = distance(points[k], points[0]); | ||
| 418 | res += dis_temp1 * dis_temp2 * Math.sin(totalAngle) / 2; | ||
| 419 | // console.log(res); | ||
| 420 | } | ||
| 421 | |||
| 422 | if (res < 1000000) { | ||
| 423 | res = Math.abs(res).toFixed(4) + " 平方米"; | ||
| 424 | } else { | ||
| 425 | res = Math.abs((res / 1000000.0).toFixed(4)) + " 平方公里"; | ||
| 426 | } | ||
| 427 | |||
| 428 | return res; | ||
| 429 | |||
| 430 | }; | ||
| 431 | |||
| 432 | /** | ||
| 433 | * 计算多边形的中心(简单的处理) | ||
| 434 | * @param mPoints | ||
| 435 | * @returns {*[]} | ||
| 436 | */ | ||
| 437 | var getCenterOfGravityPoint = function (mPoints) { | ||
| 438 | var centerPoint = mPoints[0]; | ||
| 439 | for (var i = 1; i < mPoints.length; i++) { | ||
| 440 | centerPoint = Cesium.Cartesian3.midpoint(centerPoint, mPoints[i], new Cesium.Cartesian3()); | ||
| 441 | } | ||
| 442 | return centerPoint; | ||
| 443 | } | ||
| 444 | } | ||
| 445 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
src/assets/js/map/MovePrompt.js
0 → 100644
| 1 | |||
| 2 | export default { | ||
| 3 | movePrompt: class MovePrompt { | ||
| 4 | constructor(viewer, opt) { | ||
| 5 | if (!opt) opt = {}; | ||
| 6 | var randomId = Number((new Date()).getTime()); | ||
| 7 | this.id = randomId; | ||
| 8 | this.style = opt.style; | ||
| 9 | this.viewer = viewer; | ||
| 10 | if (!this.viewer) return; | ||
| 11 | this.scene = this.viewer.scene; | ||
| 12 | this.camera = this.viewer.camera; | ||
| 13 | this.mapContainer = this.viewer.container.id; | ||
| 14 | this.rendHandler = null; | ||
| 15 | if (!this.mapContainer) return; | ||
| 16 | |||
| 17 | this.trackPopUpId = "trackPopUp" + randomId; | ||
| 18 | this.promptContentId = "promptContent" + randomId; | ||
| 19 | this.promptDivId = "promptDiv" + randomId; | ||
| 20 | this.trackPopUpContentId = "trackPopUpContent" + randomId; | ||
| 21 | this.closeBtnId = "closeBtn" + randomId; | ||
| 22 | |||
| 23 | var infoDiv; | ||
| 24 | var max_width = 300; | ||
| 25 | var max_height = 500; | ||
| 26 | infoDiv = window.document.createElement("div"); | ||
| 27 | infoDiv.id = this.trackPopUpId; | ||
| 28 | infoDiv.className = "trackPopUp"; | ||
| 29 | |||
| 30 | this.content = opt.content || ""; //提示框内容 | ||
| 31 | if (!opt.type || opt.type == 1) { | ||
| 32 | infoDiv.innerHTML = '<div id="' + this.trackPopUpContentId + '" class="cesium-popup" style="top:0;left:0;">' + | ||
| 33 | '<div class="cesium-prompt-content-wrapper" id="' + this.promptDivId + '">' + | ||
| 34 | '<div id="trackPopUpLink" class="cesium-popup-content" style="max-width: ' + max_width + 'px;max-height: ' + max_height + 'px">' + | ||
| 35 | '<span class="promptContent" id="' + this.promptContentId + '">' + this.content + '</span>' + | ||
| 36 | '</div>' + | ||
| 37 | '</div>' + | ||
| 38 | '</div>'; | ||
| 39 | } else { | ||
| 40 | infoDiv.innerHTML = '<div id="' + this.trackPopUpContentId + '" class="cesium-popup" style="top:0;left:0;">' + | ||
| 41 | '<a class="cesium-popup-close-button" href="javascript:void(0)" id="' + this.closeBtnId + '">×</a>' + | ||
| 42 | '<div class="cesium-popup-content-wrapper" id="' + this.promptDivId + '">' + | ||
| 43 | '<div id="trackPopUpLink" class="cesium-popup-content" style="max-width: ' + max_width + 'px;max-height: ' + max_height + 'px">' + | ||
| 44 | '<span class="popupContent" id="' + this.promptContentId + '">' + this.content + '</span>' + | ||
| 45 | '</div>' + | ||
| 46 | '</div>' + | ||
| 47 | '<div class="cesium-popup-tip-container">' + | ||
| 48 | '<div class="cesium-popup-tip"></div>' + | ||
| 49 | '</div>' + | ||
| 50 | '</div>'; | ||
| 51 | } | ||
| 52 | |||
| 53 | window.document.getElementById(this.mapContainer).appendChild(infoDiv); | ||
| 54 | window.document.getElementById(this.trackPopUpId).style.display = "block"; | ||
| 55 | |||
| 56 | this.offset = opt.offset || {}; | ||
| 57 | |||
| 58 | this.infoDiv = window.document.getElementById(this.trackPopUpId); | ||
| 59 | this.trackPopUpContent = window.document.getElementById(this.trackPopUpContentId); | ||
| 60 | |||
| 61 | this.promptDiv = window.document.getElementById(this.promptDivId); | ||
| 62 | this.promptContent = window.document.getElementById(this.promptContentId); | ||
| 63 | this.trackPopUpLink = window.document.getElementById(this.promptContentId); | ||
| 64 | |||
| 65 | this.popupCartesian = opt.popupCartesian; | ||
| 66 | this.rendHandler = null; | ||
| 67 | this.show = (opt.show == undefined ? true : opt.show); | ||
| 68 | if(opt.type==2){ | ||
| 69 | if(!this.popupCartesian){ | ||
| 70 | console.warn("缺少空间坐标!"); | ||
| 71 | return ; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | if (opt.type && opt.type != 1 && this.popupCartesian) { | ||
| 75 | var clsBtn = window.document.getElementById(this.closeBtnId); | ||
| 76 | var that = this; | ||
| 77 | clsBtn.addEventListener("click", function () { | ||
| 78 | that.setVisible(false); | ||
| 79 | }); | ||
| 80 | this.rendHandler = this.viewer.scene.postRender.addEventListener(function () { | ||
| 81 | if (that.popupCartesian) { | ||
| 82 | var px = Cesium.SceneTransforms.wgs84ToWindowCoordinates(that.scene, that.popupCartesian); | ||
| 83 | that.trackPopUpContent.style.left = px.x + (that.offset.x || 0)+ (Math.ceil(-that.trackPopUpContent.offsetWidth / 2)) + "px"; | ||
| 84 | that.trackPopUpContent.style.top = px.y + (that.offset.y ||0)+ (-that.trackPopUpContent.offsetHeight) + "px"; | ||
| 85 | var res = false; | ||
| 86 | var e = that.popupCartesian, | ||
| 87 | i = that.camera.position, | ||
| 88 | n = that.scene.globe.ellipsoid.cartesianToCartographic(i).height; | ||
| 89 | if (!(n += 1 * that.scene.globe.ellipsoid.maximumRadius, Cesium.Cartesian3.distance(i, e) > n)) { | ||
| 90 | res = true; | ||
| 91 | } | ||
| 92 | if (res && that.show) { | ||
| 93 | if (that.infoDiv) that.infoDiv.style.display = "block"; | ||
| 94 | } else { | ||
| 95 | if (that.infoDiv) that.infoDiv.style.display = "none"; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | }); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | setHtml(html) { | ||
| 102 | if (!html) { | ||
| 103 | return; | ||
| 104 | } | ||
| 105 | if (this.trackPopUpLink) { | ||
| 106 | this.trackPopUpLink.innerText = html; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | destroy() { | ||
| 110 | if (this.infoDiv && this.mapContainer) { | ||
| 111 | this.infoDiv.style.display = "none"; | ||
| 112 | window.document.getElementById(this.mapContainer).removeChild(this.infoDiv); | ||
| 113 | this.infoDiv = null; | ||
| 114 | } | ||
| 115 | if (this.rendHandler) { | ||
| 116 | this.rendHandler(); | ||
| 117 | this.rendHandler = null; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | displayPrompt(display) { | ||
| 121 | if (this.infoDiv) this.infoDiv.style.display = display ? "block" : "none"; | ||
| 122 | } | ||
| 123 | updateStyle(opt) { | ||
| 124 | if (!opt) opt = {}; | ||
| 125 | this.promptDiv.style.background = opt.rgba || "rgba(0,0,0,.4)"; | ||
| 126 | this.promptContent.style.color = opt.fontColor || "white"; | ||
| 127 | } | ||
| 128 | updatePrompt(px, html) { | ||
| 129 | if (!px) return; | ||
| 130 | this.infoDiv.style.display = "block"; | ||
| 131 | this.trackPopUpContent.style.left = px.x + (this.offset.x || 30) + "px"; | ||
| 132 | this.trackPopUpContent.style.top = px.y + (this.offset.y || 30) + "px"; | ||
| 133 | this.setHtml(html); | ||
| 134 | } | ||
| 135 | setVisible(isOpen) { | ||
| 136 | if(isOpen==undefined) isOpen = true; | ||
| 137 | if(isOpen){ | ||
| 138 | this.infoDiv.style.display = "block"; | ||
| 139 | this.show = true; | ||
| 140 | }else{ | ||
| 141 | this.infoDiv.style.display = "none"; | ||
| 142 | this.show = false; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
src/assets/js/map/addCompany.js
0 → 100644
| 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 |
src/assets/js/map/createBillboard.js
0 → 100644
| 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 |
src/assets/js/map/createCircle.js
0 → 100644
| 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 |
src/assets/js/map/createPolygon.js
0 → 100644
| 1 | import movePrompt from './MovePrompt'; | ||
| 2 | import addCompany from './addCompany'; | ||
| 3 | export default class CreatePolygon { | ||
| 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.polygon = null; | ||
| 10 | this.polyline = null; | ||
| 11 | this.positions = []; | ||
| 12 | this.style = style; | ||
| 13 | this.state = 0; //1为新增 2为编辑 0为清除 | ||
| 14 | this.gonPointArr = []; | ||
| 15 | this.modifyPoint = null; | ||
| 16 | this.prompt = new movePrompt.movePrompt(viewer); | ||
| 17 | } | ||
| 18 | start(callBack) { | ||
| 19 | var that = this; | ||
| 20 | this.handler.setInputAction(function(evt) { //单机开始绘制 | ||
| 21 | var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polygon]); | ||
| 22 | if (that.positions.length == 0) { | ||
| 23 | that.positions.push(cartesian.clone()); | ||
| 24 | } | ||
| 25 | that.positions.push(cartesian); | ||
| 26 | var point = addCompany.createPoint.call(that, {position: cartesian}); | ||
| 27 | point.wz = that.gonPointArr.length; | ||
| 28 | that.gonPointArr.push(point); | ||
| 29 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 30 | this.handler.setInputAction(function(evt) { //移动时绘制面 | ||
| 31 | if (that.positions.length < 1) { | ||
| 32 | that.prompt.updatePrompt(evt.endPosition, "单击开始绘制"); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | that.prompt.updatePrompt(evt.endPosition, "单击新增,右键结束"); | ||
| 36 | var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polygon]); | ||
| 37 | if (that.positions.length == 2) { | ||
| 38 | if (!Cesium.defined(that.polyline)) that.polyline = addCompany.createPolyline.call(that); | ||
| 39 | } else { | ||
| 40 | if (!Cesium.defined(that.polygon)) { | ||
| 41 | that.polygon = addCompany.createPolygon.call(that); | ||
| 42 | that.polygon.isFilter = true; | ||
| 43 | that.polygon.objId = that.objId; | ||
| 44 | if (that.polyline) that.viewer.entities.remove(that.polyline); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | that.positions.pop(); | ||
| 48 | that.positions.push(cartesian); | ||
| 49 | |||
| 50 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 51 | this.handler.setInputAction(function(evt) { | ||
| 52 | if (!that.polygon) return; | ||
| 53 | var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polygon]); | ||
| 54 | that.state = 1; | ||
| 55 | that.handler.destroy(); | ||
| 56 | if (that.floatPoint) { | ||
| 57 | if (that.floatPoint) that.floatPoint.show = false; | ||
| 58 | that.floatPoint = null; | ||
| 59 | } | ||
| 60 | that.positions.pop(); | ||
| 61 | that.positions.push(cartesian); | ||
| 62 | var point = addCompany.createPoint.call(that, {position: cartesian}); | ||
| 63 | point.wz = that.gonPointArr.length; | ||
| 64 | that.gonPointArr.push(point); | ||
| 65 | if (that.prompt) { | ||
| 66 | that.prompt.destroy(); | ||
| 67 | that.prompt = null; | ||
| 68 | } | ||
| 69 | callBack(that.polygon); | ||
| 70 | }, Cesium.ScreenSpaceEventType.RIGHT_CLICK); | ||
| 71 | } | ||
| 72 | createByPositions(lnglatArr, callBack) { | ||
| 73 | if (!lnglatArr) return; | ||
| 74 | var positions = that.getCatesian3FromPX.lnglatArrToCartesianArr(lnglatArr); | ||
| 75 | if (!positions) return; | ||
| 76 | this.polygon = addCompany.createPolygon.call(this); | ||
| 77 | this.positions = positions; | ||
| 78 | callBack(this.polygon); | ||
| 79 | for (var i = 0; i < positions.length; i++) { | ||
| 80 | var point = addCompany.createPoint.call(that, {position: positions[i]}); | ||
| 81 | point.isFilter = true; | ||
| 82 | point.wz = this.gonPointArr.length; | ||
| 83 | this.gonPointArr.push(point); | ||
| 84 | } | ||
| 85 | this.state = 1; | ||
| 86 | this.polygon.objId = this.objId; | ||
| 87 | } | ||
| 88 | startModify() { | ||
| 89 | if (this.state != 1 && this.state != 2) return; //表示还没绘制完成 | ||
| 90 | if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); | ||
| 91 | var that = this; | ||
| 92 | for (var i = 0; i < that.gonPointArr.length; i++) { | ||
| 93 | var point = that.gonPointArr[i]; | ||
| 94 | if (point) point.show = true; | ||
| 95 | } | ||
| 96 | this.modifyHandler.setInputAction(function(evt) { | ||
| 97 | var pick = that.viewer.scene.pick(evt.position); | ||
| 98 | if (Cesium.defined(pick) && pick.id) { | ||
| 99 | if (!pick.id.objId) | ||
| 100 | that.modifyPoint = pick.id; | ||
| 101 | that.forbidDrawWorld(true); | ||
| 102 | } else { | ||
| 103 | for (var i = 0; i < that.gonPointArr.length; i++) { | ||
| 104 | var point = that.gonPointArr[i]; | ||
| 105 | if (point) point.show = false; | ||
| 106 | } | ||
| 107 | if (that.modifyHandler) { | ||
| 108 | that.modifyHandler.destroy(); | ||
| 109 | that.modifyHandler = null; | ||
| 110 | } | ||
| 111 | that.state = 2; | ||
| 112 | } | ||
| 113 | }, Cesium.ScreenSpaceEventType.LEFT_DOWN); | ||
| 114 | this.modifyHandler.setInputAction(function(evt) { //移动时绘制面 | ||
| 115 | if (that.positions.length < 1 || !that.modifyPoint) return; | ||
| 116 | var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polygon, that.modifyPoint]); | ||
| 117 | if (cartesian) { | ||
| 118 | that.modifyPoint.position.setValue(cartesian); | ||
| 119 | that.positions[that.modifyPoint.wz] = cartesian; | ||
| 120 | } | ||
| 121 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 122 | this.modifyHandler.setInputAction(function(evt) { | ||
| 123 | that.forbidDrawWorld(false); | ||
| 124 | if (!that.modifyPoint) return; | ||
| 125 | var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polygon, that.modifyPoint]); | ||
| 126 | that.modifyPoint.position.setValue(cartesian); | ||
| 127 | that.positions[that.modifyPoint.wz] = cartesian; | ||
| 128 | that.modifyPoint = null; | ||
| 129 | that.forbidDrawWorld(false); | ||
| 130 | }, Cesium.ScreenSpaceEventType.LEFT_UP); | ||
| 131 | } | ||
| 132 | endModify(callback) { | ||
| 133 | for (var i = 0; i < this.gonPointArr.length; i++) { | ||
| 134 | var point = this.gonPointArr[i]; | ||
| 135 | if (point) point.show = false; | ||
| 136 | } | ||
| 137 | if (this.modifyHandler) { | ||
| 138 | this.modifyHandler.destroy(); | ||
| 139 | this.modifyHandler = null; | ||
| 140 | } | ||
| 141 | this.state = 2; | ||
| 142 | if(callback) callback(this.polygon); | ||
| 143 | } | ||
| 144 | getPositions() { | ||
| 145 | return this.positions; | ||
| 146 | } | ||
| 147 | getLnglats() { | ||
| 148 | return Cesium.caratesianArrToLnglatArr(this.positions); | ||
| 149 | } | ||
| 150 | getAttr() { | ||
| 151 | if (!this.polygon) return; | ||
| 152 | var obj = {}; | ||
| 153 | var polygon = this.polygon.polygon; | ||
| 154 | obj.fill = polygon.fill._value; | ||
| 155 | obj.outline = polygon.outline._value; | ||
| 156 | obj.outlineWidth = polygon.outlineWidth._value; | ||
| 157 | obj.outlineColor = polygon.outlineColor._value; | ||
| 158 | obj.clampToGround = line.clampToGround._value; | ||
| 159 | obj.color = line.material.color._value; | ||
| 160 | return obj; | ||
| 161 | } | ||
| 162 | setStyle() {} | ||
| 163 | remove() { | ||
| 164 | if (this.polygon) { | ||
| 165 | this.state = 0; | ||
| 166 | this.viewer.entities.remove(this.polygon); | ||
| 167 | this.polygon = null; | ||
| 168 | } | ||
| 169 | } | ||
| 170 | setVisible(vis) { | ||
| 171 | this.polygon.show = vis; | ||
| 172 | } | ||
| 173 | forbidDrawWorld(isForbid) { | ||
| 174 | this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid; | ||
| 175 | this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid; | ||
| 176 | this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid; | ||
| 177 | this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid; | ||
| 178 | } | ||
| 179 | destroy() { | ||
| 180 | if (this.handler) { | ||
| 181 | this.handler.destroy(); | ||
| 182 | this.handler = null; | ||
| 183 | } | ||
| 184 | if (this.modifyHandler) { | ||
| 185 | this.modifyHandler.destroy(); | ||
| 186 | this.modifyHandler = null; | ||
| 187 | } | ||
| 188 | if (this.polygon) { | ||
| 189 | this.viewer.entities.remove(this.polygon); | ||
| 190 | this.polygon = null; | ||
| 191 | } | ||
| 192 | if (this.polyline) { | ||
| 193 | this.viewer.entities.remove(this.polyline); | ||
| 194 | this.polyline = null; | ||
| 195 | } | ||
| 196 | this.positions = []; | ||
| 197 | this.style = null; | ||
| 198 | if (this.modifyPoint) { | ||
| 199 | this.viewer.entities.remove(this.modifyPoint); | ||
| 200 | this.modifyPoint = null; | ||
| 201 | } | ||
| 202 | for (var i = 0; i < this.gonPointArr.length; i++) { | ||
| 203 | var point = this.gonPointArr[i]; | ||
| 204 | this.viewer.entities.remove(point); | ||
| 205 | } | ||
| 206 | this.gonPointArr = []; | ||
| 207 | this.state = 0; | ||
| 208 | if (this.prompt) this.prompt.destroy(); | ||
| 209 | if (this.polyline) { | ||
| 210 | this.polyline = null; | ||
| 211 | this.viewer.entities.remove(this.polyline); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | getCatesian3FromPX(px, viewer, entitys) { | ||
| 215 | var picks = viewer.scene.drillPick(px); | ||
| 216 | this.viewer.scene.render(); | ||
| 217 | var cartesian; | ||
| 218 | var isOn3dtiles = false; | ||
| 219 | for (var i = 0; i < picks.length; i++) { | ||
| 220 | var isContinue = false; | ||
| 221 | for (var step = 0; step < entitys.length; step++) { | ||
| 222 | if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) { | ||
| 223 | isContinue = true; | ||
| 224 | break; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | if (isContinue) continue; | ||
| 228 | if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取 | ||
| 229 | isOn3dtiles = true; | ||
| 230 | } | ||
| 231 | } | ||
| 232 | if (isOn3dtiles) { | ||
| 233 | cartesian = viewer.scene.pickPosition(px); | ||
| 234 | } else { | ||
| 235 | var ray = viewer.camera.getPickRay(px); | ||
| 236 | if (!ray) return null; | ||
| 237 | cartesian = viewer.scene.globe.pick(ray, viewer.scene); | ||
| 238 | } | ||
| 239 | return cartesian; | ||
| 240 | } | ||
| 241 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
src/assets/js/map/createPolyline.js
0 → 100644
| 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 |
src/assets/js/map/createRectangle.js
0 → 100644
| 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 |
src/assets/js/map/drawTool.js
0 → 100644
| 1 | import createBillboard from './createBillboard'; | ||
| 2 | import createPolyline from './createPolyline'; | ||
| 3 | import createPolygon from './createPolygon'; | ||
| 4 | import createCircle from './createCircle'; | ||
| 5 | import createRectangle from './createRectangle'; | ||
| 6 | export default { | ||
| 7 | drawTool: class DrawTool { | ||
| 8 | constructor(obj) { | ||
| 9 | if (!obj.viewer || !obj) { | ||
| 10 | console.warn("缺少必要参数!--viewer"); | ||
| 11 | return; | ||
| 12 | } | ||
| 13 | this.viewer = obj.viewer; | ||
| 14 | this.hasEdit = obj.hasEdit; | ||
| 15 | this.toolArr = []; | ||
| 16 | this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); | ||
| 17 | this.show = obj.drawEndShow; | ||
| 18 | // this.lastSelectEntity = null; | ||
| 19 | } | ||
| 20 | startDraw(opt) { | ||
| 21 | var that = this; | ||
| 22 | if (opt.type == "polyline") { | ||
| 23 | var polyline = new createPolyline(this.viewer, opt.style); | ||
| 24 | polyline.start(function (evt) { | ||
| 25 | if (that.hasEdit) { | ||
| 26 | that.unbindEdit(); | ||
| 27 | polyline.startModify(opt.modifySuccess); | ||
| 28 | that.lastSelectEntity = polyline; | ||
| 29 | } | ||
| 30 | if (opt.success) opt.success(evt); | ||
| 31 | if (that.show == false) polyline.setVisible(false); | ||
| 32 | }); | ||
| 33 | this.toolArr.push(polyline); | ||
| 34 | } | ||
| 35 | if (opt.type == "polygon") { | ||
| 36 | var polygon = new createPolygon(this.viewer, opt.style); | ||
| 37 | polygon.start(function () { | ||
| 38 | if (that.hasEdit) { | ||
| 39 | that.unbindEdit(); | ||
| 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 | }); | ||
| 120 | this.toolArr.push(billboard); | ||
| 121 | } | ||
| 122 | } | ||
| 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 | } | ||
| 179 | } | ||
| 180 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
src/assets/js/map/roller.js
0 → 100644
| 1 | export default | ||
| 2 | class Roller { | ||
| 3 | constructor(obj) { | ||
| 4 | this.imageryLayers = obj.imageryLayers; | ||
| 5 | this.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({ | ||
| 6 | url: obj.url, | ||
| 7 | layer: "tdtBasicLayer", | ||
| 8 | style: "default", | ||
| 9 | format: "image/jpeg", | ||
| 10 | tileMatrixSetID: "GoogleMapsCompatible", | ||
| 11 | show: false | ||
| 12 | })).splitDirection = Cesium.ImagerySplitDirection.LEFT; | ||
| 13 | } | ||
| 14 | screen(opt) { | ||
| 15 | var slider = opt.slider, handler = new Cesium.ScreenSpaceEventHandler(slider), moveActive = false; | ||
| 16 | function move(movement) { | ||
| 17 | if (!moveActive) return; | ||
| 18 | var relativeOffset = movement.endPosition.x; | ||
| 19 | var splitPosition = | ||
| 20 | (slider.offsetLeft + relativeOffset) / | ||
| 21 | slider.parentElement.offsetWidth; | ||
| 22 | slider.style.left = 100.0 * splitPosition + "%"; | ||
| 23 | opt.viewer.scene.imagerySplitPosition = splitPosition; | ||
| 24 | } | ||
| 25 | |||
| 26 | handler.setInputAction(function () { | ||
| 27 | moveActive = true; | ||
| 28 | }, Cesium.ScreenSpaceEventType.LEFT_DOWN); | ||
| 29 | handler.setInputAction(function () { | ||
| 30 | moveActive = true; | ||
| 31 | }, Cesium.ScreenSpaceEventType.PINCH_START); | ||
| 32 | |||
| 33 | handler.setInputAction(move, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 34 | handler.setInputAction(move, Cesium.ScreenSpaceEventType.PINCH_MOVE); | ||
| 35 | |||
| 36 | handler.setInputAction(function () { | ||
| 37 | moveActive = false; | ||
| 38 | }, Cesium.ScreenSpaceEventType.LEFT_UP); | ||
| 39 | handler.setInputAction(function () { | ||
| 40 | moveActive = false; | ||
| 41 | }, Cesium.ScreenSpaceEventType.PINCH_END); | ||
| 42 | } | ||
| 43 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment