supermap-2.5d.vue 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113
  1. <template>
  2. <div id="supermap3D" style="width: 100%; height: 100%;background: none;overflow-y: auto;">
  3. <div id="cesiumContainer" style="width: 100%; height: 100%;background: none;">
  4. <!--地图top 显示 开始-->
  5. <transition name="fade">
  6. <div class="map-tit" v-show="mapshow">
  7. <div class="top-tit">
  8. <i class="iconfont sj-icon-jkzx"></i>
  9. <span><img src="../assets/images/close.svg" @click="mapshow=false"/></span>
  10. </div>
  11. <div class="map-txt" v-html="bindPopupHtml">
  12. </div>
  13. <el-button size="mini" type="primary" class="sj-icon-btn" @click="openTvwall()" v-if="_click!=''">
  14. 查看
  15. </el-button>
  16. <div id="super2"/>
  17. </div>
  18. </transition>
  19. <!--地图top 显示 结束-->
  20. <!--地图开挖 显示 开始-->
  21. <div id="excavation" v-if="showExcavation" class="param-container tool-bar">
  22. <div class="dzt-operate">
  23. <label class="form-label">开挖深度(米) :</label>
  24. <input type="text" class="form-control" value="20" id="depth" style="height: 25px;">
  25. </div>
  26. <div class="dzt-operate">
  27. <label class="form-label">上移高度(米) :</label>
  28. <input type="text" class="form-control" value="300" id="moveHeight" style="height: 25px;">
  29. </div>
  30. <div style="display: flex;justify-content: end;">
  31. <button id="automaticDig" class="button black" type="button">自动开挖</button>
  32. <button id="dig" class="button black" type="button">开挖</button>
  33. <button id="clear" class="button black" type="button" style="margin-right: 0">清除</button>
  34. </div>
  35. </div>
  36. <!--地图开挖 显示 结束-->
  37. <!--地图开挖分析 显示 开始-->
  38. <div id="excavationAnalyze" v-if="showExcavationAnalyze" class="param-container tool-bar">
  39. <div class="param-item">
  40. <b>开挖高程:</b>
  41. <input type="text" id="depth" value="5000" style="margin-left: 50px;">
  42. </div>
  43. <div class="param-item">
  44. <b>开挖面积(平方米):</b>
  45. <input type="text" id="cutarea" value="" style="margin-left: 10px;">
  46. </div>
  47. <div class="param-item">
  48. <b>开挖体积(立方米):</b>
  49. <input type="text" id="cutVolume" value="" style="margin-left: 10px;">
  50. </div>
  51. <div class="param-item">
  52. <b>填方面积(平方米):</b>
  53. <input type="text" id="fillarea" value="" style="margin-left: 10px;">
  54. </div>
  55. <div class="param-item">
  56. <b>填方体积(立方米):</b>
  57. <input type="text" id="fillVolume" value="" style="margin-left: 10px;">
  58. </div>
  59. <div class="param-item">
  60. <b>未填挖面积(平方米):</b>
  61. <input type="text" id="remainderArea" value="">
  62. </div>
  63. <div class="param-item" style="float: right;">
  64. <button type="button" id="filladd" class="button black">绘制</button>
  65. <button type="button" id="fillclear" class="button black">清除</button>
  66. </div>
  67. </div>
  68. <!--地图开挖分析 显示 结束-->
  69. <!--地图选择、框选 显示 开始-->
  70. <div id="boxSelection" v-if="showSoxSelection">
  71. <Form style="width: 280px;z-index: 10000;" class="tool-bar param-container" tabindex="0">
  72. <div style="margin-bottom:4px;">
  73. <input type="button" id="isSelection" class="button black"><span
  74. style="vertical-align: middle">框选</span>
  75. <input type="checkbox" id="isCallInMoving" style="vertical-align: middle;margin-right: 10px;"><span
  76. style="vertical-align: middle">实时选择</span>
  77. </div>
  78. <label>选择模式(按下选择键开始框选)</label>
  79. <select id="mode">
  80. <option value="1" selected>重置模式</option>
  81. <option value="2">并集模式</option>
  82. <option value="4">交集模式</option>
  83. <option value="8">减去模式</option>
  84. </select>
  85. </Form>
  86. </div>
  87. <!--地图选择、框选 显示 结束-->
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import {
  93. getDeviceList,queryMap,
  94. iconList
  95. } from '@/api/components/supermap.js'
  96. import Cookies from 'js-cookie'
  97. import {
  98. getConfigKey
  99. } from '@/api/system/config'
  100. export default {
  101. name: 'supermap-2.5d',
  102. data() {
  103. return {
  104. showExcavation:false,//开挖图示
  105. showExcavationAnalyze:false,//填开挖分析图示
  106. showSoxSelection:false,//选择、框选
  107. boxSelectionTooltip:null,//选择、框选Tooltip
  108. boxSelectionObjects : {//选择、框选元素
  109. isCallInMoving: false,
  110. selectedObjs: {},
  111. mode: 1
  112. },
  113. checkedCities:[],//选择的图层
  114. bindPopupHtml: null,
  115. mapshow: false,
  116. openZt: false,
  117. superMapRootUrl: null,
  118. viewer: null,
  119. scene: null,
  120. handler: null,
  121. pick: null,
  122. markerboxEntity: [], //地图落点实体
  123. connectBoxEntity: null, //地图线实体
  124. graphicsBoxEntity: null, //地图面实体
  125. graphicsBoxEntityList: [], //地图面实体
  126. markerboxEntityRadius: [], //地图落点实体
  127. connectBoxEntityTwo: null, //地图线实体
  128. /*************************原地图属性*********************/
  129. isEditableLayers: false, //绘图控件
  130. selOptV: 2, // 贴地量算
  131. clampMode: 1, // 空间模式
  132. handlerDis: null, // 距离
  133. handlerArea: null, // 面积
  134. handlerHeight: null, // 高度
  135. handlerExcavation: null, // 开挖
  136. handlerExcavationAnalyze: null, // 填开挖分析
  137. handlerBoxSelection: null, // 选择
  138. isObtainLaAndLon: false,
  139. /*************************原地图属性*********************/
  140. aac: null,
  141. queryParams: {
  142. name: null,
  143. mapData: null,
  144. mapName: null
  145. },
  146. showLayer: true,
  147. clickTime: new Date().getTime(),
  148. /*************************图层过滤属性*********************/
  149. layerList: [],
  150. dianshiqiang: null,
  151. longitude: null,
  152. latitude: null,
  153. userList: null,
  154. dataMap: {},
  155. dataNameMap: {},
  156. lonAndLat: {},
  157. mvtMap: {},
  158. queryList: {},
  159. vdivcesiumContainer: '',
  160. reportSource: '',
  161. eventStatusValue: '',
  162. cameraCode: '',
  163. cameraRadius: '',
  164. open_LifelineList: [], //生命线图层控制图层
  165. imageryProvider_hideList: [], //隐藏图层实体
  166. open_hideList: [], //隐藏图层实体
  167. openModel_hideList: [], //隐藏图层实体
  168. find_hideList: [], //隐藏图层实体
  169. findDisplayed_hideList: [], //隐藏图层实体
  170. /*************************图层过滤属性*********************/
  171. _click: null,
  172. _parameter: null,
  173. positioningEntity: null,
  174. }
  175. },
  176. watch: {},
  177. created() {
  178. },
  179. mounted() {
  180. this.showLayer = this.showLayer != undefined ? this.showLayer : false
  181. },
  182. props: {
  183. // showLayer: [Boolean],
  184. },
  185. methods: {
  186. queryMap(deptId) {
  187. queryMap(deptId).then(req => {
  188. req = req.sort(function(a, b) {
  189. return a.sort - b.sort
  190. })
  191. this.onload(req)
  192. }
  193. )
  194. },
  195. onload(supermapUrls) {
  196. let that = this
  197. const withinData = supermapUrls
  198. //1.添加地形数据
  199. that.viewer = new SuperMap3D.Viewer('cesiumContainer', {
  200. //创建地形服务提供者的实例,url为SuperMap iServer发布的TIN地形服务
  201. terrainProvider: new SuperMap3D.SuperMapTerrainProvider({
  202. url: that.superMapRootUrl + '/3D-sipingchangjing/rest/realspace/datas/dem@spyx4326',
  203. //isSct : false,//地形服务源自SuperMap iServer发布时需设置isSct为true
  204. invisibility: true
  205. }),
  206. infoBox: false,
  207. navigation: false
  208. }, {
  209. contextOptions: {
  210. msaaLevel: 4,
  211. requestWebgl2: true
  212. },
  213. orderIndependentTranslucency: false
  214. })
  215. that.scene = that.viewer.scene
  216. that.viewer._Widget._creditContainer.style.display = "none" // 去掉超图logo水印
  217. //2.添加SuperMap iServer发布的影像服务
  218. that.addImageryProvider(withinData[0].path)
  219. let longitude = withinData[0].coordinate.split(',')[0]
  220. let latitude = withinData[0].coordinate.split(',')[1]
  221. let height = withinData[0].scale
  222. setTimeout(function() {
  223. for (let i = 1; i < withinData.length; i++) {
  224. setTimeout(() => {
  225. if (withinData[i].type == 'addImagery') {
  226. if(withinData[i].note == '图层过滤'){
  227. return
  228. }
  229. that.addImageryProvider(withinData[i].path)
  230. } else if (withinData[i].type == 'addVectorTilesMap') {
  231. that.addVectorTilesMap(withinData[i].path)
  232. } else if (withinData[i].type == 'open') {
  233. if(withinData[i].note == '图层过滤'){
  234. return
  235. }
  236. that.addOpen(withinData[i].sort, withinData[i].path)
  237. }else if (withinData[i].type == 'open_model') {
  238. if(withinData[i].note == '图层过滤'){
  239. return
  240. }
  241. that.addOpen_model(withinData[i].sort, withinData[i].path)
  242. } else if (withinData[i].type == 'find') {
  243. that.addFind(withinData[i].parentId, withinData[i].path)
  244. }else if (withinData[i].type == 'findDisplayed') {
  245. that.addFind(withinData[i].parentId, withinData[i].path)
  246. }
  247. }, 100 * i)
  248. }
  249. }, 2000)
  250. that.viewer.selectedEntityChanged.addEventListener(function(entity) {
  251. if (entity != undefined && Reflect.has(entity, 'layerID')) {
  252. that.queryParams.name = entity.pickResult[entity.layerID][0].feature.properties.Name
  253. that.queryParams.mapData = entity.pickResult[entity.layerID][0].feature.properties.SmUserID
  254. that.queryParams.mapName = entity.pickResult[entity.layerID][0].feature.properties.layer
  255. getDeviceList(that.queryParams).then(res => {
  256. that.openZt = true
  257. const treeLabels = [{
  258. 'id': null,
  259. 'labelCode': '999',
  260. 'labelName': '电视墙',
  261. 'cameraType': null,
  262. 'parentLabelCode': ''
  263. }]
  264. const labelChannels = []
  265. for (let i in res.data) {
  266. if (res.data[i].cameraCode != null) {
  267. treeLabels.push({
  268. 'id': null,
  269. 'labelCode': res.data[i].cameraCode,
  270. 'labelName': res.data[i].cameraName,
  271. 'cameraType': '1',
  272. 'parentLabelCode': '999'
  273. })
  274. labelChannels.push({
  275. 'labelCode': res.data[i].cameraCode,
  276. 'channelDates': [{
  277. 'channelCode': res.data[i].cameraCode,
  278. 'channelName': res.data[i].cameraName,
  279. 'channelSn': null,
  280. 'cameraType': '1',
  281. 'online': '1',
  282. 'cameraCode': '1'
  283. }]
  284. })
  285. }
  286. }
  287. that.dianshiqiang = [{
  288. 'switchTab': '2',
  289. 'treeLabels': treeLabels,
  290. 'labelChannels': labelChannels
  291. }]
  292. that.longitude = res.data[0].longitude
  293. that.latitude = res.data[0].latitude
  294. that.userList = res.data[0].userList
  295. let html =
  296. '<div class="map-tip">' +
  297. '<span>' +
  298. ' <div class="d-l-con">' +
  299. ' <div class="d-l-l-text">' +
  300. ' <h4>名称:' + res.data[0].name +
  301. '</h4>' +
  302. ' </div>' +
  303. ' </div>' +
  304. ' </span>'
  305. for (let i in res.data[0].userList) {
  306. html += '<span>' +
  307. ' <div class="d-l-con">' +
  308. ' <div class="d-l-l-text">' +
  309. ' <h4>' + res.data[0].userList[i].position + ':' + res.data[0].userList[i]
  310. .name + '</h4>' +
  311. ' </div>' +
  312. ' </div>' +
  313. ' </span>' +
  314. '<span>' +
  315. ' <div class="d-l-con">' +
  316. ' <div class="d-l-l-text">' +
  317. ' <h4>电话:' + (res.data[0].userList[i].phone ? res.data[0].userList[i].phone :
  318. '') + '</h4>' +
  319. ' </div>' +
  320. ' </div>' +
  321. ' </span>'
  322. }
  323. html += '</div>'
  324. that.bindPopupHtml = html
  325. that.openTvwall()
  326. })
  327. }
  328. });
  329. that.handler = new SuperMap3D.ScreenSpaceEventHandler(that.scene.canvas);
  330. // that.scene.open('http://116.142.80.12:8090/iserver/services/3D-aode/rest/realspace',undefined,{
  331. // autoSetView : false //不自动定位
  332. // })
  333. // that.scene.open('http://116.142.80.12:8090/iserver/services/3D-ganghuaranqi/rest/realspace',undefined,{
  334. // autoSetView : false //不自动定位
  335. // })
  336. // that.scene.open(' http://116.142.80.12:8090/iserver/services/3D-huashengranqi-2/rest/realspace',undefined,{
  337. // autoSetView : false //不自动定位
  338. // })
  339. // that.scene.open('http://116.142.80.12:8090/iserver/services/3D-PaiShui/rest/realspace',undefined,{
  340. // autoSetView : false //不自动定位
  341. // })
  342. // that.scene.open('http://116.142.80.12:8090/iserver/services/3D-reli_yici_erci_guanduan-2/rest/realspace',undefined,{
  343. // autoSetView : false //不自动定位
  344. // })
  345. that.flyTo(longitude, latitude, height)
  346. //设置鼠标左键单击回调事件
  347. that.handler.setInputAction(function (e) {
  348. if (that.isObtainLaAndLon) {
  349. if (that.positioningEntity != null) {
  350. that.viewer.entities.remove(that.positioningEntity);
  351. }
  352. //首先移除之前添加的点
  353. // viewer.entities.removeAll();
  354. //获取点击位置笛卡尔坐标
  355. var position = that.scene.pickPosition(e.position);
  356. //将笛卡尔坐标转化为经纬度坐标
  357. var cartographic = SuperMap3D.Cartographic.fromCartesian(position);
  358. var longitude = SuperMap3D.Math.toDegrees(cartographic.longitude);
  359. var latitude = SuperMap3D.Math.toDegrees(cartographic.latitude);
  360. var height = cartographic.height;
  361. if (height < 0) {
  362. height = 0;
  363. }
  364. that.positioningEntity = that.viewer.entities.add({
  365. name: "",
  366. position: new SuperMap3D.Cartesian3.fromDegrees(longitude, latitude),
  367. billboard: {
  368. image: iconList['positioning'],
  369. width: 48,
  370. height: 48,
  371. heightReference: SuperMap3D.HeightReference.CLAMP_TO_GROUND,
  372. disableDepthTestDistance: Number.POSITIVE_INFINITY
  373. },
  374. })
  375. that.$emit('setPositioning', longitude, latitude);
  376. }
  377. }, SuperMap3D.ScreenSpaceEventType.LEFT_CLICK);
  378. },
  379. //初始化地图数据
  380. removeAllviewer(deptId, index) {
  381. if (index != -1) {
  382. $('#cesiumContainer').remove()
  383. $('#supermap3D').append(
  384. '<div id="cesiumContainer" style="width: 100%; height: 100%;background: none;" >\n' +
  385. ' </div>')
  386. }
  387. let that = this
  388. that.superMapInfo(deptId)
  389. },
  390. superMapInfo(index) {
  391. let deptId = index;
  392. getConfigKey('superMap.iServer').then(response => {
  393. this.superMapRootUrl = response.msg
  394. // this.queryMap(index)
  395. Cookies.set('superMap.iServer', response.msg)
  396. setTimeout(() =>
  397. this.queryVectorTilesMapList(deptId) //切换地图
  398. ,1000
  399. )
  400. })
  401. },
  402. // ***************************生命线---图层过滤 开始************************************************
  403. addLifelineOpen(checkedCities) {
  404. this.checkedCities=checkedCities
  405. checkedCities.forEach(url => {
  406. if (!url) return; // 如果没有 URL,跳过当前迭代
  407. if(!this.open_LifelineList.some(item => item.url === url)){//查找已勾选的图层数组
  408. let obj = this.scene.open(this.superMapRootUrl +url,undefined,{
  409. autoSetView : false //不自动定位
  410. })
  411. this.open_LifelineList.push({
  412. url: url,
  413. mapObj: obj
  414. })
  415. // 管线流动
  416. // SuperMap3D.when(obj, function (layer) {
  417. // var line = scene.layers.find("huashengranqi");
  418. // line.textureUVSpeed = new SuperMap3D.Cartesian2(0, -2);//模型纹理在UV坐标上的运动速度
  419. // });
  420. }else{
  421. SuperMap3D.when.all(this.selectMapObj(url), function (layers) {
  422. for (var layer of layers) {
  423. layer.visible = true;
  424. }
  425. });
  426. }
  427. });
  428. const urlsToRemove = this.open_LifelineList.map(item => item.url).filter(url => !checkedCities.includes(url));//查找没勾选的图层数组
  429. console.log('选中的url:', checkedCities);
  430. console.log('移除的url:', urlsToRemove);
  431. urlsToRemove.forEach(url => {
  432. if (!url) return; // 如果没有 URL,跳过当前迭代
  433. SuperMap3D.when.all(this.selectMapObj(url), function (layers) {
  434. for (var layer of layers) {
  435. layer.visible = false;
  436. }
  437. });
  438. });
  439. },
  440. selectMapObj(url) {
  441. const item = this.open_LifelineList.find(item => item.url === url);
  442. let mapObj= item ? item.mapObj : null;
  443. return mapObj
  444. },
  445. // ***************************生命线---图层过滤 结束************************************************
  446. // ***************************图层过滤 开始************************************************
  447. reload(list) {
  448. this.removeAllMvt()
  449. this.removeAllImageryProvider_hide()
  450. this.removeAllOpen_hide()
  451. this.removeAllOpenModel_hide()
  452. this.layerList = list
  453. let that = this
  454. for (let i = 0; i < this.layerList.length; i++) {
  455. let data = this.queryList.filter(item => item.id == this.layerList[i]) [0]
  456. if (data.type == 'addImagery') {
  457. let imageryProvider = that.addImageryProvider(data.path)
  458. that.imageryProvider_hideList.push(imageryProvider)
  459. } else if(data.type=='addVectorTilesMap'){
  460. for (let key in that.mvtMap) {
  461. if (data.id == key) {
  462. that.mvtMap[key].show = true
  463. let dat = this.queryList.filter(item => item.parentId == data.id)
  464. for (let j = 0; j < dat.length; j++) {
  465. let da = this.queryList.filter(item => item.parentId == dat[j].id)
  466. for (let k = 0; k < da.length; k++) {
  467. for (let dataNameMapKey in that.dataNameMap) {
  468. if (dataNameMapKey == da[k].id) {
  469. this.dataMap[da[k].parentId].then(function() {
  470. that.dataNameMap[dataNameMapKey].visible = true
  471. })
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. } else if (data.type == 'open') {
  479. let open = that.addOpen(data.id, data.path)
  480. that.open_hideList.push(open)
  481. } else if (data.type == 'open_model') {
  482. let openModel = that.addOpen_model(data.id, data.path)
  483. that.openModel_hideList.push(openModel)
  484. } else if (data.type == 'find') {
  485. let find = that.addFind(data.id, data.path)
  486. that.find_hideList.push(find)
  487. } else if (data.type == 'findDisplayed') {
  488. let findDisplayed = that.addFindDisplayed(data.id, data.path)
  489. that.findDisplayed_hideList.push(findDisplayed)
  490. }
  491. }
  492. },
  493. removeAllMvt() {
  494. let that = this
  495. // 移除方法,暂存:this.viewer.scene.removeVectorTilesMap(this.mvtMap.name);
  496. for (let i = 0; i < this.queryList.length; i++) {
  497. let data = this.queryList[i]
  498. for (let key in that.mvtMap) {
  499. if (data.id == key) {
  500. that.mvtMap[key].show = false
  501. let dat = this.queryList.filter(item => item.parentId == data.id)
  502. for (let j = 0; j < dat.length; j++) {
  503. if (dat[j].parentId != null) {
  504. let da = this.queryList.filter(item => item.parentId == dat[j].id)
  505. for (let k = 0; k < da.length; k++) {
  506. for (let dataNameMapKey in that.dataNameMap) {
  507. this.dataMap[da[k].parentId].then(function() {
  508. that.dataNameMap[dataNameMapKey].visible = false
  509. })
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. },
  518. removeAllImageryProvider_hide() {
  519. let that = this
  520. if (that.imageryProvider_hideList != null && that.imageryProvider_hideList.length > 0) {
  521. for (let i = 0; i < that.imageryProvider_hideList.length; i++) {
  522. that.viewer.imageryLayers.remove(that.imageryProvider_hideList[i])
  523. }
  524. that.imageryProvider_hideList = []
  525. }
  526. },
  527. removeAllOpen_hide() {
  528. let that = this
  529. if (that.open_hideList != null && that.open_hideList.length > 0) {
  530. for (let i = 0; i < that.open_hideList.length; i++) {
  531. SuperMap3D.when.all(that.open_hideList[i], function (layers) {
  532. for (var layer of layers) {
  533. // that.scene.layers.remove(layer.name);
  534. layer.visible = false;
  535. }
  536. });
  537. }
  538. // that.open_hideList = []
  539. }
  540. },
  541. removeAllOpenModel_hide() {
  542. let that = this
  543. if (that.openModel_hideList != null && that.openModel_hideList.length > 0) {
  544. for (let i = 0; i < that.openModel_hideList.length; i++) {
  545. SuperMap3D.when.all(that.openModel_hideList[i], function (layers) {
  546. const reversedLayers = [...layers].reverse();
  547. for (var layer of reversedLayers) {
  548. that.scene.layers.remove(layer.name);
  549. that.viewer.imageryLayers.remove(layer)
  550. }
  551. });
  552. }
  553. that.openModel_hideList = []
  554. }
  555. },
  556. addFindDisplayed(id, uri) {
  557. let that = this
  558. let data = that.queryList.filter(item => item.id == id)[0]
  559. that.dataMap[data.parentId].then(function(layers) {
  560. let obj = that.scene.layers.find(uri) //区县文字图层
  561. //加载后隐藏
  562. obj.visible = false
  563. // //关闭避让
  564. obj.isOverlapDisplayed = true
  565. that.dataNameMap[id] = obj
  566. return obj
  567. })
  568. },
  569. addFind(id, uri){
  570. let that = this;
  571. let data = that.queryList.filter(item => item.id === id)
  572. if(data.length === 0) {
  573. return;
  574. }
  575. that.dataMap[data[0].parentId].then(function(layers) {
  576. let obj = that.scene.layers.find(uri) //区县文字图层
  577. return obj
  578. })
  579. },
  580. addOpen_model(sort, uri) {
  581. let that = this
  582. // that.dataMap[sort] = that.scene.open(that.superMapRootUrl + uri)
  583. let obj = that.dataMap[sort] = that.scene.open(that.superMapRootUrl + uri,undefined,{
  584. autoSetView : false //不自动定位
  585. })
  586. //开始加载专题图等数据,8秒后开始执行
  587. setTimeout(function () {
  588. /**
  589. * @param dom ScreenSpaceEventHandler操作的dom节点,画的框会成为其子节点
  590. */
  591. function DrawRectHandler(dom) {
  592. let startPoint,
  593. self = this,
  594. isShiftAndLeftDown = false,
  595. handler = new SuperMap3D.ScreenSpaceEventHandler(dom),
  596. removalFunctions = [],
  597. rect = new Rect(dom)
  598. this.isDestroyed = false
  599. this.activeEvt = new SuperMap3D.Event()
  600. this.cancelEvt = new SuperMap3D.Event()
  601. this.movingEvt = new SuperMap3D.Event()
  602. this.drawEvt = new SuperMap3D.Event()
  603. // div框
  604. function Rect(parentDom) {
  605. this.rect = document.createElement('div')
  606. this.rect.style.visibility = 'hidden'
  607. parentDom.appendChild(this.rect)
  608. this.leftTopPoint = new SuperMap3D.Cartesian2()
  609. this.rightBottomPoint = new SuperMap3D.Cartesian2()
  610. Rect.prototype.setPosition = function (startPoint, endPosition) {
  611. let w = endPosition.x - startPoint.x
  612. let h = endPosition.y - startPoint.y
  613. let left, top, width, height
  614. if (w < 0) {
  615. left = endPosition.x
  616. width = -w
  617. } else {
  618. left = startPoint.x
  619. width = w
  620. }
  621. if (h < 0) {
  622. top = endPosition.y
  623. height = -h
  624. } else {
  625. top = startPoint.y
  626. height = h
  627. }
  628. this.leftTopPoint = new SuperMap3D.Cartesian2(left, top)
  629. this.rightBottomPoint = new SuperMap3D.Cartesian2(left + width, top + height)
  630. this.rect.style = `position:fixed;top:${top}px;left:${left}px;width:${width}px;height:${height}px;border:2px dashed #333;`
  631. this.setVisible(true)
  632. }
  633. Rect.prototype.setVisible = function (isVisible) {
  634. this.rect.style.visibility = isVisible ? 'visible' : 'hidden'
  635. }
  636. Rect.prototype.getRectPoint = function () {
  637. return {
  638. leftTopPoint: this.leftTopPoint,
  639. rightBottomPoint: this.rightBottomPoint
  640. }
  641. }
  642. Rect.prototype.destroy = function () {
  643. dom.removeChild(rect)
  644. this.rect = null
  645. }
  646. }
  647. // canvas框
  648. function RectCanvas(parentDom) {
  649. let canvas = document.createElement('canvas'),
  650. ctx = canvas.getContext('2d')
  651. this.canvas = canvas
  652. canvas.width = parentDom.clientWidth
  653. canvas.height = parentDom.clientHeight
  654. canvas.style = 'position:fixed;top:0;left:0;z-index:-1'
  655. parentDom.appendChild(canvas)
  656. this.leftTopPoint = new SuperMap3D.Cartesian2()
  657. this.rightBottomPoint = new SuperMap3D.Cartesian2()
  658. RectCanvas.prototype.setPosition = function (startPoint, endPosition) {
  659. let w = endPosition.x - startPoint.x
  660. let h = endPosition.y - startPoint.y
  661. let left, top, width, height
  662. if (w < 0) {
  663. left = endPosition.x
  664. width = -w
  665. } else {
  666. left = startPoint.x
  667. width = w
  668. }
  669. if (h < 0) {
  670. top = endPosition.y
  671. height = -h
  672. } else {
  673. top = startPoint.y
  674. height = h
  675. }
  676. this.leftTopPoint = new SuperMap3D.Cartesian2(left, top)
  677. this.rightBottomPoint = new SuperMap3D.Cartesian2(left + width, top + height)
  678. ctx.clearRect(0, 0, canvas.width, canvas.height)
  679. ctx.strokeRect(left, top, width, height)
  680. }
  681. RectCanvas.prototype.setVisible = function (isVisible) {
  682. if (isVisible) {
  683. canvas.style.zIndex = '999'
  684. } else {
  685. canvas.style.zIndex = '-1'
  686. }
  687. }
  688. RectCanvas.prototype.getRectPoint = function () {
  689. return {
  690. leftTopPoint: this.leftTopPoint,
  691. rightBottomPoint: this.rightBottomPoint
  692. }
  693. }
  694. RectCanvas.prototype.destroy = function () {
  695. dom.removeChild(canvas)
  696. ctx = null
  697. this.canvas = null
  698. }
  699. }
  700. // 开关相机控制
  701. function setCameraCtrl(isActive) {
  702. let cameraCtrl = that.scene.screenSpaceCameraController
  703. cameraCtrl.enableRotate = isActive
  704. cameraCtrl.enableTranslate = isActive
  705. cameraCtrl.enableZoom = isActive
  706. cameraCtrl.enableTilt = isActive
  707. cameraCtrl.enableLook = isActive
  708. }
  709. // 鼠标cursor控制
  710. function toggleCursorStyle(isActive) {
  711. if (isActive) {
  712. that.viewer.enableCursorStyle = false
  713. that.viewer._element.style.cursor = ''
  714. dom.style.cursor = 'default'
  715. } else {
  716. that.viewer.enableCursorStyle = true
  717. }
  718. }
  719. // 初始化事件处理
  720. function initEvent() {
  721. handler.setInputAction(function (e) {
  722. isShiftAndLeftDown = true
  723. startPoint = new SuperMap3D.Cartesian2(e.position.x, e.position.y)
  724. }, SuperMap3D.ScreenSpaceEventType.LEFT_DOWN, SuperMap3D.KeyboardEventModifier.SHIFT)
  725. // shift松开时,始终将rect隐藏
  726. let keyUpFunction = function (e) {
  727. self.cancelEvt.raiseEvent()
  728. if (e.key == 'Shift' && isShiftAndLeftDown && !self.isDestroyed) {
  729. isShiftAndLeftDown = false
  730. rect.setVisible(false)
  731. }
  732. }
  733. document.addEventListener('keyup', keyUpFunction)
  734. removalFunctions.push(function () {
  735. document.removeEventListener('keyup', keyUpFunction)
  736. })
  737. handler.setInputAction(function (e) {
  738. let endPosition = e.endPosition
  739. self.activeEvt.raiseEvent(endPosition)
  740. if (!isShiftAndLeftDown) return
  741. rect.setPosition(startPoint, endPosition)
  742. rect.setVisible(true)
  743. self.movingEvt.raiseEvent(rect.getRectPoint())
  744. }, SuperMap3D.ScreenSpaceEventType.MOUSE_MOVE, SuperMap3D.KeyboardEventModifier.SHIFT)
  745. handler.setInputAction(function (e) {
  746. isShiftAndLeftDown = false
  747. rect.setVisible(false)
  748. self.drawEvt.raiseEvent(rect.getRectPoint())
  749. }, SuperMap3D.ScreenSpaceEventType.LEFT_UP, SuperMap3D.KeyboardEventModifier.SHIFT)
  750. handler.setInputAction(function (e) {
  751. isShiftAndLeftDown = false
  752. rect.setVisible(false)
  753. }, SuperMap3D.ScreenSpaceEventType.LEFT_UP)
  754. }
  755. // 移除事件监听
  756. function removeEvent() {
  757. handler.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_DOWN, SuperMap3D.KeyboardEventModifier.SHIFT)
  758. handler.removeInputAction(SuperMap3D.ScreenSpaceEventType.MOUSE_MOVE, SuperMap3D.KeyboardEventModifier.SHIFT)
  759. handler.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_UP, SuperMap3D.KeyboardEventModifier.SHIFT)
  760. handler.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_UP)
  761. }
  762. DrawRectHandler.prototype.destroy = function () {
  763. if (this.isDestroyed) return
  764. setCameraCtrl(true)
  765. removeEvent()
  766. for (let i = 0, j = removalFunctions.length; i < j; i++) {
  767. removalFunctions[i]()
  768. }
  769. handler.destroy()
  770. rect.destroy()
  771. rect = null
  772. this.isDestroyed = true
  773. }
  774. DrawRectHandler.prototype.activate = function () {
  775. if (this.isDestroyed) return
  776. setCameraCtrl(false)
  777. toggleCursorStyle(true)
  778. initEvent()
  779. }
  780. DrawRectHandler.prototype.deactivate = function () {
  781. if (this.isDestroyed) return
  782. setCameraCtrl(true)
  783. toggleCursorStyle(false)
  784. removeEvent()
  785. }
  786. }
  787. new SuperMap3D.when(that.dataMap[sort], function (layers) {
  788. for (let layer of layers) {
  789. layer.selectColorType = 1
  790. that.selectedObjs[layer.name] = []
  791. that.resetIds[layer.name] = []
  792. }
  793. let drawRect = that.drawRect = new DrawRectHandler(document.body)
  794. // res为框的左上点与右下点的相对于给定dom节点的坐标
  795. drawRect.drawEvt.addEventListener(function (res) {
  796. for (let layer of layers) {
  797. layer.selectColorType = 1
  798. }
  799. that.tooltip = false
  800. let selectedColor = new SuperMap3D.Color(1, 0, 0, 1)
  801. that.scene.pickRect(res.leftTopPoint, res.rightBottomPoint)
  802. let objs = that.scene.getPickRectIDs()
  803. let selectedObjs = that.selectedObjs
  804. let resetIds = that.resetIds
  805. for (let k in selectedObjs) {
  806. if (selectedObjs[k].length > 0) {
  807. that.scene.layers.find(k).removeObjsColor(selectedObjs[k])
  808. }
  809. }
  810. if (that.kuangxuan) {
  811. for (let layer of layers) {
  812. let layerName = layer.name
  813. if (layerName === undefined) break
  814. let layerSlt = objs.find(e => e.layerName === layerName)
  815. let sltIds = (layerSlt && layerSlt.ids) || []
  816. resetIds[layerName] = selectedObjs[layerName]
  817. selectedObjs[layerName] = sltIds
  818. that.$parent.$refs.ldTk.FrameSelectedData(sltIds)
  819. that.$parent.$refs.ldTk.allLouDongDialog = true
  820. layer.setObjsColor(selectedObjs[layerName], selectedColor)
  821. }
  822. }
  823. })
  824. drawRect.movingEvt.addEventListener(function (res) {
  825. that.tooltip = true
  826. if (that.kuangxuan) {
  827. that.tooltipText = "松开鼠标左键以结束选择区域"
  828. for (let layer of layers) {
  829. layer.selectColorType = 1
  830. }
  831. that.scene.pickRect(res.leftTopPoint, res.rightBottomPoint)
  832. } else {
  833. that.tooltipText = "请点击框选"
  834. }
  835. })
  836. drawRect.activeEvt.addEventListener(function (position) {
  837. that.tooltip = true
  838. if (that.kuangxuan) {
  839. that.tooltipText = "松开鼠标左键以结束选择区域"
  840. } else {
  841. that.tooltipText = "请点击框选"
  842. }
  843. })
  844. drawRect.cancelEvt.addEventListener(function () {
  845. that.tooltip = false
  846. })
  847. let canvas = document.querySelector('div.cesium-widget canvas')
  848. canvas.setAttribute('tabindex', '0') // needed to put focus on the canvas
  849. canvas.focus()
  850. document.addEventListener('keydown', function (e) {
  851. if (e.key === 'Shift') {
  852. drawRect.activate()
  853. }
  854. })
  855. document.addEventListener('keyup', function (e) {
  856. if (e.key === 'Shift') {
  857. drawRect.deactivate()
  858. }
  859. })
  860. }, function () {
  861. // let title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?'
  862. // widget.showErrorPanel(title, undefined, e)
  863. }).then(function () {
  864. }, function (e) {
  865. console.log(e)
  866. })
  867. }, 3000);
  868. return obj
  869. },
  870. addOpen(id, uri) {
  871. let that = this;
  872. let obj = that.scene.open(that.superMapRootUrl + uri)
  873. // {
  874. // autoSetView : false //不自动定位
  875. // },
  876. that.dataMap[id] = obj
  877. return obj;
  878. },
  879. addVectorTilesMap(uri) {
  880. let that = this
  881. that.scene.addVectorTilesMap({
  882. url: that.superMapRootUrl + uri,
  883. canvasWidth: 512,
  884. name: 'mvt_map3',
  885. viewer: that.viewer,
  886. show: true
  887. })
  888. },
  889. addImageryProvider(uri){
  890. let that = this;
  891. let obj = that.viewer.imageryLayers.addImageryProvider(new SuperMap3D.SuperMapImageryProvider({
  892. url:that.superMapRootUrl + uri
  893. }));
  894. return obj;
  895. },
  896. // ************************************************************************图层过滤 结束***********************************************************************************
  897. // 清除测距、测面、测高
  898. closeMeasuringAll() {
  899. if (this.handlerDis != null) {
  900. this.handlerDis.clear()
  901. }
  902. if (this.handlerArea != null) {
  903. this.handlerArea.clear()
  904. }
  905. if (this.handlerHeight != null) {
  906. this.handlerHeight.clear()
  907. }
  908. },
  909. // 清除开挖,填开挖分析
  910. closeExcavationAll() {
  911. if (this.handlerExcavation != null) {
  912. this.handlerExcavation.deactivate();
  913. this.handlerExcavation.clear();
  914. this.viewer.scene.globe.removeAllExtractRegion();
  915. this.showExcavation = false//开挖图示
  916. }
  917. if (this.handlerExcavationAnalyze != null) {
  918. this.viewer.scene.globe.removeAllModifyRegion();
  919. document.getElementById("cutarea").value = "";
  920. document.getElementById("cutVolume").value = "";
  921. document.getElementById("fillarea").value = "";
  922. document.getElementById("fillVolume").value = "";
  923. document.getElementById("remainderArea").value = "";
  924. this.handlerExcavationAnalyze.clear();
  925. this.showExcavationAnalyze = false//开挖分析图示
  926. }
  927. },
  928. // 测量距离
  929. choseMeasuringDistance() {
  930. let that = this
  931. if (that.handlerDis != null) {
  932. that.handlerDis.deactivate()
  933. that.handlerDis.clear()
  934. }
  935. //初始化测量距离
  936. that.handlerDis = new SuperMap3D.MeasureHandler(that.viewer, SuperMap3D.MeasureMode.Distance, that.clampMode)
  937. that.handlerDis.clampMode = 1
  938. //注册测距功能事件
  939. that.handlerDis.measureEvt.addEventListener(function(result) {
  940. var dis = Number(result.distance)
  941. var selOptV = that.selOptV
  942. if (selOptV == 3 || selOptV == 4) {
  943. dis = Number(calcClampDistance(positions))
  944. }
  945. var distance = dis > 1000 ? (dis / 1000).toFixed(2) + 'km' : dis.toFixed(2) + 'm'
  946. that.handlerDis.disLabel.text = '距离:' + distance
  947. })
  948. that.handlerDis.activeEvt.addEventListener(function(isActive) {
  949. if (isActive == true) {
  950. that.viewer.enableCursorStyle = false
  951. that.viewer._element.style.cursor = ''
  952. $('#super2').removeClass('measureCur').addClass('measureCur')
  953. that.viewer.scene.pickPointEnabled = false
  954. } else {
  955. that.viewer.enableCursorStyle = true
  956. $('#super2').removeClass('measureCur')
  957. that.viewer.scene.pickPointEnabled = false
  958. }
  959. })
  960. that.handlerDis.activate()
  961. },
  962. // 测量面积
  963. choseMeasuringArea() {
  964. let that = this
  965. if (that.handlerArea != null) {
  966. // that.handlerArea.deactivate()
  967. that.handlerArea.clear()
  968. }
  969. //初始化测量面积
  970. that.handlerArea = new SuperMap3D.MeasureHandler(that.viewer, SuperMap3D.MeasureMode.Area, that.clampMode)
  971. that.handlerArea.clampMode = 1
  972. that.handlerArea.measureEvt.addEventListener(function(result) {
  973. var mj = Number(result.area)
  974. var area = mj > 1000000 ? (mj / 1000000).toFixed(2) + 'km²' : mj.toFixed(2) + '㎡'
  975. that.handlerArea.areaLabel.text = '面积:' + area
  976. })
  977. that.handlerArea.activeEvt.addEventListener(function(isActive) {
  978. if (isActive == true) {
  979. that.viewer.enableCursorStyle = false
  980. that.viewer._element.style.cursor = ''
  981. $('#super2').removeClass('measureCur').addClass('measureCur')
  982. that.viewer.scene.pickPointEnabled = false
  983. } else {
  984. that.viewer.enableCursorStyle = true
  985. that.viewer._element.style.cursor = ''
  986. $('#super2').removeClass('measureCur')
  987. that.viewer.scene.pickPointEnabled = false
  988. }
  989. })
  990. that.handlerArea.activate()
  991. },
  992. // 测量高度
  993. choseMeasuringHeight() {
  994. let that = this
  995. if (that.handlerHeight != null) {
  996. // that.handlerHeight.deactivate()
  997. that.handlerHeight.clear()
  998. }
  999. //初始化测量高度
  1000. that.handlerHeight = new SuperMap3D.MeasureHandler(that.viewer, SuperMap3D.MeasureMode.DVH);
  1001. that.handlerHeight.measureEvt.addEventListener(function (result) {
  1002. var distance = result.distance > 1000 ? (result.distance / 1000).toFixed(2) + 'km' : result.distance + 'm';
  1003. var vHeight = result.verticalHeight > 1000 ? (result.verticalHeight / 1000).toFixed(2) + 'km' : result.verticalHeight + 'm';
  1004. var hDistance = result.horizontalDistance > 1000 ? (result.horizontalDistance / 1000).toFixed(2) + 'km' : result.horizontalDistance + 'm';
  1005. that.handlerHeight.disLabel.text = '空间距离:' + distance;
  1006. that.handlerHeight.vLabel.text = '垂直高度:' + vHeight;
  1007. that.handlerHeight.hLabel.text = '水平距离:' + hDistance;
  1008. //实时等高线显示
  1009. lineHeight = Number(result.endHeight);
  1010. if (isShowLine) updateContourLine(lineHeight)
  1011. });
  1012. that.handlerHeight.activeEvt.addEventListener(function (isActive) {
  1013. if (isActive == true) {
  1014. that.viewer.enableCursorStyle = false;
  1015. that.viewer._element.style.cursor = '';
  1016. $('body').removeClass('measureCur').addClass('measureCur');
  1017. that.viewer.scene.pickPointEnabled = pickPointEnabled;
  1018. }
  1019. else {
  1020. that.viewer.enableCursorStyle = true;
  1021. $('body').removeClass('measureCur');
  1022. that.viewer.scene.pickPointEnabled = false;
  1023. }
  1024. });
  1025. that.handlerHeight.activate()
  1026. },
  1027. //开挖
  1028. excavation(){
  1029. let that = this
  1030. that.showExcavation=true
  1031. setTimeout(function() {
  1032. var tooltip = createTooltip(document.body);
  1033. that.handlerExcavation = new SuperMap3D.DrawHandler(that.viewer, SuperMap3D.DrawMode.Polygon);
  1034. that.handlerExcavation.activeEvt.addEventListener(function(isActive) {
  1035. if(isActive == true) {
  1036. that.viewer.enableCursorStyle = false;
  1037. that.viewer._element.style.cursor = '';
  1038. $('body').removeClass('drawCur').addClass('drawCur');
  1039. } else {
  1040. that.viewer.enableCursorStyle = true;
  1041. $('body').removeClass('drawCur');
  1042. }
  1043. });
  1044. that.handlerExcavation.movingEvt.addEventListener(function(windowPosition) {
  1045. if(that.handlerExcavation.isDrawing) {
  1046. tooltip.showAt(windowPosition, '<p>绘制多边形,</p><p>右键结束绘制.</p>');
  1047. } else {
  1048. tooltip.showAt(windowPosition, '<p>点击绘制第一个点</p>');
  1049. }
  1050. });
  1051. that.handlerExcavation.drawEvt.addEventListener(function(res) {
  1052. var positions = [].concat(res.object.positions);
  1053. var positionsDegrees = [];
  1054. for(var i = 0; i < positions.length; i++) {
  1055. var cartographic = SuperMap3D.Cartographic.fromCartesian(positions[i]);
  1056. var lon = SuperMap3D.Math.toDegrees(cartographic.longitude);
  1057. var lat = SuperMap3D.Math.toDegrees(cartographic.latitude);
  1058. var h = cartographic.height;
  1059. positionsDegrees = positionsDegrees.concat([lon, lat, h]);
  1060. }
  1061. that.extract(positionsDegrees);
  1062. that.handlerExcavation.clear();
  1063. that.handlerExcavation.deactivate();
  1064. tooltip.setVisible(false);
  1065. })
  1066. //清除剖切结果
  1067. $('#clear').click(function() {
  1068. tooltip.setVisible(false);
  1069. that.handlerExcavation.deactivate();
  1070. that.handlerExcavation.clear();
  1071. that.viewer.scene.globe.removeAllExtractRegion();
  1072. });
  1073. $("#dig").click(function() {
  1074. that.handlerExcavation.activate();
  1075. });
  1076. $("#automaticDig").click(function() {
  1077. that.automaticExcavationCalculation(124.3486419476308,43.168731902748924);
  1078. });
  1079. $('#loadingbar').remove();
  1080. }, 1000)
  1081. },
  1082. //自动挖选点
  1083. // automaticExcavation(){
  1084. // this.setIsObtainLaAndLon(true)
  1085. // },
  1086. //自动挖选计算
  1087. automaticExcavationCalculation(longitude, latitude) {
  1088. // 地球半径,单位:米
  1089. const EARTH_RADIUS = 6371000;
  1090. // 将经纬度转换为弧度
  1091. const latRad = latitude * Math.PI / 180;
  1092. const lonRad = longitude * Math.PI / 180;
  1093. // 矩形半边长,单位:米
  1094. const halfSide = 2;
  1095. // 计算经度和纬度的变化量(近似)
  1096. const dLat = halfSide / EARTH_RADIUS;
  1097. const dLon = halfSide / (EARTH_RADIUS * Math.cos(latRad));
  1098. // 将弧度转换回角度
  1099. const dLatDeg = dLat * 180 / Math.PI;
  1100. const dLonDeg = dLon * 180 / Math.PI;
  1101. const points = [
  1102. longitude - dLonDeg,
  1103. latitude + dLatDeg,
  1104. 0,
  1105. longitude + dLonDeg,
  1106. latitude + dLatDeg,
  1107. 0,
  1108. longitude + dLonDeg,
  1109. latitude - dLatDeg,
  1110. 0,
  1111. longitude - dLonDeg,
  1112. latitude - dLatDeg,
  1113. 0
  1114. ]
  1115. // // 计算四个角点的经纬度
  1116. // const points = {
  1117. // // 左上角
  1118. // topLeft: {
  1119. // latitude: latitude + dLatDeg,
  1120. // longitude: longitude - dLonDeg
  1121. // },
  1122. // // 右上角
  1123. // topRight: {
  1124. // latitude: latitude + dLatDeg,
  1125. // longitude: longitude + dLonDeg
  1126. // },
  1127. // // 左下角
  1128. // bottomLeft: {
  1129. // latitude: latitude - dLatDeg,
  1130. // longitude: longitude - dLonDeg
  1131. // },
  1132. // // 右下角
  1133. // bottomRight: {
  1134. // latitude: latitude - dLatDeg,
  1135. // longitude: longitude + dLonDeg
  1136. // }
  1137. // }
  1138. this.extract(points);
  1139. },
  1140. //地形抽出部分
  1141. extract(positions) {
  1142. this.viewer.scene.globe.removeAllExtractRegion();
  1143. this.viewer.scene.globe.addExtractRegion({
  1144. name: 'extract', //名称
  1145. position: positions, //区域
  1146. height: $('#depth').val(), //开挖深度
  1147. transparent: false, //封边是否透明
  1148. extractHeight: Number($('#moveHeight').val()), //抽出高度
  1149. granularity: 1 //精度
  1150. });
  1151. },
  1152. //填开挖分析
  1153. excavationAnalyze(){
  1154. let that = this
  1155. that.showExcavationAnalyze=true
  1156. setTimeout(function() {
  1157. var tooltip = createTooltip(document.body);
  1158. that.handlerExcavationAnalyze = new SuperMap3D.DrawHandler(that.viewer, SuperMap3D.DrawMode.Polygon, that.clampMode);
  1159. that.handlerExcavationAnalyze.activeEvt.addEventListener(function (isActive) {
  1160. if (isActive == true) {
  1161. that.viewer.enableCursorStyle = false;
  1162. that.viewer._element.style.cursor = '';
  1163. $('body').removeClass('drawCur').addClass('drawCur');
  1164. } else {
  1165. that.viewer.enableCursorStyle = true;
  1166. $('body').removeClass('drawCur');
  1167. }
  1168. });
  1169. that.handlerExcavationAnalyze.movingEvt.addEventListener(function (windowPosition) {
  1170. if (that.handlerExcavationAnalyze.isDrawing) {
  1171. tooltip.showAt(windowPosition, '<p>点击确定多边形中间点</p><p>右键单击结束绘制</p>');
  1172. } else {
  1173. tooltip.showAt(windowPosition, '<p>点击绘制第一个点</p>');
  1174. }
  1175. });
  1176. that.handlerExcavationAnalyze.drawEvt.addEventListener(function (result) {
  1177. that.handlerExcavationAnalyze.polygon.show = false;
  1178. // that.handlerExcavationAnalyze.polyline.show = false;
  1179. that.handlerExcavationAnalyze.deactivate();
  1180. tooltip.setVisible(false);
  1181. var dep = document.getElementById("depth").value;
  1182. var array = [].concat(result.object.positions);
  1183. var positions = [];
  1184. var positionsii = [];
  1185. for (var i = 0, len = array.length; i < len; i++) {
  1186. var cartographic = SuperMap3D.Cartographic.fromCartesian(array[i]);
  1187. var longitude = SuperMap3D.Math.toDegrees(cartographic.longitude);
  1188. var latitude = SuperMap3D.Math.toDegrees(cartographic.latitude);
  1189. var h = cartographic.height;
  1190. if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) {
  1191. positions.push(longitude);
  1192. positions.push(latitude);
  1193. positions.push(parseInt(dep));
  1194. positionsii.push({
  1195. x: longitude,
  1196. y: latitude
  1197. });
  1198. }
  1199. }
  1200. //此处用的地形修改 而不是地形开挖
  1201. that.viewer.scene.globe.removeAllModifyRegion();
  1202. that.viewer.scene.globe.addModifyRegion({
  1203. name: 'ggg',
  1204. position: positions
  1205. });
  1206. var length = [];
  1207. length.push(positionsii.length);
  1208. //需要在此 动态构造一个 REGION类型的对象
  1209. var geometry = {
  1210. "id": 23,
  1211. "parts": length,
  1212. "points": positionsii,
  1213. "style": null,
  1214. "type": "REGION"
  1215. };
  1216. var queryObj = {
  1217. "cutFillType": "REGIONANDALTITUDE",
  1218. "baseAltitude": dep,
  1219. "region": geometry,
  1220. "resultDataset": "result",
  1221. "buildPyramid": true,
  1222. "deleteExistResultDataset": true
  1223. };
  1224. var queryObjJSON = JSON.stringify(queryObj);
  1225. $.ajax({
  1226. type: 'post',
  1227. url: "http://www.supermapol.com/realspace/services/spatialAnalysis-dxyx_ios/restjsr/spatialanalyst/datasets/DEM@%E5%9B%9B%E5%A7%91%E5%A8%98%E5%B1%B1/terraincalculation/cutfill.json?returnContent=true",
  1228. data: queryObjJSON,
  1229. success: function (data) {
  1230. console.log(data);
  1231. // var resultObj = JSON.parse(data);
  1232. var resultObj = data;
  1233. document.getElementById("cutarea").value = resultObj.cutArea;
  1234. document.getElementById("cutVolume").value = resultObj.cutVolume;
  1235. document.getElementById("fillarea").value = resultObj.fillArea;
  1236. document.getElementById("fillVolume").value = resultObj.fillVolume;
  1237. document.getElementById("remainderArea").value = resultObj.remainderArea;
  1238. }
  1239. });
  1240. });
  1241. document.getElementById("filladd").onclick = function () {
  1242. that.handlerExcavationAnalyze.activate();
  1243. };
  1244. document.getElementById("fillclear").onclick = function () {
  1245. that.viewer.scene.globe.removeAllModifyRegion();
  1246. document.getElementById("cutarea").value = "";
  1247. document.getElementById("cutVolume").value = "";
  1248. document.getElementById("fillarea").value = "";
  1249. document.getElementById("fillVolume").value = "";
  1250. document.getElementById("remainderArea").value = "";
  1251. that.handlerExcavationAnalyze.clear();
  1252. };
  1253. $('#excavationAnalyze').show();
  1254. $('#loadingbar').remove();
  1255. if (!that.viewer.scene.pickPositionSupported) {
  1256. alert('不支持深度拾取,无法进行鼠标交互绘制!');
  1257. }
  1258. }, 1000)
  1259. },
  1260. //选择、框选
  1261. boxSelection(){
  1262. let that=this;
  1263. let layersAll = [];
  1264. that.checkedCities.forEach(url => {
  1265. if (!url) return; // 如果没有 URL,跳过当前迭代
  1266. SuperMap3D.when.all(that.selectMapObj(url), function (layers) {
  1267. layersAll.push(layers)
  1268. });
  1269. });
  1270. if (layersAll.length === 0) {
  1271. return
  1272. }
  1273. that.showSoxSelection= true
  1274. /**
  1275. * @param dom ScreenSpaceEventHandler操作的dom节点,画的框会成为其子节点
  1276. */
  1277. function DrawRectHandler(dom) {
  1278. let startPoint,
  1279. self = this,
  1280. isShiftAndLeftDown = false,
  1281. removalFunctions = [],
  1282. rect = new Rect(dom)
  1283. that.handlerBoxSelection = new SuperMap3D.ScreenSpaceEventHandler(dom)
  1284. this.isDestroyed = false
  1285. this.activeEvt = new SuperMap3D.Event()
  1286. this.cancelEvt = new SuperMap3D.Event()
  1287. this.movingEvt = new SuperMap3D.Event()
  1288. this.drawEvt = new SuperMap3D.Event()
  1289. // div框
  1290. function Rect(parentDom) {
  1291. this.rect = document.createElement('div')
  1292. this.rect.style.visibility = 'hidden'
  1293. parentDom.appendChild(this.rect)
  1294. this.leftTopPoint = new SuperMap3D.Cartesian2()
  1295. this.rightBottomPoint = new SuperMap3D.Cartesian2()
  1296. Rect.prototype.setPosition = function (startPoint, endPosition) {
  1297. let w = endPosition.x - startPoint.x
  1298. let h = endPosition.y - startPoint.y
  1299. let left, top, width, height
  1300. if (w < 0) {
  1301. left = endPosition.x
  1302. width = -w
  1303. } else {
  1304. left = startPoint.x
  1305. width = w
  1306. }
  1307. if (h < 0) {
  1308. top = endPosition.y
  1309. height = -h
  1310. } else {
  1311. top = startPoint.y
  1312. height = h
  1313. }
  1314. this.leftTopPoint = new SuperMap3D.Cartesian2(left, top)
  1315. this.rightBottomPoint = new SuperMap3D.Cartesian2(left + width, top + height)
  1316. this.rect.style = `position:fixed;top:${top}px;left:${left}px;width:${width}px;height:${height}px;border:2px dashed #333;`
  1317. this.setVisible(true)
  1318. }
  1319. Rect.prototype.setVisible = function (isVisible) {
  1320. this.rect.style.visibility = isVisible ? 'visible' : 'hidden'
  1321. }
  1322. Rect.prototype.getRectPoint = function () {
  1323. return {
  1324. leftTopPoint: this.leftTopPoint,
  1325. rightBottomPoint: this.rightBottomPoint
  1326. }
  1327. }
  1328. Rect.prototype.destroy = function () {
  1329. dom.removeChild(rect)
  1330. this.rect = null
  1331. }
  1332. }
  1333. // canvas框
  1334. function RectCanvas(parentDom) {
  1335. let canvas = document.createElement('canvas'),
  1336. ctx = canvas.getContext('2d')
  1337. this.canvas = canvas
  1338. canvas.width = parentDom.clientWidth
  1339. canvas.height = parentDom.clientHeight
  1340. canvas.style = 'position:fixed;top:0;left:0;z-index:-1'
  1341. parentDom.appendChild(canvas)
  1342. this.leftTopPoint = new SuperMap3D.Cartesian2()
  1343. this.rightBottomPoint = new SuperMap3D.Cartesian2()
  1344. RectCanvas.prototype.setPosition = function (startPoint, endPosition) {
  1345. let w = endPosition.x - startPoint.x
  1346. let h = endPosition.y - startPoint.y
  1347. let left, top, width, height
  1348. if (w < 0) {
  1349. left = endPosition.x
  1350. width = -w
  1351. } else {
  1352. left = startPoint.x
  1353. width = w
  1354. }
  1355. if (h < 0) {
  1356. top = endPosition.y
  1357. height = -h
  1358. } else {
  1359. top = startPoint.y
  1360. height = h
  1361. }
  1362. this.leftTopPoint = new SuperMap3D.Cartesian2(left, top)
  1363. this.rightBottomPoint = new SuperMap3D.Cartesian2(left + width, top + height)
  1364. ctx.clearRect(0, 0, canvas.width, canvas.height)
  1365. ctx.strokeRect(left, top, width, height)
  1366. }
  1367. RectCanvas.prototype.setVisible = function (isVisible) {
  1368. if (isVisible) {
  1369. canvas.style.zIndex = '999'
  1370. } else {
  1371. canvas.style.zIndex = '-1'
  1372. }
  1373. }
  1374. RectCanvas.prototype.getRectPoint = function () {
  1375. return {
  1376. leftTopPoint: this.leftTopPoint,
  1377. rightBottomPoint: this.rightBottomPoint
  1378. }
  1379. }
  1380. RectCanvas.prototype.destroy = function () {
  1381. dom.removeChild(canvas)
  1382. ctx = null
  1383. this.canvas = null
  1384. }
  1385. }
  1386. // 开关相机控制
  1387. function setCameraCtrl(isActive) {
  1388. let cameraCtrl = that.scene.screenSpaceCameraController
  1389. cameraCtrl.enableRotate = isActive
  1390. cameraCtrl.enableTranslate = isActive
  1391. cameraCtrl.enableZoom = isActive
  1392. cameraCtrl.enableTilt = isActive
  1393. cameraCtrl.enableLook = isActive
  1394. }
  1395. // 鼠标cursor控制
  1396. function toggleCursorStyle(isActive) {
  1397. if (isActive) {
  1398. that.viewer.enableCursorStyle = false
  1399. that.viewer._element.style.cursor = ''
  1400. dom.style.cursor = 'default'
  1401. } else {
  1402. that.viewer.enableCursorStyle = true
  1403. }
  1404. }
  1405. // 初始化事件处理
  1406. function initEvent() {
  1407. that.handlerBoxSelection.setInputAction(function (e) {
  1408. isShiftAndLeftDown = true
  1409. startPoint = new SuperMap3D.Cartesian2(e.position.x, e.position.y)
  1410. }, SuperMap3D.ScreenSpaceEventType.LEFT_DOWN, SuperMap3D.KeyboardEventModifier.SHIFT)
  1411. // shift松开时,始终将rect隐藏
  1412. let keyUpFunction = function (e) {
  1413. self.cancelEvt.raiseEvent()
  1414. if (e.key == 'Shift' && isShiftAndLeftDown && !self.isDestroyed) {
  1415. isShiftAndLeftDown = false
  1416. rect.setVisible(false)
  1417. }
  1418. }
  1419. document.addEventListener('keyup', keyUpFunction)
  1420. removalFunctions.push(function () {
  1421. document.removeEventListener('keyup', keyUpFunction)
  1422. })
  1423. that.handlerBoxSelection.setInputAction(function (e) {
  1424. let endPosition = e.endPosition
  1425. self.activeEvt.raiseEvent(endPosition)
  1426. if (!isShiftAndLeftDown) return
  1427. rect.setPosition(startPoint, endPosition)
  1428. rect.setVisible(true)
  1429. self.movingEvt.raiseEvent(rect.getRectPoint())
  1430. }, SuperMap3D.ScreenSpaceEventType.MOUSE_MOVE, SuperMap3D.KeyboardEventModifier.SHIFT)
  1431. that.handlerBoxSelection.setInputAction(function (e) {
  1432. isShiftAndLeftDown = false
  1433. rect.setVisible(false)
  1434. self.drawEvt.raiseEvent(rect.getRectPoint())
  1435. }, SuperMap3D.ScreenSpaceEventType.LEFT_UP, SuperMap3D.KeyboardEventModifier.SHIFT)
  1436. that.handlerBoxSelection.setInputAction(function (e) {
  1437. isShiftAndLeftDown = false
  1438. rect.setVisible(false)
  1439. }, SuperMap3D.ScreenSpaceEventType.LEFT_UP)
  1440. }
  1441. // 移除事件监听
  1442. function removeEvent() {
  1443. that.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_DOWN, SuperMap3D.KeyboardEventModifier.SHIFT)
  1444. that.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.MOUSE_MOVE, SuperMap3D.KeyboardEventModifier.SHIFT)
  1445. that.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_UP, SuperMap3D.KeyboardEventModifier.SHIFT)
  1446. that.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_UP)
  1447. }
  1448. DrawRectHandler.prototype.destroy = function () {
  1449. if (this.isDestroyed) return
  1450. setCameraCtrl(true)
  1451. removeEvent()
  1452. for (let i = 0, j = removalFunctions.length; i < j; i++) {
  1453. removalFunctions[i]()
  1454. }
  1455. that.handlerBoxSelection.destroy()
  1456. rect.destroy()
  1457. rect = null
  1458. this.isDestroyed = true
  1459. }
  1460. DrawRectHandler.prototype.activate = function () {
  1461. if (this.isDestroyed) return
  1462. setCameraCtrl(false)
  1463. toggleCursorStyle(true)
  1464. initEvent()
  1465. }
  1466. DrawRectHandler.prototype.deactivate = function () {
  1467. if (this.isDestroyed) return
  1468. setCameraCtrl(true)
  1469. toggleCursorStyle(false)
  1470. that.boxSelectionTooltip.setVisible(false)
  1471. removeEvent()
  1472. }
  1473. }
  1474. // div框
  1475. function Rect(parentDom) {
  1476. this.rect = document.createElement('div')
  1477. this.rect.style.visibility = 'hidden'
  1478. parentDom.appendChild(this.rect)
  1479. this.leftTopPoint = new SuperMap3D.Cartesian2()
  1480. this.rightBottomPoint = new SuperMap3D.Cartesian2()
  1481. Rect.prototype.setPosition = function (startPoint, endPosition) {
  1482. let w = endPosition.x - startPoint.x
  1483. let h = endPosition.y - startPoint.y
  1484. let left, top, width, height
  1485. if (w < 0) {
  1486. left = endPosition.x
  1487. width = -w
  1488. } else {
  1489. left = startPoint.x
  1490. width = w
  1491. }
  1492. if (h < 0) {
  1493. top = endPosition.y
  1494. height = -h
  1495. } else {
  1496. top = startPoint.y
  1497. height = h
  1498. }
  1499. this.leftTopPoint = new SuperMap3D.Cartesian2(left, top)
  1500. this.rightBottomPoint = new SuperMap3D.Cartesian2(left + width, top + height)
  1501. this.rect.style = `position:fixed;top:${top}px;left:${left}px;width:${width}px;height:${height}px;border:2px dashed #333;`
  1502. this.setVisible(true)
  1503. }
  1504. Rect.prototype.setVisible = function (isVisible) {
  1505. this.rect.style.visibility = isVisible ? 'visible' : 'hidden'
  1506. }
  1507. Rect.prototype.getRectPoint = function () {
  1508. return {
  1509. leftTopPoint: this.leftTopPoint,
  1510. rightBottomPoint: this.rightBottomPoint
  1511. }
  1512. }
  1513. Rect.prototype.destroy = function () {
  1514. dom.removeChild(rect)
  1515. this.rect = null
  1516. }
  1517. }
  1518. setTimeout(function() {
  1519. that.boxSelectionTooltip = createTooltip(document.body);
  1520. $('#loadingbar').remove();
  1521. for (let layers of layersAll) {
  1522. for (let layer of layers) {
  1523. layer.selectColorType = 1;
  1524. that.boxSelectionObjects.selectedObjs[layer.name] = [];
  1525. }
  1526. }
  1527. let drawRect = new DrawRectHandler(document.body);
  1528. drawRect.drawEvt.addEventListener(function (res) {
  1529. that.boxSelectionTooltip.setVisible(false);
  1530. let selectedColor = new SuperMap3D.Color(1, 0, 0, 1);
  1531. that.scene.pickRect(res.leftTopPoint, res.rightBottomPoint);
  1532. that.scene.getPickRectIDsAsync().then(objs=>{
  1533. let selectedObjs = that.boxSelectionObjects.selectedObjs;
  1534. for (let k in selectedObjs) {
  1535. if (selectedObjs[k] !== undefined && selectedObjs[k] !== null && selectedObjs[k].length>0) {
  1536. that.scene.layers.find(k).removeObjsColor(selectedObjs[k]);
  1537. }
  1538. }
  1539. for (let layers of layersAll) {
  1540. for (let layer of layers) {
  1541. let layerName = layer.name;
  1542. let layerSlt = objs.find(e => e.layerName === layerName);
  1543. let sltIds = (layerSlt && layerSlt.ids) || [];
  1544. let lastIds = selectedObjs[layerName];
  1545. switch (that.boxSelectionObjects.mode) {
  1546. case 1:
  1547. selectedObjs[layerName] = sltIds;
  1548. break;
  1549. case 2:
  1550. selectedObjs[layerName] = _.union(lastIds, sltIds);;
  1551. break;
  1552. case 4:
  1553. selectedObjs[layerName] = _.intersection(lastIds, sltIds);
  1554. break;
  1555. case 8:
  1556. selectedObjs[layerName] = _.difference(lastIds, sltIds);
  1557. break;
  1558. default:
  1559. break;
  1560. }
  1561. layer.setObjsColor(selectedObjs[layerName], selectedColor);
  1562. }
  1563. }
  1564. console.log('选择的数据:'+JSON.stringify(selectedObjs))
  1565. });
  1566. });
  1567. drawRect.movingEvt.addEventListener(function (res) {
  1568. that.boxSelectionTooltip.showAt(res.rightBottomPoint,
  1569. '<p>松开鼠标左键以结束选择区域</p>'
  1570. );
  1571. if (that.boxSelectionObjects.isCallInMoving) {
  1572. for (let layer of layersAll) {
  1573. layer.selectColorType = 1;
  1574. }
  1575. that.scene.pickRect(res.leftTopPoint, res.rightBottomPoint);
  1576. }
  1577. });
  1578. drawRect.activeEvt.addEventListener(function (position) {
  1579. that.boxSelectionTooltip.showAt(position,
  1580. '<p>点击鼠标左键以开始选择区域</p>'
  1581. );
  1582. });
  1583. // $(document).keydown(function (e) {
  1584. // if (e.key === 'Shift') {
  1585. // drawRect.activate();
  1586. // }
  1587. // })
  1588. $(document).keyup(function (e) {
  1589. if (e.key === 'Shift') {
  1590. drawRect.deactivate();
  1591. }
  1592. })
  1593. $("#isCallInMoving").on("input change", function () {
  1594. that.boxSelectionObjects.isCallInMoving = that.checked;
  1595. });
  1596. $("#isSelection").click(function() {
  1597. drawRect.activate();
  1598. });
  1599. $("#mode").change(function (e) {
  1600. let mode = $("#mode").val();
  1601. that.boxSelectionObjects.mode = parseInt(mode);
  1602. });
  1603. }, 1000)
  1604. },
  1605. //清除框选
  1606. removeBoxSelection(){
  1607. this.showSoxSelection= false
  1608. let selectedObjs = this.boxSelectionObjects.selectedObjs;
  1609. for (let k in selectedObjs) {
  1610. if (selectedObjs[k] !== undefined && selectedObjs[k] !== null && selectedObjs[k].length>0) {
  1611. this.scene.layers.find(k).removeObjsColor(selectedObjs[k]);
  1612. }
  1613. }
  1614. if(this.boxSelectionTooltip){
  1615. this.boxSelectionTooltip.setVisible(false);
  1616. }
  1617. if(this.handlerBoxSelection){
  1618. this.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_DOWN, SuperMap3D.KeyboardEventModifier.SHIFT)
  1619. this.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.MOUSE_MOVE, SuperMap3D.KeyboardEventModifier.SHIFT)
  1620. this.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_UP, SuperMap3D.KeyboardEventModifier.SHIFT)
  1621. this.handlerBoxSelection.removeInputAction(SuperMap3D.ScreenSpaceEventType.LEFT_UP)
  1622. }
  1623. },
  1624. /**
  1625. * 切换地图
  1626. */
  1627. queryVectorTilesMapList(deptId) {
  1628. queryMap(deptId).then(req => { // from forestry_develop_2.0
  1629. //切换地图
  1630. req = req.sort(function(a, b) {
  1631. return a.sort - b.sort
  1632. })
  1633. this.queryList = req
  1634. this.onload(req)
  1635. })
  1636. },
  1637. //清除所有
  1638. clearAll() {
  1639. this.viewer.entities.removeAll()
  1640. this.viewer.scene.scanEffect.show = false
  1641. },
  1642. //移除之前添加的点
  1643. clearMRadius() {
  1644. if (this.markerboxEntityRadius != null && this.markerboxEntityRadius.length > 0) {
  1645. for (let i = 0; i < this.markerboxEntityRadius.length; i++) {
  1646. this.viewer.entities.remove(this.markerboxEntityRadius[i])
  1647. }
  1648. this.markerboxEntityRadius = []
  1649. }
  1650. },
  1651. //移除之前添加的线
  1652. clearTwoC() {
  1653. if (this.connectBoxEntityTwo != null) {
  1654. this.viewer.entities.remove(this.connectBoxEntityTwo)
  1655. this.connectBoxEntityTwo = null
  1656. }
  1657. },
  1658. /**
  1659. * 地图落点-覆盖范围
  1660. */
  1661. setMarkersRadius(makerList) {
  1662. let that = this
  1663. for (let i = 0; i < makerList.length; i++) {
  1664. let longitude = makerList[i].lng*1;
  1665. let latitude = makerList[i].lat*1;
  1666. let radius = makerList[i].radius*1;
  1667. let marker = that.viewer.entities.add({
  1668. name: "",
  1669. position: new SuperMap3D.Cartesian3.fromDegrees(longitude, latitude),
  1670. billboard: {
  1671. image: iconList[makerList[i].icon],
  1672. width: 48,
  1673. height: 48,
  1674. heightReference: SuperMap3D.HeightReference.CLAMP_TO_GROUND,
  1675. disableDepthTestDistance: Number.POSITIVE_INFINITY
  1676. },
  1677. description: makerList[i].bindPopupHtml,
  1678. click: makerList[i].click,
  1679. parameter: makerList[i].parameter
  1680. })
  1681. that.markerboxEntityRadius.push(marker)
  1682. //绘制摄像头的圈(覆盖范围)
  1683. // if(radius!=0){
  1684. // const markerRadius = that.viewer.entities.add({
  1685. // position: new SuperMap3D.Cartesian3.fromDegrees(longitude, latitude),
  1686. // ellipse: {
  1687. // semiMinorAxis: radius,
  1688. // semiMajorAxis: radius,
  1689. // material: SuperMap3D.Color.DODGERBLUE.withAlpha(0.4),
  1690. // outline: true, //是否显示边框
  1691. // outlineColor: SuperMap3D.Color.BLUE, //边框颜色
  1692. // outlineWidth: 1,
  1693. // heightReference: SuperMap3D.HeightReference.NONE
  1694. // },
  1695. // });
  1696. // that.markerboxEntityRadius.push(markerRadius)
  1697. // }
  1698. }
  1699. // that.createLeftClickDescription()
  1700. that.createRightClickDescription()
  1701. },
  1702. /**
  1703. * 地图画线(贴地)
  1704. */
  1705. setConnectTwoList(connectList, color, withAlpha) {
  1706. let that = this
  1707. //SuperMap3D.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  1708. let material = SuperMap3D.Color.fromCssColorString(color).withAlpha(withAlpha)
  1709. that.connectBoxEntityTwo = that.viewer.entities.add({
  1710. Type: 'Polyline',
  1711. polyline: {
  1712. positions: new SuperMap3D.Cartesian3.fromDegreesArray(connectList),
  1713. clampToGround: true, //贴地 true,不贴地 false
  1714. width: 5,
  1715. material: material
  1716. }
  1717. })
  1718. },
  1719. //移除之前添加的点
  1720. clearM() {
  1721. if (this.markerboxEntity != null && this.markerboxEntity.length > 0) {
  1722. for (let i = 0; i < this.markerboxEntity.length; i++) {
  1723. this.viewer.entities.remove(this.markerboxEntity[i])
  1724. }
  1725. this.markerboxEntity = []
  1726. }
  1727. },
  1728. //移除之前添加的线
  1729. clearC() {
  1730. if (this.connectBoxEntity != null) {
  1731. this.viewer.entities.remove(this.connectBoxEntity)
  1732. this.connectBoxEntity = null
  1733. }
  1734. },
  1735. //移除之前添加的面
  1736. clearG() {
  1737. if (this.graphicsBoxEntity != null) {
  1738. this.viewer.entities.remove(this.graphicsBoxEntity)
  1739. this.graphicsBoxEntity = null
  1740. }
  1741. },
  1742. //移除之前添加的面
  1743. clearGList() {
  1744. for (let i = 0; i < this.graphicsBoxEntityList.length; i++) {
  1745. this.viewer.entities.remove(this.graphicsBoxEntityList[i])
  1746. }
  1747. this.graphicsBoxEntityList = []
  1748. },
  1749. lonAndLatPlacement(lon, lat) {
  1750. let that = this
  1751. if (that.positioningEntity != null) {
  1752. this.viewer.entities.remove(that.positioningEntity)
  1753. }
  1754. that.positioningEntity = that.viewer.entities.add({
  1755. name: "",
  1756. position: new SuperMap3D.Cartesian3.fromDegrees(lon, lat),
  1757. billboard: {
  1758. image: iconList['positioning'],
  1759. width: 48,
  1760. height: 48,
  1761. heightReference: SuperMap3D.HeightReference.CLAMP_TO_GROUND,
  1762. disableDepthTestDistance: Number.POSITIVE_INFINITY
  1763. }
  1764. })
  1765. },
  1766. setIsObtainLaAndLon(isObtainLaAndLon) {
  1767. this.isObtainLaAndLon = isObtainLaAndLon
  1768. },
  1769. clearDW() {
  1770. if (this.positioningEntity != null) {
  1771. this.viewer.entities.remove(this.positioningEntity);
  1772. }
  1773. },
  1774. flyTo(longitude, latitude, height) {
  1775. let that = this
  1776. setTimeout(function() {
  1777. that.viewer.camera.setView({
  1778. destination: new SuperMap3D.Cartesian3.fromDegrees(Number(longitude)-Number(0.115), Number(latitude)-Number(0.27), Number(6000)),
  1779. orientation: {
  1780. heading: SuperMap3D.Math.toRadians(0),
  1781. pitch: SuperMap3D.Math.toRadians(-45),
  1782. roll: 0
  1783. }
  1784. })
  1785. }, 3000)
  1786. },
  1787. openTvwall() {
  1788. this.mapshow = false
  1789. if (this.openZt) {
  1790. this.$emit('fatherMethod', this.dianshiqiang, this.longitude, this.latitude, this.userList)
  1791. } else {
  1792. this.$emit(this._click, this._parameter)
  1793. }
  1794. },
  1795. /**
  1796. * 地图落点
  1797. */
  1798. setMarkers(makerList) {
  1799. let that = this
  1800. clearInterval(that.aac)
  1801. for (let i in makerList) {
  1802. let longitude = makerList[i].lng
  1803. let latitude = makerList[i].lat
  1804. let marker = that.viewer.entities.add({
  1805. name: '',
  1806. position: new SuperMap3D.Cartesian3.fromDegrees(Number(longitude), Number(latitude)),
  1807. billboard: {
  1808. image: iconList[makerList[i].icon],
  1809. width: 48,
  1810. height: 48,
  1811. heightReference: SuperMap3D.HeightReference.CLAMP_TO_GROUND,
  1812. disableDepthTestDistance: Number.POSITIVE_INFINITY
  1813. },
  1814. description: makerList[i].bindPopupHtml,
  1815. click: makerList[i].click,
  1816. parameter: makerList[i].parameter
  1817. })
  1818. that.markerboxEntity.push(marker)
  1819. }
  1820. that.viewer.scene.globe.depthTestAgainstTerrain = false
  1821. // that.createLeftClickDescription()
  1822. that.createRightClickDescription()
  1823. },
  1824. /**
  1825. *鼠标左击事件是原来的气泡
  1826. */
  1827. createLeftClickDescription() {
  1828. let that = this
  1829. that.handler.setInputAction(function(movement) {
  1830. that.pick = that.viewer.scene.pick(movement.position)
  1831. if (that.pick && that.pick) {
  1832. let id = SuperMap3D.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(
  1833. movement.position).primitive.id)
  1834. let html = id._description
  1835. if (html != undefined && html._value != null && html._value != '') {
  1836. that.bindPopupHtml = html
  1837. that.mapshow = true
  1838. that.openZt = false
  1839. that._click = id._click
  1840. that._parameter = id._parameter
  1841. } else {
  1842. that.mapshow = false
  1843. }
  1844. } else {
  1845. that.mapshow = false
  1846. }
  1847. }, SuperMap3D.ScreenSpaceEventType.LEFT_CLICK)
  1848. },
  1849. /**
  1850. *鼠标右击事件是原来的点击
  1851. */
  1852. createRightClickDescription() {
  1853. let that = this
  1854. that.handler.setInputAction(function(movement) {
  1855. that.mapshow = false
  1856. if (new Date().getTime() - that.clickTime < 2000) {
  1857. return
  1858. } else {
  1859. that.clickTime = new Date().getTime()
  1860. }
  1861. // 监听鼠标的当前位置坐标,然后根据当前坐标去动态更新气泡窗口div的显示位置;
  1862. that.pick = that.viewer.scene.pick(movement.position)
  1863. if (that.pick && that.pick) {
  1864. let id = SuperMap3D.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(
  1865. movement.position).primitive.id)
  1866. let clickName = id._click
  1867. that.$emit(clickName, id._parameter)
  1868. }
  1869. }, SuperMap3D.ScreenSpaceEventType.LEFT_CLICK)
  1870. },
  1871. /**
  1872. * 落点定位
  1873. */
  1874. /**
  1875. * 落点定位
  1876. */
  1877. dropLocation(lat, lng, index,radius) {
  1878. this.viewer.scene.globe.depthTestAgainstTerrain = true;
  1879. this.viewer.camera.flyTo({
  1880. destination: new SuperMap3D.Cartesian3.fromDegrees(Number(lng), Number(lat)-Number(0.003), Number(500)),
  1881. orientation: {
  1882. heading: SuperMap3D.Math.toRadians(0),
  1883. pitch: SuperMap3D.Math.toRadians(-45),
  1884. roll: 0
  1885. }
  1886. })
  1887. if (radius != undefined && radius != null) {
  1888. let that = this
  1889. // 初始化颜色选择控件
  1890. var initialScanColor = '#2263e6'
  1891. that.viewer.scene.scanEffect.color = SuperMap3D.Color.fromCssColorString(initialScanColor)
  1892. // 获取或设置扫描线的运行周期,单位:秒。
  1893. that.viewer.scene.scanEffect.period = radius / 500
  1894. // 获取或设置扫描线的运行速度,单位:米/秒。
  1895. that.viewer.scene.scanEffect.speed = 500
  1896. that.viewer.scene.scanEffect.mode = SuperMap3D.ScanEffectMode.CIRCLE
  1897. that.viewer.scene.scanEffect.centerPostion = new SuperMap3D.Cartesian3.fromDegrees(lng, lat, 3000)
  1898. that.viewer.scene.scanEffect.show = true
  1899. }
  1900. },
  1901. /**
  1902. * 地图画线(贴地)
  1903. */
  1904. setConnectList(connectList, color, withAlpha) {
  1905. let that = this
  1906. //SuperMap3D.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  1907. let material = SuperMap3D.Color.fromCssColorString(color).withAlpha(withAlpha)
  1908. that.connectBoxEntity = that.viewer.entities.add({
  1909. Type: 'Polyline',
  1910. polyline: {
  1911. positions: new SuperMap3D.Cartesian3.fromDegreesArray(connectList),
  1912. clampToGround: true, //贴地 true,不贴地 false
  1913. width: 5,
  1914. material: material
  1915. }
  1916. })
  1917. },
  1918. /**
  1919. * 地图图形(贴地)
  1920. */
  1921. setGraphicsList(graphicsList, color, withAlpha) {
  1922. let that = this
  1923. //SuperMap3D.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  1924. let material = SuperMap3D.Color.fromCssColorString(color).withAlpha(withAlpha)
  1925. that.graphicsBoxEntity = that.viewer.entities.add({
  1926. polygon: {
  1927. hierarchy: new SuperMap3D.Cartesian3.fromDegreesArray(graphicsList),
  1928. clampToGround: true, //贴地 true,不贴地 false
  1929. width: 5,
  1930. material: material
  1931. }
  1932. })
  1933. },
  1934. // 批量画面
  1935. setGraphicsLists(graphicsList, color, withAlpha) {
  1936. let that = this
  1937. let material = SuperMap3D.Color.fromCssColorString(color).withAlpha(withAlpha)
  1938. for (let i = 0; i < graphicsList.length; i++) {
  1939. let positions = new SuperMap3D.Cartesian3.fromDegreesArray(graphicsList[i].latLng)
  1940. let name = graphicsList[i].name.toString()
  1941. let center = SuperMap3D.BoundingSphere.fromPoints(positions).center
  1942. let namePosition = SuperMap3D.Cartographic.fromCartesian(center)
  1943. namePosition.height = 0 // 将名称高度设置为0,使其贴地显示
  1944. that.graphicsBoxEntityList.push(that.viewer.entities.add({
  1945. polygon: {
  1946. hierarchy: positions,
  1947. clampToGround: true,
  1948. width: 5,
  1949. material: material
  1950. },
  1951. position: center,
  1952. label: {
  1953. text: name,
  1954. font: 'Bold 12px sans-serif',
  1955. fillColor: SuperMap3D.Color.BLACK,
  1956. outlineColor: SuperMap3D.Color.WHITE,
  1957. outlineWidth: 2,
  1958. pixelOffset: new SuperMap3D.Cartesian2(0, 0),
  1959. heightReference: SuperMap3D.HeightReference.CLAMP_TO_GROUND,
  1960. disableDepthTestDistance: Number.POSITIVE_INFINITY
  1961. }
  1962. }))
  1963. }
  1964. }
  1965. }
  1966. }
  1967. </script>
  1968. <style rel="stylesheet/scss" lang="scss" scoped>
  1969. .map-tit {
  1970. position: absolute;
  1971. top: 90px;
  1972. left: 50%;
  1973. transform: translatex(-50%);
  1974. border: 1px solid #15519b;
  1975. z-index: 9999;
  1976. background: linear-gradient(rgba(4, 23, 62, 0.6), rgba(0, 28, 70, 0.6));
  1977. min-width: 300px;
  1978. .sj-icon-btn {
  1979. display: block;
  1980. margin: 10px auto 15px auto;
  1981. padding: 0px 16px;
  1982. font-size: 10px;
  1983. height: 1.7rem;
  1984. }
  1985. .top-tit {
  1986. width: 100%;
  1987. height: 28px;
  1988. line-height: 28px;
  1989. display: flex;
  1990. flex-direction: row;
  1991. justify-content: space-between;
  1992. background: #15519b80;
  1993. padding: 0px 10px;
  1994. align-items: center;
  1995. i {
  1996. color: #10ccff;
  1997. font-size: 18px;
  1998. text-shadow: 0px 0px 5px #23b3b3;;
  1999. }
  2000. span img {
  2001. display: block;
  2002. width: 12px;
  2003. height: 12px;
  2004. color: #fff;
  2005. cursor: pointer;
  2006. }
  2007. }
  2008. .map-txt {
  2009. padding: 10px 15px;
  2010. color: #fff;
  2011. line-height: 20px;
  2012. font-size: 12px;
  2013. .d-l-con {
  2014. }
  2015. }
  2016. }
  2017. .fade-enter-active,
  2018. .fade-leave-active {
  2019. transition: 1s;
  2020. }
  2021. .fade-enter,
  2022. .fade-leave-to {
  2023. opacity: 0;
  2024. transform: translateY(-10rem);
  2025. }
  2026. </style>