supermap.vue 51 KB

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