jikai commit
Showing
15 changed files
with
454 additions
and
2065 deletions
src/assets/js/json/graphicAnalyze.json
0 → 100644
| 1 | { | ||
| 2 | "layers": [{ | ||
| 3 | "name": "建设用地管制区", | ||
| 4 | "alias": "土地利用总体规划", | ||
| 5 | "category": "总体规划", | ||
| 6 | "id": "3G_GT_JSYDGZQ", | ||
| 7 | "keys": "intersects", | ||
| 8 | "database": [{ | ||
| 9 | "table": "gt_jsydgzqgx", | ||
| 10 | "field": [{ | ||
| 11 | "name": "gzqlxmc", | ||
| 12 | "alias": "用地性质" | ||
| 13 | }] | ||
| 14 | }], | ||
| 15 | "textarea": true, | ||
| 16 | "url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/JSYDGZQ/MapServer" | ||
| 17 | }, { | ||
| 18 | "name": "西安市总体规划2017修改版", | ||
| 19 | "alias": "西安市总体规划2017修改版", | ||
| 20 | "category": "总体规划", | ||
| 21 | "id": "3G_GH_XASZTGH", | ||
| 22 | "keys": "intersects", | ||
| 23 | "database": [{ | ||
| 24 | "table": "csgh_ztgh", | ||
| 25 | "field": [{ | ||
| 26 | "name": "layer", | ||
| 27 | "alias": "用地性质" | ||
| 28 | }, { | ||
| 29 | "name": "ydxzdm", | ||
| 30 | "alias": "用地性质代码" | ||
| 31 | }] | ||
| 32 | }], | ||
| 33 | "textarea": true, | ||
| 34 | "url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/西安市总体规划2017修改/MapServer" | ||
| 35 | }, { | ||
| 36 | "name": "西安市总体规划2008版", | ||
| 37 | "alias": "西安市总体规划2008版", | ||
| 38 | "category": "总体规划", | ||
| 39 | "id": "3G_GH_XASZTGH1", | ||
| 40 | "keys": "intersects", | ||
| 41 | "database": [{ | ||
| 42 | "table": "csgh_zgydgh", | ||
| 43 | "field": [{ | ||
| 44 | "name": "ydxz", | ||
| 45 | "alias": "用地性质" | ||
| 46 | }] | ||
| 47 | }], | ||
| 48 | "textarea": true, | ||
| 49 | "url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/西安市总体规划旧版/MapServer" | ||
| 50 | }, { | ||
| 51 | "name": "过渡期适用图层", | ||
| 52 | "alias": "过渡期适用图层", | ||
| 53 | "category": "过渡期适用图层", | ||
| 54 | "id": "3G_CSGH_GDQSY", | ||
| 55 | "keys": "intersects", | ||
| 56 | "database": [{ | ||
| 57 | "table": "csgh_xxgh", | ||
| 58 | "field": [{ | ||
| 59 | "name": "layer", | ||
| 60 | "alias": "用地性质" | ||
| 61 | }, { | ||
| 62 | "name": "ydxzdm", | ||
| 63 | "alias": "用地性质代码" | ||
| 64 | }, { | ||
| 65 | "name": "fqghmc", | ||
| 66 | "alias": "规划名称" | ||
| 67 | }, { | ||
| 68 | "name": "pfwh", | ||
| 69 | "alias": "批复文号" | ||
| 70 | }, { | ||
| 71 | "name": "type", | ||
| 72 | "alias": "用地类型" | ||
| 73 | }] | ||
| 74 | }, { | ||
| 75 | "table": "csgh_ghbg", | ||
| 76 | "field": [{ | ||
| 77 | "name": "ydxzmc", | ||
| 78 | "alias": "用地性质" | ||
| 79 | }, { | ||
| 80 | "name": "ydxzdm", | ||
| 81 | "alias": "用地性质代码" | ||
| 82 | }, { | ||
| 83 | "name": "type", | ||
| 84 | "alias": "规划名称" | ||
| 85 | }, { | ||
| 86 | "name": "bgyj", | ||
| 87 | "alias": "变更依据" | ||
| 88 | }, { | ||
| 89 | "name": "bgqxz", | ||
| 90 | "alias": "变更前性质" | ||
| 91 | }, { | ||
| 92 | "name": "type", | ||
| 93 | "alias": "用地类型" | ||
| 94 | }] | ||
| 95 | }], | ||
| 96 | "textarea": true, | ||
| 97 | "url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/过渡期适用图层/MapServer" | ||
| 98 | }, { | ||
| 99 | "name": "详细规划", | ||
| 100 | "alias": "详细规划", | ||
| 101 | "category": "详细规划", | ||
| 102 | "id": "3G_JC_XXGH", | ||
| 103 | "keys": "intersects", | ||
| 104 | "database": [{ | ||
| 105 | "table": "csgh_xxghkg", | ||
| 106 | "field": [{ | ||
| 107 | "name": "layer", | ||
| 108 | "alias": "用地性质" | ||
| 109 | }, { | ||
| 110 | "name": "ydxzdm", | ||
| 111 | "alias": "用地性质代码" | ||
| 112 | }, { | ||
| 113 | "name": "name", | ||
| 114 | "alias": "规划名称" | ||
| 115 | }, { | ||
| 116 | "name": "fqghmc", | ||
| 117 | "alias": "批复文号" | ||
| 118 | }, { | ||
| 119 | "name": "type", | ||
| 120 | "alias": "用地类型" | ||
| 121 | }] | ||
| 122 | }], | ||
| 123 | "textarea": true, | ||
| 124 | "url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/详细规划/MapServer" | ||
| 125 | }, { | ||
| 126 | "name": "基本农田保护区", | ||
| 127 | "alias": "基本农田保护区", | ||
| 128 | "category": "专项规划", | ||
| 129 | "id": "3G_GH_JBNTBHQ", | ||
| 130 | "keys": "intersectsAndContains", | ||
| 131 | "database": [{ | ||
| 132 | "table": "gt_jbntbhq", | ||
| 133 | "field": [{ | ||
| 134 | "name": "tdytqlxmc", | ||
| 135 | "alias": "用地性质" | ||
| 136 | }] | ||
| 137 | }], | ||
| 138 | "textarea": false, | ||
| 139 | "url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/基本农田保护区/MapServer" | ||
| 140 | }, { | ||
| 141 | "name": "城市建设控制线", | ||
| 142 | "alias": "城市建设控制线", | ||
| 143 | "category": "专项规划", | ||
| 144 | "textarea": true, | ||
| 145 | "layers": [{ | ||
| 146 | "name": "城市黄线", | ||
| 147 | "alias": "城市黄线", | ||
| 148 | "id": "3G_WX_CSHX", | ||
| 149 | "keys": "intersects", | ||
| 150 | "database": [{ | ||
| 151 | "table": "kzx_huangxian", | ||
| 152 | "field": [{ | ||
| 153 | "name": "layer", | ||
| 154 | "alias": "用地性质" | ||
| 155 | }] | ||
| 156 | }], | ||
| 157 | "url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/城市黄线/MapServer" | ||
| 158 | }, { | ||
| 159 | "name": "城市绿线", | ||
| 160 | "alias": "城市绿线", | ||
| 161 | "id": "3G_GH_CSLX", | ||
| 162 | "keys": "intersects", | ||
| 163 | "database": [{ | ||
| 164 | "table": "kzx_lvxian", | ||
| 165 | "field": [{ | ||
| 166 | "name": "layer", | ||
| 167 | "alias": "用地性质" | ||
| 168 | }] | ||
| 169 | }], | ||
| 170 | "url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/绿线/MapServer" | ||
| 171 | }, { | ||
| 172 | "name": "城市紫线", | ||
| 173 | "alias": "城市紫线", | ||
| 174 | "id": "3G_WX_CSZX", | ||
| 175 | "keys": "intersects", | ||
| 176 | "database": [{ | ||
| 177 | "table": "kzx_zixian", | ||
| 178 | "field": [{ | ||
| 179 | "name": "gid", | ||
| 180 | "alias": "用地性质" | ||
| 181 | }] | ||
| 182 | }], | ||
| 183 | "url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/紫线/MapServer" | ||
| 184 | }, { | ||
| 185 | "name": "道路红线", | ||
| 186 | "alias": "道路红线", | ||
| 187 | "id": "3G_GH_DLHX", | ||
| 188 | "keys": "intersects", | ||
| 189 | "database": [{ | ||
| 190 | "table": "kzx_hongxian", | ||
| 191 | "field": [{ | ||
| 192 | "name": "layer", | ||
| 193 | "alias": "用地性质" | ||
| 194 | }] | ||
| 195 | }], | ||
| 196 | "url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/红线/MapServer" | ||
| 197 | }, { | ||
| 198 | "name": "城市蓝线", | ||
| 199 | "alias": "城市蓝线", | ||
| 200 | "id": "3G_WX_CSLX", | ||
| 201 | "keys": "intersects", | ||
| 202 | "database": [{ | ||
| 203 | "table": "kzx_lanxian", | ||
| 204 | "field": [{ | ||
| 205 | "name": "layer", | ||
| 206 | "alias": "用地性质" | ||
| 207 | }] | ||
| 208 | }], | ||
| 209 | "url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/蓝线/MapServer" | ||
| 210 | }] | ||
| 211 | }, { | ||
| 212 | "name": "地铁控制线", | ||
| 213 | "alias": "地铁控制线", | ||
| 214 | "category": "专项规划", | ||
| 215 | "id": "3G_GH_DTKZX", | ||
| 216 | "keys": "intersects", | ||
| 217 | "database": [{ | ||
| 218 | "table": "kzx_dtkzx", | ||
| 219 | "field": [{ | ||
| 220 | "name": "objectid", | ||
| 221 | "alias": "用地性质" | ||
| 222 | }] | ||
| 223 | }], | ||
| 224 | "textarea": false, | ||
| 225 | "url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/地铁控制线/MapServer" | ||
| 226 | }, { | ||
| 227 | "name": "城市快速路体系", | ||
| 228 | "alias": "城市快速路体系", | ||
| 229 | "category": "专项规划", | ||
| 230 | "id": "GH_CSYS_CSKSLTX", | ||
| 231 | "keys": "intersects", | ||
| 232 | "database": [{ | ||
| 233 | "table": "szjt_kslwtx", | ||
| 234 | "field": [{ | ||
| 235 | "name": "layer", | ||
| 236 | "alias": "用地性质" | ||
| 237 | }] | ||
| 238 | }], | ||
| 239 | "textarea": true, | ||
| 240 | "url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/城市快速路体系规划/MapServer" | ||
| 241 | }, { | ||
| 242 | "name": "铁路南环线", | ||
| 243 | "alias": "铁路南环线", | ||
| 244 | "category": "专项规划", | ||
| 245 | "id": "3G_JC_TLNHX", | ||
| 246 | "keys": "intersects", | ||
| 247 | "database": [{ | ||
| 248 | "table": "kzx_tlnhx", | ||
| 249 | "field": [{ | ||
| 250 | "name": "layer", | ||
| 251 | "alias": "用地性质" | ||
| 252 | }] | ||
| 253 | }], | ||
| 254 | "textarea": true, | ||
| 255 | "url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/铁路南环线/MapServer" | ||
| 256 | }, { | ||
| 257 | "name": "公交场站规划(2018-2021年)", | ||
| 258 | "alias": "公交场站规划(2018-2021年)", | ||
| 259 | "category": "专项规划", | ||
| 260 | "keys": "intersectsAndContains", | ||
| 261 | "database": [{ | ||
| 262 | "table": "szjt_gjczgh", | ||
| 263 | "field": [{ | ||
| 264 | "name": "layer", | ||
| 265 | "alias": "用地性质" | ||
| 266 | }] | ||
| 267 | }], | ||
| 268 | "id": "GH_CSYS_GJCZGH", | ||
| 269 | "url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/公交场站规划图/MapServer" | ||
| 270 | }, { | ||
| 271 | "name": "停车场规划", | ||
| 272 | "alias": "停车场规划", | ||
| 273 | "category": "专项规划", | ||
| 274 | "id": "3G_JC_XXGH", | ||
| 275 | "keys": "intersects", | ||
| 276 | "database": [{ | ||
| 277 | "table": "szjtzt_tccgh", | ||
| 278 | "field": [{ | ||
| 279 | "name": "layer", | ||
| 280 | "alias": "用地性质" | ||
| 281 | }] | ||
| 282 | }], | ||
| 283 | "textarea": true, | ||
| 284 | "url": "http://10.7.120.44:6080/arcgis/rest/services/规划2000/停车场规划/MapServer" | ||
| 285 | }, { | ||
| 286 | "name": "国家级文物保护区", | ||
| 287 | "alias": "文物保护区", | ||
| 288 | "category": "专项规划", | ||
| 289 | "id": "SZ_GJWWBH", | ||
| 290 | "keys": "intersects", | ||
| 291 | "database": [{ | ||
| 292 | "table": "wbgh_gjjwwbhq", | ||
| 293 | "field": [{ | ||
| 294 | "name": "公布类别", | ||
| 295 | "alias": "用地性质" | ||
| 296 | }] | ||
| 297 | }, { | ||
| 298 | "table": "wbgh_gjjwwbhfw", | ||
| 299 | "field": [{ | ||
| 300 | "name": "公布类别", | ||
| 301 | "alias": "用地性质" | ||
| 302 | }] | ||
| 303 | }, { | ||
| 304 | "table": "wbgh_gjjwwjskzq", | ||
| 305 | "field": [{ | ||
| 306 | "name": "公布类", | ||
| 307 | "alias": "用地性质" | ||
| 308 | }] | ||
| 309 | }], | ||
| 310 | "textarea": true, | ||
| 311 | "url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/国家级文物保护区/MapServer" | ||
| 312 | }, { | ||
| 313 | "name": "生态控制红线", | ||
| 314 | "alias": "生态控制红线", | ||
| 315 | "category": "专项规划", | ||
| 316 | "id": "HB_STKZHX", | ||
| 317 | "keys": "intersectsAndContains", | ||
| 318 | "database": [{ | ||
| 319 | "table": "stkzhx_ys", | ||
| 320 | "field": [{ | ||
| 321 | "name": "类型", | ||
| 322 | "alias": "用地性质" | ||
| 323 | }] | ||
| 324 | }], | ||
| 325 | "textarea": false, | ||
| 326 | "url": "http://10.6.144.134:6080/arcgis/rest/services/生态控制红线2000/生态保护红线/MapServer" | ||
| 327 | }, { | ||
| 328 | "name": "地质灾害防治规划", | ||
| 329 | "alias": "地质灾害防治规划", | ||
| 330 | "category": "专项规划", | ||
| 331 | "id": "GT_DZZHFZGH", | ||
| 332 | "keys": "intersects", | ||
| 333 | "database": [{ | ||
| 334 | "table": "gt_dlf", | ||
| 335 | "field": [{ | ||
| 336 | "name": "dlfsx", | ||
| 337 | "alias": "用地性质" | ||
| 338 | }] | ||
| 339 | }, { | ||
| 340 | "table": "gt_dzzhyfq", | ||
| 341 | "field": [{ | ||
| 342 | "name": "易发程", | ||
| 343 | "alias": "用地性质" | ||
| 344 | }] | ||
| 345 | }, { | ||
| 346 | "table": "gt_dzzhyhd", | ||
| 347 | "field": [{ | ||
| 348 | "name": "灾害类", | ||
| 349 | "alias": "用地性质" | ||
| 350 | }] | ||
| 351 | }], | ||
| 352 | "textarea": true, | ||
| 353 | "url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/地质灾害/MapServer" | ||
| 354 | }, { | ||
| 355 | "name": "2018年年度变更调查", | ||
| 356 | "alias": "2018年年度变更调查", | ||
| 357 | "category": "现状", | ||
| 358 | "id": "tdgh_2018ndbgdc", | ||
| 359 | "keys": "intersects", | ||
| 360 | "database": [{ | ||
| 361 | "table": "tdgh_2018ndbgdc", | ||
| 362 | "field": [{ | ||
| 363 | "name": "dlmc", | ||
| 364 | "alias": "用地性质" | ||
| 365 | }] | ||
| 366 | }], | ||
| 367 | "textarea": true, | ||
| 368 | "url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/2018年年度变更调查/MapServer" | ||
| 369 | }, { | ||
| 370 | "name": "影像地图", | ||
| 371 | "alias": "影像地图", | ||
| 372 | "category": "现状", | ||
| 373 | "id": "yxdt", | ||
| 374 | "url": "http://10.6.144.134:6080/arcgis/rest/services/影像底图2000/2018GF影像/MapServer" | ||
| 375 | }] | ||
| 376 | } |
src/assets/js/map/GraphicAttributeManager.js
0 → 100644
| 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 |
src/assets/js/map/MeasureTools.js
deleted
100644 → 0
| 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/addCompany.js
deleted
100644 → 0
| 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
deleted
100644 → 0
| 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
deleted
100644 → 0
| 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
deleted
100644 → 0
| 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
deleted
100644 → 0
| 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
deleted
100644 → 0
| 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 | } | ||
| 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 | }); | 19 | }); |
| 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 | } | 20 | } |
| 56 | if (opt.success) opt.success(billboard); | 21 | activate(c, b) { |
| 57 | if (that.show == false) billboard.setVisible(false); | 22 | this.active = !0; |
| 23 | this.drawType = c.toUpperCase(); | ||
| 24 | this.callback = b; | ||
| 25 | this.guids = []; | ||
| 26 | this.downCount = 0; | ||
| 27 | this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1); | ||
| 28 | switch (this.drawType) { | ||
| 29 | |||
| 30 | case "POINT1": | ||
| 31 | loadModules(["esri/Graphic"]).then(([h, f]) => { | ||
| 32 | this.downCount = 0; | ||
| 33 | this.view.container.addEventListener('mousedown', b => { | ||
| 34 | var a = new h(b.offsetX, b.offsetY), a = this.view.toMap(a); | ||
| 35 | console.log(a); | ||
| 36 | // this.graphic = new f(a, this.options1.pm, null); | ||
| 37 | // this.graphicsLayer.add(this.graphic); | ||
| 38 | // console.log('OKOKOK'); | ||
| 39 | // b.stopPropagation() | ||
| 58 | }); | 40 | }); |
| 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 | }); | 41 | }); |
| 72 | this.toolArr.push(circle); | 42 | |
| 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; | 43 | break; |
| 163 | } | 44 | } |
| 164 | } | 45 | } |
| 165 | if (isContinue) continue; | 46 | deactivate() { |
| 166 | if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取 | 47 | this.active = !1; |
| 167 | isOn3dtiles = true; | 48 | this.drawType = ""; |
| 168 | } | 49 | this.downCount = 0; |
| 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 | } | 50 | } |
| 180 | } | 51 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
src/assets/js/map/responseData.js
0 → 100644
| 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 | } | ... | ... |
src/assets/js/map/tool.js
deleted
100644 → 0
| 1 | |||
| 2 | export default { | ||
| 3 | attributes: { | ||
| 4 | drawPolt: class DrawPolt { | ||
| 5 | constructor(arg) { | ||
| 6 | this.viewer = arg.viewer; | ||
| 7 | this.type = {}; | ||
| 8 | this._billboardArr = []; | ||
| 9 | this._lineArr = []; | ||
| 10 | this._gonArr = []; | ||
| 11 | this.handler = null; | ||
| 12 | } | ||
| 13 | get billboardArr() { | ||
| 14 | return this._billboardArr; | ||
| 15 | } | ||
| 16 | get polylineArr() { | ||
| 17 | return this._lineArr; | ||
| 18 | } | ||
| 19 | get polygonArr() { | ||
| 20 | return this._gonArr; | ||
| 21 | } | ||
| 22 | create(e) { | ||
| 23 | this.type[e].startCreate(); | ||
| 24 | } | ||
| 25 | clearAll() { | ||
| 26 | for (var i = 0; i < this._lineArr.length; i++) { | ||
| 27 | var line = this._lineArr[i]; | ||
| 28 | line.destroy(); | ||
| 29 | } | ||
| 30 | this._lineArr = []; | ||
| 31 | for (var j = 0; j < this._gonArr.length; j++) { | ||
| 32 | var gon = this._gonArr[j]; | ||
| 33 | gon.destroy(); | ||
| 34 | } | ||
| 35 | this._gonArr = []; | ||
| 36 | for (var k = 0; k < this._billboardArr.length; k++) { | ||
| 37 | var billboard = this._billboardArr[k]; | ||
| 38 | billboard.destroy(); | ||
| 39 | } | ||
| 40 | this._billboardArr = []; | ||
| 41 | } | ||
| 42 | clearOne() { | ||
| 43 | if (!this.handler) { | ||
| 44 | this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); | ||
| 45 | } | ||
| 46 | var that = this; | ||
| 47 | this.handler.setInputAction(function (evt) { | ||
| 48 | var pick = that.viewer.scene.pick(evt.position); | ||
| 49 | if (Cesium.defined(pick) && pick.id) { | ||
| 50 | that.viewer.entities.remove(pick.id); | ||
| 51 | that.handler.destroy(); | ||
| 52 | that.handler = null; | ||
| 53 | } | ||
| 54 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 55 | } | ||
| 56 | }, | ||
| 57 | polygon: class DrawPolygon { | ||
| 58 | constructor(arg) { | ||
| 59 | this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0)); | ||
| 60 | this.viewer = arg.viewer; | ||
| 61 | this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); | ||
| 62 | this._polygon = null; | ||
| 63 | this._polyline = null; | ||
| 64 | this._positions = []; | ||
| 65 | } | ||
| 66 | get polygon() { | ||
| 67 | return this._polygon; | ||
| 68 | } | ||
| 69 | get positions() { | ||
| 70 | return this._positions; | ||
| 71 | } | ||
| 72 | startCreate(func) { | ||
| 73 | var $this = this; | ||
| 74 | this.handler.setInputAction(function (evt) { //单机开始绘制 | ||
| 75 | var cartesian = $this.getCatesian3FromPX(evt.position); | ||
| 76 | if ($this._positions.length == 0) { | ||
| 77 | $this._positions.push(cartesian.clone()); | ||
| 78 | } | ||
| 79 | $this._positions.push(cartesian); | ||
| 80 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 81 | this.handler.setInputAction(function (evt) { //移动时绘制面 | ||
| 82 | if ($this._positions.length < 1) return; | ||
| 83 | var cartesian = $this.getCatesian3FromPX(evt.endPosition); | ||
| 84 | if ($this._positions.length == 2) { | ||
| 85 | if (!Cesium.defined($this._polyline)) { | ||
| 86 | $this._polyline = $this.createPolyline(); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | if ($this._positions.length == 3) { | ||
| 90 | if ($this._polyline){ | ||
| 91 | $this.viewer.entities.remove($this._polyline); | ||
| 92 | $this._polyline = null; | ||
| 93 | } | ||
| 94 | if (!Cesium.defined($this._polygon)) { | ||
| 95 | $this._polygon = $this.createPolygon(); | ||
| 96 | $this._polygon.objId = $this.objId; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | $this._positions.pop(); | ||
| 100 | $this._positions.push(cartesian); | ||
| 101 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 102 | this.handler.setInputAction(function (evt) { | ||
| 103 | if (!$this._polygon) return; | ||
| 104 | var cartesian = $this.getCatesian3FromPX(evt.position); | ||
| 105 | $this.handler.destroy(); | ||
| 106 | $this._positions.pop(); | ||
| 107 | $this._positions.push(cartesian); | ||
| 108 | func && func($this._positions); | ||
| 109 | }, Cesium.ScreenSpaceEventType.RIGHT_CLICK); | ||
| 110 | } | ||
| 111 | createPolygon(obj) { | ||
| 112 | var $this = this; | ||
| 113 | return this.viewer.entities.add({ | ||
| 114 | polygon: { | ||
| 115 | hierarchy: new Cesium.CallbackProperty(function () { | ||
| 116 | return new Cesium.PolygonHierarchy($this._positions); | ||
| 117 | }, false), | ||
| 118 | // clampToGround: true, | ||
| 119 | // show: true, | ||
| 120 | // fill: false, | ||
| 121 | // material: Cesium.Color.RED, | ||
| 122 | // width: 3, | ||
| 123 | material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2), | ||
| 124 | perPositionHeight: true, | ||
| 125 | outlineColor: Cesium.Color.BLACK, | ||
| 126 | outlineWidth: 3, | ||
| 127 | outline: true | ||
| 128 | } | ||
| 129 | }); | ||
| 130 | } | ||
| 131 | createPolyline() { | ||
| 132 | var $this = this; | ||
| 133 | return this.viewer.entities.add({ | ||
| 134 | polyline: { | ||
| 135 | positions: new Cesium.CallbackProperty(function () { | ||
| 136 | return $this._positions | ||
| 137 | }, false), | ||
| 138 | clampToGround: true, | ||
| 139 | material: Cesium.Color.YELLOW, | ||
| 140 | width: 5 | ||
| 141 | } | ||
| 142 | }); | ||
| 143 | } | ||
| 144 | getCatesian3FromPX(px) { | ||
| 145 | var cartesian; | ||
| 146 | var ray = this.viewer.camera.getPickRay(px); | ||
| 147 | if (!ray) return null; | ||
| 148 | cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene); | ||
| 149 | return cartesian; | ||
| 150 | } | ||
| 151 | destroy() { | ||
| 152 | if (this.handler) { | ||
| 153 | this.handler.destroy(); | ||
| 154 | this.handler = null; | ||
| 155 | } | ||
| 156 | if (this._polygon) { | ||
| 157 | this.viewer.entities.remove(this._polygon); | ||
| 158 | this._polygon = null; | ||
| 159 | } | ||
| 160 | if (this._polyline) { | ||
| 161 | this.viewer.entities.remove(this._polyline); | ||
| 162 | this._polyline = null; | ||
| 163 | } | ||
| 164 | this._positions = []; | ||
| 165 | } | ||
| 166 | }, | ||
| 167 | point: class DrawBillboard { | ||
| 168 | constructor(arg) { | ||
| 169 | this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0)); | ||
| 170 | this.viewer = arg.viewer; | ||
| 171 | this._position = null; | ||
| 172 | this._billboard = null; | ||
| 173 | } | ||
| 174 | get billboard() { | ||
| 175 | return this._billboard; | ||
| 176 | } | ||
| 177 | get position() { | ||
| 178 | return this._position; | ||
| 179 | } | ||
| 180 | startCreate() { | ||
| 181 | var $this = this; | ||
| 182 | this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); | ||
| 183 | this.handler.setInputAction(evt => { //单机开始绘制 | ||
| 184 | var cartesian = $this.getCatesian3FromPX(evt.position); | ||
| 185 | // if(!Cesium.defined($this._billboard)){ | ||
| 186 | // $this._billboard = $this.createBillboard(cartesian); | ||
| 187 | // $this.handler.destroy(); | ||
| 188 | // } | ||
| 189 | this.handler.destroy(); | ||
| 190 | this.handler = undefined; | ||
| 191 | this.createBillboard(cartesian); | ||
| 192 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 193 | } | ||
| 194 | createBillboard(cartesian) { | ||
| 195 | var billboard = this.viewer.entities.add({ | ||
| 196 | position: cartesian, | ||
| 197 | point: { | ||
| 198 | color: Cesium.Color.SKYBLUE, | ||
| 199 | pixelSize: 10, | ||
| 200 | outlineColor: Cesium.Color.YELLOW, | ||
| 201 | outlineWidth: 3, | ||
| 202 | disableDepthTestDistance: Number.POSITIVE_INFINITY | ||
| 203 | } | ||
| 204 | }); | ||
| 205 | billboard.objId = this.objId; | ||
| 206 | return billboard; | ||
| 207 | } | ||
| 208 | destroy() { | ||
| 209 | if (this.handler) { | ||
| 210 | this.handler.destroy(); | ||
| 211 | this.handler = null; | ||
| 212 | } | ||
| 213 | if (this._billboard) { | ||
| 214 | this.viewer.entities.remove(this._billboard); | ||
| 215 | this._billboard = null; | ||
| 216 | } | ||
| 217 | this._position = null; | ||
| 218 | } | ||
| 219 | getCatesian3FromPX(px) { | ||
| 220 | var cartesian; | ||
| 221 | var ray = this.viewer.camera.getPickRay(px); | ||
| 222 | if (!ray) return null; | ||
| 223 | cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene); | ||
| 224 | return cartesian; | ||
| 225 | } | ||
| 226 | }, | ||
| 227 | polyline: class DrawPolyline { | ||
| 228 | constructor(arg) { | ||
| 229 | //设置唯一id 备用 | ||
| 230 | this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0)); | ||
| 231 | this.viewer = arg.viewer; | ||
| 232 | //事件 | ||
| 233 | this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); | ||
| 234 | this._polyline = null; | ||
| 235 | this._positions = []; | ||
| 236 | } | ||
| 237 | //获取线 | ||
| 238 | get line(){ | ||
| 239 | return this._polyline; | ||
| 240 | } | ||
| 241 | //获取线的坐标数组 | ||
| 242 | get positions(){ | ||
| 243 | return this._positions; | ||
| 244 | } | ||
| 245 | //开始创建 | ||
| 246 | startCreate() { | ||
| 247 | var $this = this; | ||
| 248 | this.handler.setInputAction(function (evt) { //单机开始绘制 | ||
| 249 | //屏幕坐标转地形上坐标 | ||
| 250 | var cartesian = $this.getCatesian3FromPX(evt.position); | ||
| 251 | if ($this._positions.length == 0) { | ||
| 252 | $this._positions.push(cartesian.clone()); | ||
| 253 | } | ||
| 254 | $this._positions.push(cartesian); | ||
| 255 | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
| 256 | this.handler.setInputAction(function (evt) { //移动时绘制线 | ||
| 257 | if ($this._positions.length < 1) return; | ||
| 258 | var cartesian = $this.getCatesian3FromPX(evt.endPosition); | ||
| 259 | if ($this._positions.length == 2) { | ||
| 260 | if (!Cesium.defined($this._polyline)) { | ||
| 261 | $this._polyline = $this.createPolyline(); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | if ($this._polyline) { | ||
| 265 | $this._positions.pop(); | ||
| 266 | $this._positions.push(cartesian); | ||
| 267 | } | ||
| 268 | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
| 269 | this.handler.setInputAction(function (evt) { //单机开始绘制 | ||
| 270 | if (!$this._polyline) return; | ||
| 271 | var cartesian = $this.getCatesian3FromPX(evt.position); | ||
| 272 | $this.handler.destroy(); | ||
| 273 | $this._positions.pop(); | ||
| 274 | $this._positions.push(cartesian); | ||
| 275 | }, Cesium.ScreenSpaceEventType.RIGHT_CLICK); | ||
| 276 | } | ||
| 277 | createPolyline(obj) { | ||
| 278 | if (!obj) obj = {}; | ||
| 279 | var $this = this; | ||
| 280 | var polyline = this.viewer.entities.add({ | ||
| 281 | polyline: { | ||
| 282 | //使用cesium的peoperty | ||
| 283 | positions: new Cesium.CallbackProperty(function () { | ||
| 284 | return $this._positions | ||
| 285 | }, false), | ||
| 286 | show: true, | ||
| 287 | material: Cesium.Color.YELLOW, | ||
| 288 | width:5 , | ||
| 289 | clampToGround:true | ||
| 290 | } | ||
| 291 | }); | ||
| 292 | polyline.objId = this.objId; | ||
| 293 | return polyline; | ||
| 294 | } | ||
| 295 | destroy() { | ||
| 296 | this.linePointArr = []; | ||
| 297 | if (this.handler) { | ||
| 298 | this.handler.destroy(); | ||
| 299 | this.handler = null; | ||
| 300 | } | ||
| 301 | if (this._polyline) { | ||
| 302 | this.viewer.entities.remove(this._polyline); | ||
| 303 | this._polyline = null; | ||
| 304 | } | ||
| 305 | this._positions = []; | ||
| 306 | } | ||
| 307 | getCatesian3FromPX(px) { | ||
| 308 | var cartesian; | ||
| 309 | var ray = this.viewer.camera.getPickRay(px); | ||
| 310 | if (!ray) return null; | ||
| 311 | cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene); | ||
| 312 | return cartesian; | ||
| 313 | } | ||
| 314 | } | ||
| 315 | } | ||
| 316 | } |
src/assets/js/map/towMapObjects.js
0 → 100644
-
Please register or sign in to post a comment