supermap.vue 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. <template>
  2. <div v-bind:id="mapDivId" ref="map" style="width: 100%; height: 100%;background: none;">
  3. <transition-group
  4. appear
  5. name="animate__animated animate__bounce"
  6. enter-active-class="animate__backInLeft"
  7. leave-active-class="animate__backOutLeft"
  8. >
  9. <div id="toolbar" v-if="isdynamicPlotting" class="panel panel-primary" v-show="mapToolShowBH" key="mapFlash"
  10. style="position:absolute;z-index: 9999;top:4rem;left: 1rem; border-radius: 4px; width: fit-content;height:635px;overflow-y:scroll;background:#040b1f" data-html2canvas-ignore>
  11. <div class="panel-heading" id="panelheading">
  12. <h5 style=" color: #2bacf7;font-size: 1rem;padding:.5rem;">鼠标标绘</h5>
  13. </div>
  14. <div class="panel-body content" id="panelbodycontent" style="margin-bottom: .5rem;padding-right: .5rem;">
  15. <div align="right" class="button-group">
  16. <el-button type="success" @click="PlottingDrawCancel">取消标绘</el-button>
  17. &nbsp;&nbsp;
  18. <el-button type="success" @click="clearLayers">清空标绘</el-button>
  19. </div>
  20. </div>
  21. <div id="plottingPanel">
  22. <div id="plotPanel" style="width: 15rem;height:50%;overflow-y:scroll;">
  23. </div>
  24. </div>
  25. </div>
  26. </transition-group>
  27. <div id="toolbar-heat" v-if="isheatPlotting" class="panel panel-primary"
  28. style="position:absolute;z-index: 9999; padding: 1rem; bottom:3rem;right: 1rem; border-radius: 4px; width: fit-content;height:fit-content;overflow-y:scroll;background:#040b1f">
  29. <div class="panel-body content">
  30. <div class="panel">
  31. <div class="input-group">
  32. <span class="input-group-addon">风向</span>
  33. <select class="form-control" style="width:auto" id="heatNums">
  34. <option value="1">南风</option>
  35. <option value="31">西南风</option>
  36. <option value="41">东南风</option>
  37. <option value="2">北风</option>
  38. <option value="32">西北风</option>
  39. <option value="42">东北风</option>
  40. <option value="3">西风</option>
  41. <option value="4">东风</option>
  42. </select>
  43. </div>
  44. </div>
  45. <div class="panel">
  46. <div class="input-group">
  47. <span class="input-group-addon">风速</span>
  48. <input type="text" class="form-control" id="heatNums1" value="6"/>
  49. </div>
  50. </div>
  51. <div class="panel">
  52. <div class="input-group">
  53. <span class="input-group-addon">温度</span>
  54. <input type="text" class="form-control" id="heatNums2" value="10℃"/>
  55. </div>
  56. </div>
  57. <div class="panel">
  58. <div class="input-group">
  59. <span class="input-group-addon">湿度</span>
  60. <input type="text" class="form-control" id="heatNums3" value="6%RH"/>
  61. </div>
  62. </div>
  63. <div class="panel">
  64. <div class="input-group">
  65. <span class="input-group-addon">持续时间</span>
  66. <input type="text" class="form-control" id="heatNums4" value="60分钟"/>
  67. </div>
  68. </div>
  69. <div class="panel">
  70. <div class="input-group">
  71. <span class="input-group-addon">植被类型</span>
  72. <select class="form-control" style="width:auto" id="heatNums5">
  73. <option value="1">针叶林</option>
  74. <option value="31">落叶林</option>
  75. </select>
  76. </div>
  77. </div>
  78. <div class="panel">
  79. <div class="input-group">
  80. <span class="input-group-addon">大气压</span>
  81. <input type="text" class="form-control" id="heatNums6" value="101.325kPa"/>
  82. </div>
  83. </div>
  84. <div class="panel">
  85. <el-button type="success" @click="createHeatPoints">分析</el-button>
  86. <el-button type="success" @click="clearHeatPoints">重置</el-button>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. // import 'leaflet-side-by-side'
  94. // import '@supermap/iclient-leaflet'
  95. // import 'leaflet/dist/leaflet.css'
  96. // import 'leaflet.markercluster/dist/leaflet.markercluster-src.js'
  97. // import 'leaflet.markercluster/dist/MarkerCluster.css'
  98. // import 'leaflet.markercluster/dist/MarkerCluster.Default.css'
  99. // import 'leaflet-draw'
  100. // import 'leaflet-draw/dist/leaflet.draw.css'
  101. // import L from 'leaflet'
  102. import {
  103. getSuperMap,
  104. iconList
  105. } from '@/api/components/supermap.js'
  106. import { selectConfigKey } from "@/api/system/config";
  107. // import {setToken} from '../plugins/auth'
  108. import modal from '@/plugins/modal'
  109. export default {
  110. name: 'sookaSuperMap',
  111. data() {
  112. return {
  113. windDirection:'',
  114. windSpeed:null,
  115. plottingdrawControl: null,
  116. plottingLayer: null,
  117. mapDivId: '',
  118. map: null,
  119. layers: [],
  120. layersBytype: [],
  121. isAggregationLayers: [],
  122. radiusLayers: [],
  123. myGroup: [],
  124. myGroupBytype: [],
  125. isAggregationMyGroup: [],
  126. polygon: null,
  127. connectLayer: [],
  128. connectLayerTwo: [],
  129. graphicsLayer: [],
  130. latLngLayers: [],
  131. latLngGroup: [],
  132. isEditableLayers: false, //绘图控件
  133. drawControl: null, //绘图控件
  134. deckglLayer: null, //图层Layer
  135. deckglLayerList: [], //图层Layer(数组)
  136. heatMapLayer: [], //火灾蔓延图层Layer
  137. isheatPlotting: false,//火灾蔓延
  138. heat_lat: 0, //火灾蔓延经纬度
  139. heat_lng: 0, //火灾蔓延经纬度
  140. aac:null,
  141. host:''
  142. }
  143. },
  144. watch: {
  145. isEditableLayers: {
  146. handler(newValue, oldValue) {
  147. if (newValue) {
  148. var editableLayers = new window.L.FeatureGroup()
  149. this.map.addLayer(editableLayers)
  150. let options = {
  151. position: 'topleft',
  152. draw: {
  153. polyline: {},
  154. polygon: {},
  155. circle: {},
  156. rectangle: {},
  157. marker: {},
  158. remove: {}
  159. },
  160. edit: {
  161. featureGroup: editableLayers,
  162. remove: true
  163. }
  164. }
  165. this.drawControl = new window.L.Control.Draw(options)
  166. this.map.addControl(this.drawControl)
  167. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  168. let editableLayer = e.layer
  169. let layerType = e.layerType
  170. editableLayer.on('dblclick', function(e) {
  171. if (layerType === 'polygon' || layerType === 'rectangle') {
  172. let latlng = editableLayer.getLatLngs()[0]
  173. //一个自定义的计算面积的函数
  174. var seeArea = window.L.GeometryUtil.geodesicArea(latlng)
  175. let area = (seeArea / 10e5).toFixed(2) + 'k㎡'
  176. modal.msg(area)
  177. } else if (layerType === 'polyline') {
  178. let latlng = editableLayer.getLatLngs()
  179. //一个自定义的计算长度的函数
  180. let dis = 0
  181. for (let i = 0; i < latlng.length - 1; i++) {
  182. let start = latlng[i]
  183. let end = latlng[i + 1]
  184. dis += window.L.latLng([start.lat, start.lng]).distanceTo([end.lat,
  185. end.lng
  186. ]) //计算两个点之间的距离,并累加
  187. }
  188. //结果得到的也是number类型,单位是KM
  189. modal.msg((dis / 10e2).toFixed(2) + 'km')
  190. }
  191. })
  192. if (layerType === 'marker') {
  193. let icon = new window.L.Icon({
  194. iconUrl: iconList['marker'],
  195. iconSize: [48, 48],
  196. iconAnchor: [24, 40],
  197. popupAnchor: [-3, -40],
  198. shadowSize: [41, 41]
  199. })
  200. editableLayer.options.icon = icon
  201. }
  202. editableLayers.addLayer(editableLayer)
  203. })
  204. } else {
  205. this.map.removeControl(this.drawControl)
  206. }
  207. }
  208. }
  209. },
  210. mounted() {
  211. this.getspuerMapHost()
  212. this.initMap()
  213. //添加画图的提示信息
  214. window.L.drawLocal.draw.toolbar = {
  215. actions: {
  216. title: '取消绘图',
  217. text: '取消'
  218. },
  219. finish: {
  220. title: '完成绘图',
  221. text: '完成'
  222. },
  223. undo: {
  224. title: '删除最后绘制的点',
  225. text: '删除最后一个点'
  226. },
  227. buttons: {
  228. polyline: '绘制折线',
  229. polygon: '绘制多边形',
  230. rectangle: '绘制矩形',
  231. circle: '绘制圆圈',
  232. marker: '绘制标记',
  233. circlemarker: '绘制圆圈标记'
  234. }
  235. }
  236. window.L.drawLocal.draw.handlers = {
  237. circle: {
  238. tooltip: {
  239. start: '单击并拖动以绘制圆形'
  240. },
  241. radius: '半径'
  242. },
  243. circlemarker: {
  244. tooltip: {
  245. start: '点击地图放置圆圈标记'
  246. }
  247. },
  248. marker: {
  249. tooltip: {
  250. start: '点击地图放置标记'
  251. }
  252. },
  253. polygon: {
  254. tooltip: {
  255. start: '点击开始绘制形状',
  256. cont: '点击继续绘制形状',
  257. end: '单击第一个点以关闭此形状'
  258. }
  259. },
  260. polyline: {
  261. error: '<strong>Error:</strong> shape edges cannot cross!',
  262. tooltip: {
  263. start: '点击开始画线',
  264. cont: '点击继续画线',
  265. end: '单击最后一点以完成线'
  266. }
  267. },
  268. rectangle: {
  269. tooltip: {
  270. start: '单击并拖动以绘制矩形'
  271. }
  272. },
  273. simpleshape: {
  274. tooltip: {
  275. end: '释放鼠标完成绘图'
  276. }
  277. }
  278. }
  279. window.L.drawLocal.edit = {
  280. toolbar: {
  281. actions: {
  282. save: {
  283. title: '保存更改',
  284. text: '保存'
  285. },
  286. cancel: {
  287. title: '取消编辑,放弃所有更改',
  288. text: '取消'
  289. },
  290. clearAll: {
  291. title: '清除所有图层',
  292. text: '清除所有'
  293. }
  294. },
  295. buttons: {
  296. edit: '编辑图层',
  297. editDisabled: '没有可编辑的图层',
  298. remove: '删除图层',
  299. removeDisabled: '没有可删除的图层'
  300. }
  301. },
  302. handlers: {
  303. edit: {
  304. tooltip: {
  305. text: '拖动手柄或标记以编辑要素',
  306. subtext: '单击取消以撤消更改'
  307. }
  308. },
  309. remove: {
  310. tooltip: {
  311. text: '单击要删除的功能'
  312. }
  313. }
  314. }
  315. }
  316. },
  317. props: {
  318. mapDiv: null,
  319. codes: null,
  320. mapSite: {},
  321. isdynamicPlotting: false,//动态标绘表格
  322. isSideBySide: false,
  323. showLatLng: null,
  324. showAreaLatLng: null,
  325. showLineLatLng: null,
  326. mapToolShowBH:false,
  327. },
  328. methods: {
  329. /** ----------------------------------火势蔓延 开始------------------------------------- */
  330. // initEditView: function() {
  331. // var that = this
  332. // var infoView = window.L.control({ position: 'topright' })
  333. // infoView.onAdd = function() {
  334. // that._div = L.DomUtil.create('div', 'editPane')
  335. // that._div.style.width = '236px'
  336. // that._div.innerHTML = '<div id="toolbar" class="panel panel-primary">' +
  337. // '<div class="panel-heading">' +
  338. // '<h5 class="panel-title text-center">' + resources.text_fastHeatMapLayer + '</h5></div>' +
  339. // '<div class="panel-body content">' +
  340. // '<div class="panel">' +
  341. // '<div class="input-group">' +
  342. // '<span class="input-group-addon">风向</span>' +
  343. // '<select class="form-control" style="width:auto" id="heatNums">' +
  344. // '<option value="1" >南风</option>' +
  345. // '<option value="2" >北风</option>' +
  346. // '<option value="3" >西风</option>' +
  347. // '<option value="4" >东风</option>' +
  348. // '</select>' +
  349. // '</div>' +
  350. // '</div>' +
  351. // '<div class="panel">' +
  352. // '<div class="input-group">' +
  353. // '<span class="input-group-addon">风速</span>' +
  354. // '<input type="text" class="form-control" id="heatNums1" value="20"/>' +
  355. // '</div>' +
  356. // '</div>' +
  357. //
  358. // '<input type="button" class="btn btn-default" value="' + resources.btn_startDraw + '" onclick ="'+that.createHeatPoints()+'"/>&nbsp; &nbsp;' +
  359. // '<input type="button" class="btn btn-default" value="' + resources.text_input_value_clear + '" onclick ="'+that.clearHeatPoints()+'"/>' +
  360. // '</div>' +
  361. // '</div>'
  362. // that.handleMapEvent(that._div, that.map)
  363. // return that._div
  364. // }
  365. // infoView.addTo(that.map)
  366. // },
  367. // handleMapEvent: function(div, map) {
  368. // let that = this
  369. // if (!div || !map) {
  370. // return
  371. // }
  372. // div.addEventListener('mouseover', function() {
  373. // that.map.dragging.disable()
  374. // that.map.scrollWheelZoom.disable()
  375. // that.map.doubleClickZoom.disable()
  376. // })
  377. // div.addEventListener('mouseout', function() {
  378. // that.map.dragging.enable()
  379. // that.map.scrollWheelZoom.enable()
  380. // that.map.doubleClickZoom.enable()
  381. // })
  382. // },
  383. showheatPlotting: function(heat_lat, heat_lng,windSpeed,windDirection) {
  384. console.log(heat_lat, heat_lng,windSpeed,windDirection)
  385. this.heat_lat = heat_lat
  386. this.heat_lng = heat_lng
  387. this.windDirection = windDirection
  388. this.windSpeed = windSpeed
  389. this.createHeatPoints()
  390. },
  391. createHeatPoints: function() {
  392. let that = this
  393. that.clearHeatPoints()
  394. that.heatMapLayer = new window.L.supermap.heatMapLayer(
  395. 'heatMap',
  396. {
  397. 'map': that.map,
  398. 'id': 'heatmap',
  399. 'radius': 10,
  400. // 设置图层透明度:(参数方式)
  401. 'opacity': 0.5,
  402. //featureWeight指定以哪个属性值为热力权重值创建热力图:
  403. 'featureWeight': 'value'
  404. }
  405. )
  406. var heatNums = parseInt($('#heatNums').val())
  407. //热力半径单位不使用用地理单位
  408. that.heatMapLayer.useGeoUnit = true
  409. that.heatMapLayer.radius = 0.01
  410. var features = []
  411. switch (that.windDirection) {
  412. case '南风'://南风
  413. features = that.getPointArray1()
  414. break
  415. case '西南风'://西南风
  416. features = that.getPointArray3_1()
  417. break
  418. case '东南风'://东南风
  419. features = that.getPointArray4_1()
  420. break
  421. case '北风'://北风
  422. features = that.getPointArray2()
  423. break
  424. case '西北风'://西北风
  425. features = that.getPointArray3_2()
  426. break
  427. case '东北风'://东北风
  428. features = that.getPointArray4_2()
  429. break
  430. case '西风'://西风
  431. features = that.getPointArray3()
  432. break
  433. case '东风'://东风
  434. features = that.getPointArray4()
  435. break
  436. }
  437. //加载heatMapFeature格式数据:
  438. that.heatMapLayer.addFeatures(features)
  439. that.heatMapLayer.addTo(that.map)
  440. },
  441. clearHeatPoints: function() {
  442. let that = this
  443. if (that.heatMapLayer) {
  444. that.map.removeLayer(that.heatMapLayer)
  445. that.heatMapLayer = null
  446. }
  447. },
  448. getPointArray1: function() {
  449. var heatNums1 = this.windSpeed
  450. var mLon = this.heat_lng, mLat = this.heat_lat
  451. var points = []
  452. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  453. mLat = this.accAdd(mLat, 0.005)
  454. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  455. 'value': 2000 - (i * Math.random())
  456. })
  457. }
  458. return points
  459. },
  460. getPointArray3_1: function() {
  461. var heatNums1 = this.windSpeed
  462. var mLon = this.heat_lng, mLat = this.heat_lat
  463. var points = []
  464. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  465. mLat = this.accAdd(mLat, 0.005)
  466. mLon = this.accAdd(mLon, 0.005)
  467. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  468. 'value': 2000 - (i * Math.random())
  469. })
  470. }
  471. return points
  472. },
  473. getPointArray4_1: function() {
  474. var heatNums1 = this.windSpeed
  475. var mLon = this.heat_lng, mLat = this.heat_lat
  476. var points = []
  477. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  478. mLat = this.accAdd(mLat, 0.005)
  479. mLon = this.accSub(mLon, 0.005)
  480. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  481. 'value': 2000 - (i * Math.random())
  482. })
  483. }
  484. return points
  485. },
  486. getPointArray2: function() {
  487. var heatNums1 = this.windSpeed
  488. var mLon = this.heat_lng, mLat = this.heat_lat
  489. var points = []
  490. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  491. mLat = this.accSub(mLat, 0.005)
  492. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  493. 'value': 2000 - (i * Math.random())
  494. })
  495. }
  496. return points
  497. },
  498. getPointArray3_2: function() {
  499. var heatNums1 = this.windSpeed
  500. var mLon = this.heat_lng, mLat = this.heat_lat
  501. var points = []
  502. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  503. mLat = this.accSub(mLat, 0.005)
  504. mLon = this.accAdd(mLon, 0.005)
  505. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  506. 'value': 2000 - (i * Math.random())
  507. })
  508. }
  509. return points
  510. },
  511. getPointArray4_2: function() {
  512. var heatNums1 = this.windSpeed
  513. var mLon = this.heat_lng, mLat = this.heat_lat
  514. var points = []
  515. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  516. mLat = this.accSub(mLat, 0.005)
  517. mLon = this.accSub(mLon, 0.005)
  518. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  519. 'value': 2000 - (i * Math.random())
  520. })
  521. }
  522. return points
  523. },
  524. getPointArray3: function() {
  525. var heatNums1 = this.windSpeed
  526. console.log(heatNums1)
  527. var mLon = this.heat_lng, mLat = this.heat_lat
  528. var points = []
  529. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  530. mLon = this.accAdd(mLon, 0.005)
  531. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  532. 'value': 2000 - (i * Math.random())
  533. })
  534. }
  535. return points
  536. },
  537. getPointArray4: function() {
  538. var heatNums1 = this.windSpeed
  539. var mLon = this.heat_lng, mLat = this.heat_lat
  540. var points = []
  541. for (var i = 0; i < parseInt(heatNums1 / 3); i++) {
  542. mLon = this.accSub(mLon, 0.005)
  543. points[i] = new window.L.supermap.heatMapFeature(L.point(mLon, mLat), {
  544. 'value': 2000 - (i * Math.random())
  545. })
  546. }
  547. return points
  548. },
  549. //加法函数,用来得到精确的加法结果
  550. //说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
  551. //调用:accAdd(arg1,arg2)
  552. //返回值:arg1加上arg2的精确结果
  553. accAdd: function(arg1, arg2) {
  554. var r1, r2, m, c
  555. try {
  556. r1 = arg1.toString().split('.')[1].length
  557. } catch (e) {
  558. r1 = 0
  559. }
  560. try {
  561. r2 = arg2.toString().split('.')[1].length
  562. } catch (e) {
  563. r2 = 0
  564. }
  565. c = Math.abs(r1 - r2)
  566. m = Math.pow(10, Math.max(r1, r2))
  567. if (c > 0) {
  568. var cm = Math.pow(10, c)
  569. if (r1 > r2) {
  570. arg1 = Number(arg1.toString().replace('.', ''))
  571. arg2 = Number(arg2.toString().replace('.', '')) * cm
  572. } else {
  573. arg1 = Number(arg1.toString().replace('.', '')) * cm
  574. arg2 = Number(arg2.toString().replace('.', ''))
  575. }
  576. } else {
  577. arg1 = Number(arg1.toString().replace('.', ''))
  578. arg2 = Number(arg2.toString().replace('.', ''))
  579. }
  580. return (arg1 + arg2) / m
  581. },
  582. /**
  583. ** 减法函数,用来得到精确的减法结果
  584. ** 说明:javascript的减法结果会有误差,在两个浮点数相减的时候会比较明显。这个函数返回较为精确的减法结果。
  585. ** 调用:accSub(arg1,arg2)
  586. ** 返回值:arg1加上arg2的精确结果
  587. **/
  588. accSub: function(arg1, arg2) {
  589. var r1, r2, m, n
  590. try {
  591. r1 = arg1.toString().split('.')[1].length
  592. } catch (e) {
  593. r1 = 0
  594. }
  595. try {
  596. r2 = arg2.toString().split('.')[1].length
  597. } catch (e) {
  598. r2 = 0
  599. }
  600. m = Math.pow(10, Math.max(r1, r2)) //last modify by deeka //动态控制精度长度
  601. n = r1 >= r2 ? r1 : r2
  602. return ((arg1 * m - arg2 * m) / m).toFixed(n)
  603. },
  604. /** ----------------------------------火势蔓延 结束------------------------------------- */
  605. /** ----------------------------------热力图 结束------------------------------------- */
  606. loadHeatMap: async function(points) {
  607. var heatNumbers = 150, heatRadius = 30
  608. var num = parseInt(heatNumbers)
  609. num = (num > 0) ? num : 0
  610. var radius = parseInt(heatRadius)
  611. radius = (radius > 0) ? radius : 0
  612. var heatPoints = points
  613. // for (var i = 0; i < num; i++) {
  614. // heatPoints[i] = [Math.random() * 0.28 + 42, Math.random() * 0.5 + 125, Math.random() * 80]
  615. // }
  616. var resultLayer = window.L.heatLayer(heatPoints, {
  617. radius: radius,
  618. minOpacity: 0.5
  619. }).addTo(this.map)
  620. },
  621. /** ----------------------------------热力图 开始------------------------------------- */
  622. clearM: async function(isAggregation) { //清理地图标点
  623. if (isAggregation) {
  624. if (this.isAggregationMyGroup != undefined && this.isAggregationMyGroup != false) {
  625. this.isAggregationMyGroup.clearLayers()
  626. }
  627. this.map.removeLayer(this.isAggregationLayers)
  628. this.isAggregationLayers = []
  629. this.radiusLayers = []
  630. this.isAggregationLayers = window.L.markerClusterGroup({
  631. //设置为true时显示聚类所占据的范围
  632. showCoverageOnHover: true,
  633. //设置为true时会向低一级聚类缩放
  634. zoomToBoundsOnClick: true,
  635. //增加点位时增加聚合动画(否则会出问题)
  636. animateAddingMarkers: true,
  637. //最大缩放级别点击聚合图标展开图标
  638. spiderfyOnMaxZoom: true
  639. })
  640. } else {
  641. if (this.myGroup != undefined && this.myGroup != false) {
  642. this.myGroup.clearLayers()
  643. }
  644. this.map.removeLayer(this.layers)
  645. this.layers = []
  646. }
  647. },
  648. clearMByType: async function(type) { //清理地图标点(根据类型,可取消落点)
  649. if (this.myGroupBytype != undefined && this.myGroupBytype != false) {
  650. for (var i = this.myGroupBytype.length - 1; i >= 0; i--) {
  651. if (this.myGroupBytype[i].type == type) {
  652. this.myGroupBytype[i].myGroup.clearLayers()
  653. this.myGroupBytype.splice(i, 1)
  654. }
  655. }
  656. }
  657. if (this.layersBytype != null && this.layersBytype.length > 0) {
  658. for (var i = this.layersBytype.length - 1; i >= 0; i--) {
  659. if (this.layersBytype[i].type == type) {
  660. this.layersBytype.splice(i, 1)
  661. }
  662. }
  663. }
  664. },
  665. clearC: async function() { //清理地图画线
  666. if (this.connectLayer != undefined && this.connectLayer != false) {
  667. this.connectLayer.clearLayers()
  668. }
  669. this.connectLayer = []
  670. },
  671. clearCTwo: async function() { //清理地图画线two
  672. if (this.connectLayerTwo != undefined && this.connectLayerTwo != false) {
  673. this.connectLayerTwo.clearLayers()
  674. }
  675. this.connectLayerTwo = []
  676. },
  677. clearG: async function() { //清理地图图形
  678. if (this.graphicsLayer != undefined && this.graphicsLayer != false) {
  679. this.graphicsLayer.clearLayers()
  680. }
  681. this.graphicsLayer = []
  682. },
  683. clearP: async function() { //清理点击事件落点
  684. if (this.latLngGroup != undefined && this.latLngGroup != false) {
  685. this.latLngGroup.clearLayers()
  686. }
  687. this.latLngLayers = []
  688. },
  689. initMap: function() {
  690. let _that = this
  691. this.mapDivId = this.mapDiv
  692. let mapSite = this.mapSite
  693. let isSideBySide = this.isSideBySide
  694. let isdynamicPlotting = this.isdynamicPlotting
  695. // setToken("eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImY5Zjg3ZjVmLWQ4NTctNDQxZC04NmQ5LTg4OWExZWRlODE4ZSIsInVzZXJuYW1lIjoiYWRtaW4ifQ.26mAzmaM9pUza9585aLnRMyRd4GxvrWbCxN0erYsuiBDYQiYnyc-TwXVNDI7Xrpt3Bqmbnul-XMszOxYQi12LA");
  696. _that.isAggregationLayers = window.L.markerClusterGroup({
  697. //设置为true时显示聚类所占据的范围
  698. showCoverageOnHover: true,
  699. //设置为true时会向低一级聚类缩放
  700. zoomToBoundsOnClick: true,
  701. //增加点位时增加聚合动画(否则会出问题)
  702. animateAddingMarkers: true,
  703. //最大缩放级别点击聚合图标展开图标
  704. spiderfyOnMaxZoom: true
  705. })
  706. if (!isSideBySide) { //只有一个地图
  707. if (_that.codes.length != 1) {
  708. modal.msgError('请输入一个地图code!')
  709. return
  710. }
  711. getSuperMap(_that.codes).then(resp => {
  712. let mapList = resp.data
  713. if (mapList != null && mapList.length > 0) {
  714. let url = mapList[0].url
  715. let centerLat = mapList[0].centerLat
  716. let centerLng = mapList[0].centerLng
  717. let zoom = mapList[0].zoom //默认比例
  718. let maxZoom = mapList[0].maxZoom //最大比例
  719. let minZoom = mapList[0].minZoom //最小比例
  720. let zoomControl = mapList[0].zoomControl == null ? true : mapList[0]
  721. .zoomControl //地图缩放+-号是否显示
  722. let attributionControl = mapList[0].attributionControl == null ? true : mapList[0]
  723. .attributionControl //logo是否显示
  724. let logoControl = mapList[0].logoControl == null ? false : mapList[0]
  725. .logoControl //logo是否显示
  726. let dragging = mapList[0].dragging == null ? true : mapList[0]
  727. .dragging //地图是否允许鼠标拖拽
  728. let defaultConfigure = {
  729. crs: window.L.CRS.EPSG4326,
  730. center: [centerLat, centerLng],
  731. maxZoom: maxZoom,
  732. minZoom: minZoom,
  733. zoom: zoom,
  734. editable: true,
  735. zoomControl: zoomControl,
  736. attributionControl: attributionControl,
  737. dragging: dragging,
  738. logoControl: logoControl
  739. }
  740. let loadConfiguration = Object.assign(defaultConfigure, mapSite)
  741. _that.map = window.L.map(_that.mapDiv, loadConfiguration)
  742. //鼠标双击落点
  743. if (_that.showLatLng != undefined) {
  744. let icon = new window.L.Icon({
  745. iconUrl: iconList['marker'],
  746. iconSize: [48, 48],
  747. iconAnchor: [24, 40],
  748. popupAnchor: [-3, -40],
  749. shadowSize: [41, 41]
  750. })
  751. _that.map.on('dblclick', function(e) {
  752. _that.clearP()
  753. _that.showLatLng(e.latlng.lat, e.latlng.lng)
  754. let marker = window.L.marker([e.latlng.lat, e.latlng.lng], {
  755. icon: icon
  756. }).addTo(_that.map)
  757. _that.latLngLayers.push(marker)
  758. _that.latLngGroup = window.L.layerGroup(_that.latLngLayers)
  759. _that.map.addLayer(_that.latLngGroup)
  760. })
  761. }
  762. //鼠标绘制区域
  763. if (_that.showAreaLatLng != undefined) {
  764. var editableLayers = new window.L.FeatureGroup()
  765. _that.map.addLayer(editableLayers)
  766. let options = {
  767. position: 'topleft',
  768. draw: {
  769. polyline: null,
  770. polygon: {},
  771. circle: null,
  772. rectangle: null,
  773. circlemarker: null,
  774. marker: null,
  775. remove: {}
  776. },
  777. edit: {
  778. featureGroup: editableLayers,
  779. remove: true
  780. }
  781. }
  782. var drawControl = new window.L.Control.Draw(options)
  783. _that.map.addControl(drawControl)
  784. _that.map.on(window.L.Draw.Event.CREATED, function(e) {
  785. let editableLayer = e.layer
  786. let layerType = e.layerType
  787. editableLayer.on('dblclick', function(e) {
  788. if (layerType === 'polygon' || layerType ===
  789. 'rectangle') {
  790. let latlng = editableLayer.getLatLngs()[0]
  791. _that.showAreaLatLng(latlng)
  792. }
  793. })
  794. editableLayers.addLayer(editableLayer)
  795. })
  796. }
  797. //鼠标绘制线段
  798. if (_that.showLineLatLng != undefined) {
  799. var editableLayers = new window.L.FeatureGroup()
  800. _that.map.addLayer(editableLayers)
  801. let options = {
  802. position: 'topleft',
  803. draw: {
  804. polyline: {},
  805. polygon: null,
  806. circle: null,
  807. rectangle: null,
  808. circlemarker: null,
  809. marker: null,
  810. remove: {}
  811. },
  812. edit: {
  813. featureGroup: editableLayers,
  814. remove: true
  815. }
  816. }
  817. var drawControl = new window.L.Control.Draw(options)
  818. _that.map.addControl(drawControl)
  819. _that.map.on(window.L.Draw.Event.CREATED, function(e) {
  820. let editableLayer = e.layer
  821. let layerType = e.layerType
  822. editableLayer.on('dblclick', function(e) {
  823. if (layerType === 'polyline') {
  824. let latlng = editableLayer.getLatLngs()
  825. _that.showLineLatLng(latlng)
  826. }
  827. })
  828. editableLayers.addLayer(editableLayer)
  829. })
  830. }
  831. // url = 'https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China_4326'
  832. window.L.supermap.tiledMapLayer(url).addTo(_that.map)
  833. }
  834. })
  835. } else { //卷帘地图
  836. if (_that.codes.length != 2) {
  837. modal.msgError('请输入两个地图code!')
  838. return
  839. }
  840. getSuperMap(_that.codes).then(resp => {
  841. let mapList = resp.data
  842. if (mapList != null && mapList.length == 2) {
  843. let stamenurl = mapList[0].url
  844. let osmurl = mapList[1].url
  845. let centerLat = mapList[0].centerLat
  846. let centerLng = mapList[0].centerLng
  847. let zoom = mapList[0].zoom //默认比例
  848. let maxZoom = mapList[0].maxZoom //最大比例
  849. let minZoom = mapList[0].minZoom //最小比例
  850. let zoomControl = mapList[0].zoomControl == null ? true : mapList[0]
  851. .zoomControl //地图缩放+-号是否显示
  852. let attributionControl = mapList[0].attributionControl == null ? true : mapList[0]
  853. .attributionControl //logo是否显示
  854. let logoControl = mapList[0].logoControl == null ? false : mapList[0]
  855. .logoControl //logo是否显示
  856. let dragging = mapList[0].dragging == null ? true : mapList[0]
  857. .dragging //地图是否允许鼠标拖拽
  858. let defaultConfigure = {
  859. crs: window.L.CRS.EPSG4326,
  860. center: [centerLat, centerLng],
  861. maxZoom: maxZoom,
  862. minZoom: minZoom,
  863. zoom: zoom,
  864. editable: true,
  865. zoomControl: zoomControl,
  866. attributionControl: attributionControl,
  867. dragging: dragging,
  868. logoControl: logoControl
  869. }
  870. let loadConfiguration = Object.assign(defaultConfigure, mapSite)
  871. _that.map = window.L.map(_that.mapDiv, loadConfiguration)
  872. //鼠标双击落点
  873. if (_that.showLatLng != undefined) {
  874. let icon = new window.L.Icon({
  875. iconUrl: iconList['marker'],
  876. iconSize: [48, 48],
  877. iconAnchor: [24, 40],
  878. popupAnchor: [-3, -40],
  879. shadowSize: [41, 41]
  880. })
  881. _that.map.on('dblclick', function(e) {
  882. _that.clearP()
  883. _that.showLatLng(e.latlng.lat, e.latlng.lng)
  884. let marker = window.L.marker([e.latlng.lat, e.latlng.lng], {
  885. icon: icon
  886. }).addTo(_that.map)
  887. _that.latLngLayers.push(marker)
  888. _that.latLngGroup = window.L.layerGroup(_that.latLngLayers)
  889. _that.map.addLayer(_that.latLngGroup)
  890. })
  891. }
  892. //鼠标绘制区域
  893. if (_that.showAreaLatLng != undefined) {
  894. var editableLayers = new window.L.FeatureGroup()
  895. _that.map.addLayer(editableLayers)
  896. let options = {
  897. position: 'topleft',
  898. draw: {
  899. polyline: null,
  900. polygon: {},
  901. circle: null,
  902. rectangle: null,
  903. circlemarker: null,
  904. marker: null,
  905. remove: {}
  906. },
  907. edit: {
  908. featureGroup: editableLayers,
  909. remove: true
  910. }
  911. }
  912. var drawControl = new window.L.Control.Draw(options)
  913. _that.map.addControl(drawControl)
  914. _that.map.on(window.L.Draw.Event.CREATED, function(e) {
  915. let editableLayer = e.layer
  916. let layerType = e.layerType
  917. editableLayer.on('dblclick', function(e) {
  918. if (layerType === 'polygon' || layerType ===
  919. 'rectangle') {
  920. let latlng = editableLayer.getLatLngs()[0]
  921. _that.showAreaLatLng(latlng)
  922. }
  923. })
  924. editableLayers.addLayer(editableLayer)
  925. })
  926. }
  927. //鼠标绘制线段
  928. if (_that.showLineLatLng != undefined) {
  929. var editableLayers = new window.L.FeatureGroup()
  930. _that.map.addLayer(editableLayers)
  931. let options = {
  932. position: 'topleft',
  933. draw: {
  934. polyline: {},
  935. polygon: null,
  936. circle: null,
  937. rectangle: null,
  938. circlemarker: null,
  939. marker: null,
  940. remove: {}
  941. },
  942. edit: {
  943. featureGroup: editableLayers,
  944. remove: true
  945. }
  946. }
  947. var drawControl = new window.L.Control.Draw(options)
  948. _that.map.addControl(drawControl)
  949. _that.map.on(window.L.Draw.Event.CREATED, function(e) {
  950. let editableLayer = e.layer
  951. let layerType = e.layerType
  952. editableLayer.on('dblclick', function(e) {
  953. if (layerType === 'polyline') {
  954. let latlng = editableLayer.getLatLngs()
  955. _that.showLineLatLng(latlng)
  956. }
  957. })
  958. editableLayers.addLayer(editableLayer)
  959. })
  960. }
  961. let stamenLayer = window.L.supermap.tiledMapLayer(stamenurl).addTo(_that.map)
  962. let osmLayer = window.L.supermap.tiledMapLayer(osmurl).addTo(_that.map)
  963. L.control.sideBySide(stamenLayer, osmLayer).addTo(_that.map)
  964. }
  965. })
  966. }
  967. },
  968. // 获取面积
  969. /**
  970. * polygon [{lat:30,lng:104},{lat:30,lng:104},{lat:30,lng:104}]
  971. */
  972. formatArea: function(polygon) {
  973. //L.GeometryUtil.geodesicArea(),返回number类型的数据,单位是平方米,这里做了一下转化
  974. var seeArea = window.L.GeometryUtil.geodesicArea(polygon)
  975. let area = (seeArea / 10e5).toFixed(2) + 'k㎡'
  976. return area
  977. },
  978. // 获取长度
  979. /**
  980. * line[{lat:30,lng:104},{lat:30,lng:104},{lat:30,lng:104}]
  981. */
  982. formatLength: function(line) {
  983. let dis = 0
  984. for (let i = 0; i < line.length - 1; i++) {
  985. let start = line[i]
  986. let end = line[i + 1]
  987. dis += window.L.latLng([start.lat, start.lng]).distanceTo([end.lat, end.lng]) //计算两个点之间的距离,并累加
  988. }
  989. //结果得到的也是number类型,单位是 米
  990. return (dis / 10e2).toFixed(2) + 'km'
  991. },
  992. setMarkers: function(markersList) { //地图标点
  993. const _that = this
  994. for (let i = 0; i < markersList.length; i++) {
  995. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  996. .isAggregation //是否聚合点位
  997. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  998. let icon = new window.L.Icon({
  999. iconUrl: iconList[markersList[i].icon],
  1000. iconSize: [48, 48],
  1001. iconAnchor: [24, 40],
  1002. popupAnchor: [-3, -40],
  1003. shadowSize: [41, 41]
  1004. })
  1005. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  1006. icon: icon
  1007. })
  1008. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  1009. let html = markersList[i].bindPopupHtml
  1010. if (keepBindPopup) {
  1011. markerClick.bindPopup(html, {
  1012. autoClose: false,
  1013. closeOnClick: null,
  1014. closeButton: false
  1015. }).openPopup(markerClick.getLatLng())
  1016. } else {
  1017. markerClick.on('mouseover', function() {
  1018. let html = markersList[i].bindPopupHtml
  1019. this.bindPopup(html).openPopup(this.getLatLng())
  1020. }).on('mouseout', function() {
  1021. this.closePopup()
  1022. })
  1023. }
  1024. }
  1025. if (markersList[i].click != null && markersList[i].click !== '') {
  1026. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  1027. markerClick.on('click', function() {
  1028. let clickName = markersList[i].click
  1029. _that.$emit(clickName, markersList[i].parameter)
  1030. })
  1031. } else {
  1032. markerClick.on('click', function() {
  1033. let clickName = markersList[i].click
  1034. _that.$emit(clickName)
  1035. })
  1036. }
  1037. }
  1038. if (isAggregation) {
  1039. _that.isAggregationLayers.addLayer(markerClick)
  1040. _that.isAggregationMyGroup = window.L.layerGroup(_that.isAggregationLayers)
  1041. } else {
  1042. _that.layers.push(markerClick)
  1043. _that.myGroup = window.L.layerGroup(_that.layers)
  1044. }
  1045. }
  1046. if (_that.myGroup != undefined && _that.myGroup != false) {
  1047. _that.map.addLayer(_that.myGroup)
  1048. }
  1049. _that.map.addLayer(_that.isAggregationLayers)
  1050. },
  1051. setMarkersA: function(markersList) { //地图标点
  1052. const _that = this
  1053. for (let i = 0; i < markersList.length; i++) {
  1054. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  1055. .isAggregation //是否聚合点位
  1056. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  1057. let icon = new window.L.Icon({
  1058. iconUrl: iconList[markersList[i].icon],
  1059. iconSize: [48, 48],
  1060. iconAnchor: [24, 40],
  1061. popupAnchor: [-3, -40],
  1062. shadowSize: [41, 41]
  1063. })
  1064. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  1065. icon: icon
  1066. })
  1067. markerClick.on('mouseover', function() {
  1068. let a = "";
  1069. _that.aac = setInterval(function (){
  1070. var color = "green";
  1071. var value = Math.random();
  1072. var up = "▲";
  1073. var down = "▼";
  1074. if(value>0.5){
  1075. color = "red";
  1076. value = value +""+ up;
  1077. }else{
  1078. value = value +""+ down;
  1079. }
  1080. a = "<span style='color:"+color+"'>当前传感器数值:"+value+"</span>";
  1081. markerClick.bindPopup(a).openPopup(markerClick.getLatLng());
  1082. console.log(this);
  1083. },500);
  1084. }).on('mouseout', function() {
  1085. clearInterval(_that.aac);
  1086. this.closePopup();
  1087. })
  1088. if (markersList[i].click != null && markersList[i].click !== '') {
  1089. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  1090. markerClick.on('click', function() {
  1091. let clickName = markersList[i].click
  1092. _that.$emit(clickName, markersList[i].parameter)
  1093. })
  1094. } else {
  1095. markerClick.on('click', function() {
  1096. let clickName = markersList[i].click
  1097. _that.$emit(clickName)
  1098. })
  1099. }
  1100. }
  1101. if (isAggregation) {
  1102. _that.isAggregationLayers.addLayer(markerClick)
  1103. _that.isAggregationMyGroup = window.L.layerGroup(_that.isAggregationLayers)
  1104. } else {
  1105. _that.layers.push(markerClick)
  1106. _that.myGroup = window.L.layerGroup(_that.layers)
  1107. }
  1108. }
  1109. if (_that.myGroup != undefined && _that.myGroup != false) {
  1110. _that.map.addLayer(_that.myGroup)
  1111. }
  1112. _that.map.addLayer(_that.isAggregationLayers)
  1113. },
  1114. setMarkersByType: function(markersList, type) { //地图标点(根据类型,可取消落点 clearMByType方法)
  1115. const _that = this
  1116. let lay = []
  1117. let myGroup = []
  1118. for (let i = 0; i < markersList.length; i++) {
  1119. let keepBindPopup = markersList[i].keepBindPopup //提示气泡是否一直显示
  1120. let icon = new window.L.Icon({
  1121. iconUrl: iconList[markersList[i].icon],
  1122. iconSize: [48, 48],
  1123. iconAnchor: [24, 40],
  1124. popupAnchor: [-3, -40],
  1125. shadowSize: [41, 41]
  1126. })
  1127. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  1128. icon: icon
  1129. }).addTo(this.map)
  1130. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  1131. let html = markersList[i].bindPopupHtml
  1132. if (keepBindPopup) {
  1133. markerClick.bindPopup(html, {
  1134. autoClose: false,
  1135. closeOnClick: null,
  1136. closeButton: false
  1137. }).openPopup(markerClick.getLatLng())
  1138. } else {
  1139. markerClick.on('mouseover', function() {
  1140. let html = markersList[i].bindPopupHtml
  1141. this.bindPopup(html).openPopup(this.getLatLng())
  1142. }).on('mouseout', function() {
  1143. this.closePopup()
  1144. })
  1145. }
  1146. }
  1147. if (markersList[i].click != null && markersList[i].click !== '') {
  1148. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  1149. markerClick.on('click', function() {
  1150. let clickName = markersList[i].click
  1151. _that.$emit(clickName, markersList[i].parameter)
  1152. })
  1153. } else {
  1154. markerClick.on('click', function() {
  1155. let clickName = markersList[i].click
  1156. _that.$emit(clickName)
  1157. })
  1158. }
  1159. }
  1160. lay.push(markerClick)
  1161. _that.layersBytype.push({ type: type, marker: markerClick })
  1162. myGroup = window.L.layerGroup(lay)
  1163. _that.myGroupBytype.push({ type: type, myGroup: myGroup })
  1164. this.map.addLayer(myGroup)
  1165. }
  1166. },
  1167. setMarkersRadius: function(markersList) { //地图标点带范围
  1168. const _that = this
  1169. for (let i = 0; i < markersList.length; i++) {
  1170. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  1171. .isAggregation //是否聚合点位
  1172. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  1173. _that.polygon = window.L.circle([markersList[i].lat, markersList[i].lng], {
  1174. radius: markersList[i].radius
  1175. })
  1176. let icon = new window.L.Icon({ //传感器
  1177. iconUrl: iconList[markersList[i].icon],
  1178. iconSize: [48, 48],
  1179. iconAnchor: [24, 40],
  1180. popupAnchor: [-3, -40],
  1181. shadowSize: [41, 41]
  1182. })
  1183. let marker = window.L.marker([markersList[i].lat, markersList[i].lng], {
  1184. icon: icon
  1185. })
  1186. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  1187. let html = markersList[i].bindPopupHtml
  1188. if (keepBindPopup) {
  1189. marker.bindPopup(html, {
  1190. autoClose: false,
  1191. closeOnClick: null,
  1192. closeButton: false
  1193. }).openPopup(marker.getLatLng())
  1194. } else {
  1195. marker.on('mouseover', function() {
  1196. let html = markersList[i].bindPopupHtml
  1197. this.bindPopup(html).openPopup(this.getLatLng())
  1198. }).on('mouseout', function() {
  1199. this.closePopup()
  1200. })
  1201. }
  1202. }
  1203. if (markersList[i].click != null && markersList[i].click != '') {
  1204. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  1205. marker.on('click', function() {
  1206. let clickName = markersList[i].click
  1207. _that.$emit(clickName, markersList[i].parameter)
  1208. })
  1209. } else {
  1210. marker.on('click', function() {
  1211. let clickName = markersList[i].click
  1212. _that.$emit(clickName)
  1213. })
  1214. }
  1215. }
  1216. marker.addTo(this.map)
  1217. if (isAggregation) {
  1218. _that.isAggregationLayers.addLayer(marker)
  1219. _that.radiusLayers.push(_that.polygon)
  1220. this.map.addLayer(_that.isAggregationLayers)
  1221. _that.isAggregationMyGroup = window.L.layerGroup(_that.radiusLayers)
  1222. this.map.addLayer(_that.isAggregationMyGroup)
  1223. } else {
  1224. _that.layers.push(marker)
  1225. _that.layers.push(_that.polygon)
  1226. _that.myGroup = window.L.layerGroup(_that.layers)
  1227. this.map.addLayer(_that.myGroup)
  1228. }
  1229. }
  1230. },
  1231. setConnectList: function(connectList, color) { //地图画线
  1232. const _that = this
  1233. let points = []
  1234. for (let i = 0; i < connectList.length; i++) {
  1235. points.push([connectList[i].lat, connectList[i].lng]) //创建点
  1236. }
  1237. let polyline = window.L.polyline(points, {
  1238. color: color
  1239. })
  1240. if (this.connectLayer != undefined && this.connectLayer != false) {
  1241. _that.connectLayer.addLayer(polyline)
  1242. } else {
  1243. _that.connectLayer = window.L.featureGroup().addTo(this.map)
  1244. _that.connectLayer.addLayer(polyline)
  1245. }
  1246. },
  1247. setConnectTwoList: function(connectList, color) { //地图画线图层2
  1248. const _that = this
  1249. let points = []
  1250. for (let i = 0; i < connectList.length; i++) {
  1251. points.push([connectList[i].lat, connectList[i].lng]) //创建点
  1252. }
  1253. let polyline = window.L.polyline(points, {
  1254. color: color
  1255. })
  1256. if (this.connectLayerTwo != undefined && this.connectLayerTwo != false) {
  1257. _that.connectLayerTwo.addLayer(polyline)
  1258. } else {
  1259. _that.connectLayerTwo = window.L.featureGroup().addTo(this.map)
  1260. _that.connectLayerTwo.addLayer(polyline)
  1261. }
  1262. },
  1263. setGraphicsList: function(graphicsList, color) { //地图图形
  1264. const _that = this
  1265. let points = []
  1266. for (let i = 0; i < graphicsList.length; i++) {
  1267. points.push([graphicsList[i].lat, graphicsList[i].lng]) //创建点
  1268. }
  1269. let polygon = window.L.polygon(points, {
  1270. color: color
  1271. })
  1272. polygon.addTo(this.map)
  1273. if (this.graphicsLayer != undefined && this.graphicsLayer != false) {
  1274. _that.graphicsLayer.addLayer(polygon)
  1275. } else {
  1276. _that.graphicsLayer = window.L.featureGroup().addTo(this.map)
  1277. _that.graphicsLayer.addLayer(polygon)
  1278. }
  1279. },
  1280. dropLocation: function(lat, lng) { //落点定位
  1281. this.map.flyTo([lat, lng], 13, { duration: 2 })
  1282. },
  1283. dropLocation: function(lat, lng,leve) { //落点定位
  1284. this.map.flyTo([lat, lng], leve, {
  1285. duration: 2
  1286. })
  1287. },
  1288. dropLocation10: function(lat, lng) { //落点定位
  1289. this.map.flyTo([lat, lng], 10, { duration: 2 })
  1290. },
  1291. dropLocation5: function(lat, lng) { //落点定位
  1292. this.map.flyTo([lat, lng], 5, { duration: 2 })
  1293. },
  1294. controlLevel: function(level) { //控制地图缩放级别
  1295. this.map.setZoom(level)
  1296. },
  1297. layerSwitching: function(url, isClear) { //图层切换 url 图层地址 isClear 是否清除图层
  1298. if (isClear) {
  1299. if (this.deckglLayer != null) {
  1300. this.deckglLayer.remove()
  1301. }
  1302. }
  1303. this.deckglLayer = window.L.supermap.tiledMapLayer(url, {})
  1304. this.map.addLayer(this.deckglLayer)
  1305. },
  1306. layerSwitchingList: function(urlList) { //图层切换数组 urlList 图层地址(数组)
  1307. if (this.deckglLayerList != null && this.deckglLayerList.length > 0) {
  1308. for (let i = 0; i < this.deckglLayerList.length; i++) {
  1309. this.deckglLayerList[i].remove()
  1310. }
  1311. }
  1312. if (urlList != null && urlList.length > 0) {
  1313. for (let i = 0; i < urlList.length; i++) {
  1314. this.deckglLayer = window.L.supermap.tiledMapLayer(urlList[i], {})
  1315. this.deckglLayerList.push(this.deckglLayer)
  1316. this.map.addLayer(this.deckglLayer)
  1317. }
  1318. }
  1319. },
  1320. /** ----------------------------------动态绘制开始------------------------------------- */
  1321. clearLayers: function() {
  1322. this.plottingLayer.removeAllFeatures()
  1323. },
  1324. PlottingDrawCancel: function() {
  1325. this.plottingdrawControl.handler.disable()
  1326. },
  1327. getspuerMapHost(){
  1328. selectConfigKey('superMap.iserver.plot').then(res => {
  1329. this.host = res.data;
  1330. })
  1331. },
  1332. dynamicPlotting: function() {
  1333. setTimeout(() => {
  1334. var host = this.host
  1335. var serverUrl = host + '/iserver/services/plot-jingyong/rest/plot/'
  1336. var me = this
  1337. this.plottingLayer = window.L.supermap.plotting.plottingLayer('plot',
  1338. serverUrl)
  1339. this.plottingLayer.spatialAnalystUrl =
  1340. host + '/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst'
  1341. this.plottingLayer.addTo(this.map)
  1342. this.plottingdrawControl = window.L.supermap.plotting.drawControl(this
  1343. .plottingLayer)
  1344. this.plottingdrawControl.addTo(this.map)
  1345. var editControl = window.L.supermap.plotting.editControl()
  1346. editControl.addTo(this.map)
  1347. window.L.supermap.plotting.initPlotPanel('plotPanel', serverUrl, this
  1348. .plottingdrawControl)
  1349. }, 2000)
  1350. }
  1351. /** ----------------------------------动态绘制结束------------------------------------- */
  1352. }
  1353. }
  1354. </script>
  1355. <style lang="scss" scoped>
  1356. @import '@/assets/styles/base.scss';
  1357. .panel{
  1358. margin-bottom: .5rem;
  1359. button{
  1360. margin-top: .5rem;
  1361. }
  1362. .input-group{
  1363. display: flex;
  1364. flex-direction: row;
  1365. align-items: center;
  1366. .input-group-addon{
  1367. color: $inBlue;
  1368. width: 3rem;
  1369. text-align: right;
  1370. }
  1371. .form-control{
  1372. padding: 0 .3rem;
  1373. margin-left: .5rem;
  1374. height: 1.5rem;
  1375. line-height: 1.5rem;
  1376. background-color: #112543;
  1377. color: $inBlue;
  1378. border: 1px $searchBorder;
  1379. }
  1380. }
  1381. }
  1382. .button-group {
  1383. button {
  1384. padding: 0 0.3rem;
  1385. height: 1.5rem;
  1386. background-color: #112543;
  1387. color: #2bacf7;
  1388. border: 1px solid #33467f;
  1389. }
  1390. button:hover {
  1391. border: 1px solid #33467f;
  1392. background-color: #112543;
  1393. text-shadow: 0 0 15px rgba($color: $inBlueHover, $alpha: 1.0);
  1394. }
  1395. }
  1396. </style>