supermap.vue 46 KB

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