supermap.vue 50 KB

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