supermap.vue 41 KB

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