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. this.map.removeLayer(this.isAggregationLayers)
  577. this.isAggregationLayers = []
  578. this.radiusLayers = []
  579. this.isAggregationLayers = window.L.markerClusterGroup({
  580. //设置为true时显示聚类所占据的范围
  581. showCoverageOnHover: true,
  582. //设置为true时会向低一级聚类缩放
  583. zoomToBoundsOnClick: true,
  584. //增加点位时增加聚合动画(否则会出问题)
  585. animateAddingMarkers: true,
  586. //最大缩放级别点击聚合图标展开图标
  587. spiderfyOnMaxZoom: true
  588. })
  589. } else {
  590. if (this.myGroup != undefined && this.myGroup != false) {
  591. this.myGroup.clearLayers()
  592. }
  593. this.map.removeLayer(this.layers)
  594. this.layers = []
  595. }
  596. },
  597. clearMByType: async function(type) { //清理地图标点(根据类型,可取消落点)
  598. if (this.myGroupBytype != undefined && this.myGroupBytype != false) {
  599. for (var i = this.myGroupBytype.length - 1; i >= 0; i--) {
  600. if (this.myGroupBytype[i].type == type) {
  601. this.myGroupBytype[i].myGroup.clearLayers()
  602. this.myGroupBytype.splice(i, 1)
  603. }
  604. }
  605. }
  606. if (this.layersBytype != null && this.layersBytype.length > 0) {
  607. for (var i = this.layersBytype.length - 1; i >= 0; i--) {
  608. if (this.layersBytype[i].type == type) {
  609. this.layersBytype.splice(i, 1)
  610. }
  611. }
  612. }
  613. },
  614. clearC: async function() { //清理地图画线
  615. if (this.connectLayer != undefined && this.connectLayer != false) {
  616. this.connectLayer.clearLayers()
  617. }
  618. this.connectLayer = []
  619. },
  620. clearCTwo: async function() { //清理地图画线two
  621. if (this.connectLayerTwo != undefined && this.connectLayerTwo != false) {
  622. this.connectLayerTwo.clearLayers()
  623. }
  624. this.connectLayerTwo = []
  625. },
  626. clearG: async function() { //清理地图图形
  627. if (this.graphicsLayer != undefined && this.graphicsLayer != false) {
  628. this.graphicsLayer.clearLayers()
  629. }
  630. this.graphicsLayer = []
  631. },
  632. clearP: async function() { //清理点击事件落点
  633. if (this.latLngGroup != undefined && this.latLngGroup != false) {
  634. this.latLngGroup.clearLayers()
  635. }
  636. this.latLngLayers = []
  637. },
  638. initMap: function() {
  639. let _that = this
  640. this.mapDivId = this.mapDiv
  641. let mapSite = this.mapSite
  642. let isSideBySide = this.isSideBySide
  643. let isdynamicPlotting = this.isdynamicPlotting
  644. // setToken("eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImY5Zjg3ZjVmLWQ4NTctNDQxZC04NmQ5LTg4OWExZWRlODE4ZSIsInVzZXJuYW1lIjoiYWRtaW4ifQ.26mAzmaM9pUza9585aLnRMyRd4GxvrWbCxN0erYsuiBDYQiYnyc-TwXVNDI7Xrpt3Bqmbnul-XMszOxYQi12LA");
  645. _that.isAggregationLayers = window.L.markerClusterGroup({
  646. //设置为true时显示聚类所占据的范围
  647. showCoverageOnHover: true,
  648. //设置为true时会向低一级聚类缩放
  649. zoomToBoundsOnClick: true,
  650. //增加点位时增加聚合动画(否则会出问题)
  651. animateAddingMarkers: true,
  652. //最大缩放级别点击聚合图标展开图标
  653. spiderfyOnMaxZoom: true
  654. })
  655. if (!isSideBySide) { //只有一个地图
  656. if (this.codes.length != 1) {
  657. modal.msgError('请输入一个地图code!')
  658. return
  659. }
  660. getSuperMap(this.codes).then(resp => {
  661. let mapList = resp.data
  662. if (mapList != null && mapList.length > 0) {
  663. let url = mapList[0].url
  664. let centerLat = mapList[0].centerLat
  665. let centerLng = mapList[0].centerLng
  666. let zoom = mapList[0].zoom //默认比例
  667. let maxZoom = mapList[0].maxZoom //最大比例
  668. let minZoom = mapList[0].minZoom //最小比例
  669. let zoomControl = mapList[0].zoomControl == null ? true : mapList[0]
  670. .zoomControl //地图缩放+-号是否显示
  671. let attributionControl = mapList[0].attributionControl == null ? true : mapList[0]
  672. .attributionControl //logo是否显示
  673. let logoControl = mapList[0].logoControl == null ? false : mapList[0]
  674. .logoControl //logo是否显示
  675. let dragging = mapList[0].dragging == null ? true : mapList[0]
  676. .dragging //地图是否允许鼠标拖拽
  677. let defaultConfigure = {
  678. crs: window.L.CRS.EPSG4326,
  679. center: [centerLat, centerLng],
  680. maxZoom: maxZoom,
  681. minZoom: minZoom,
  682. zoom: zoom,
  683. editable: true,
  684. zoomControl: zoomControl,
  685. attributionControl: attributionControl,
  686. dragging: dragging,
  687. logoControl: logoControl
  688. }
  689. let loadConfiguration = Object.assign(defaultConfigure, mapSite)
  690. this.map = window.L.map(this.mapDiv, loadConfiguration)
  691. //鼠标双击落点
  692. if (this.showLatLng != undefined) {
  693. let icon = new window.L.Icon({
  694. iconUrl: iconList['marker'],
  695. iconSize: [48, 48],
  696. iconAnchor: [24, 40],
  697. popupAnchor: [-3, -40],
  698. shadowSize: [41, 41]
  699. })
  700. this.map.on('dblclick', function(e) {
  701. _that.clearP()
  702. _that.showLatLng(e.latlng.lat, e.latlng.lng)
  703. let marker = window.L.marker([e.latlng.lat, e.latlng.lng], {
  704. icon: icon
  705. }).addTo(this.map)
  706. _that.latLngLayers.push(marker)
  707. _that.latLngGroup = window.L.layerGroup(_that.latLngLayers)
  708. this.map.addLayer(_that.latLngGroup)
  709. })
  710. }
  711. //鼠标绘制区域
  712. if (this.showAreaLatLng != undefined) {
  713. var editableLayers = new window.L.FeatureGroup()
  714. this.map.addLayer(editableLayers)
  715. let options = {
  716. position: 'topleft',
  717. draw: {
  718. polyline: null,
  719. polygon: {},
  720. circle: null,
  721. rectangle: null,
  722. circlemarker: null,
  723. marker: null,
  724. remove: {}
  725. },
  726. edit: {
  727. featureGroup: editableLayers,
  728. remove: true
  729. }
  730. }
  731. var drawControl = new window.L.Control.Draw(options)
  732. this.map.addControl(drawControl)
  733. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  734. let editableLayer = e.layer
  735. let layerType = e.layerType
  736. editableLayer.on('dblclick', function(e) {
  737. if (layerType === 'polygon' || layerType ===
  738. 'rectangle') {
  739. let latlng = editableLayer.getLatLngs()[0]
  740. _that.showAreaLatLng(latlng)
  741. }
  742. })
  743. editableLayers.addLayer(editableLayer)
  744. })
  745. }
  746. //鼠标绘制线段
  747. if (this.showLineLatLng != undefined) {
  748. var editableLayers = new window.L.FeatureGroup()
  749. this.map.addLayer(editableLayers)
  750. let options = {
  751. position: 'topleft',
  752. draw: {
  753. polyline: {},
  754. polygon: null,
  755. circle: null,
  756. rectangle: null,
  757. circlemarker: null,
  758. marker: null,
  759. remove: {}
  760. },
  761. edit: {
  762. featureGroup: editableLayers,
  763. remove: true
  764. }
  765. }
  766. var drawControl = new window.L.Control.Draw(options)
  767. this.map.addControl(drawControl)
  768. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  769. let editableLayer = e.layer
  770. let layerType = e.layerType
  771. editableLayer.on('dblclick', function(e) {
  772. if (layerType === 'polyline') {
  773. let latlng = editableLayer.getLatLngs()
  774. _that.showLineLatLng(latlng)
  775. }
  776. })
  777. editableLayers.addLayer(editableLayer)
  778. })
  779. }
  780. // url = 'https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China_4326'
  781. window.L.supermap.tiledMapLayer(url).addTo(this.map)
  782. }
  783. })
  784. } else { //卷帘地图
  785. if (this.codes.length != 2) {
  786. modal.msgError('请输入两个地图code!')
  787. return
  788. }
  789. getSuperMap(this.codes).then(resp => {
  790. let mapList = resp.data
  791. if (mapList != null && mapList.length == 2) {
  792. let stamenurl = mapList[0].url
  793. let osmurl = mapList[1].url
  794. let centerLat = mapList[0].centerLat
  795. let centerLng = mapList[0].centerLng
  796. let zoom = mapList[0].zoom //默认比例
  797. let maxZoom = mapList[0].maxZoom //最大比例
  798. let minZoom = mapList[0].minZoom //最小比例
  799. let zoomControl = mapList[0].zoomControl == null ? true : mapList[0]
  800. .zoomControl //地图缩放+-号是否显示
  801. let attributionControl = mapList[0].attributionControl == null ? true : mapList[0]
  802. .attributionControl //logo是否显示
  803. let logoControl = mapList[0].logoControl == null ? false : mapList[0]
  804. .logoControl //logo是否显示
  805. let dragging = mapList[0].dragging == null ? true : mapList[0]
  806. .dragging //地图是否允许鼠标拖拽
  807. let defaultConfigure = {
  808. crs: window.L.CRS.EPSG4326,
  809. center: [centerLat, centerLng],
  810. maxZoom: maxZoom,
  811. minZoom: minZoom,
  812. zoom: zoom,
  813. editable: true,
  814. zoomControl: zoomControl,
  815. attributionControl: attributionControl,
  816. dragging: dragging,
  817. logoControl: logoControl
  818. }
  819. let loadConfiguration = Object.assign(defaultConfigure, mapSite)
  820. this.map = window.L.map(this.mapDiv, loadConfiguration)
  821. //鼠标双击落点
  822. if (this.showLatLng != undefined) {
  823. let icon = new window.L.Icon({
  824. iconUrl: iconList['marker'],
  825. iconSize: [48, 48],
  826. iconAnchor: [24, 40],
  827. popupAnchor: [-3, -40],
  828. shadowSize: [41, 41]
  829. })
  830. this.map.on('dblclick', function(e) {
  831. _that.clearP()
  832. _that.showLatLng(e.latlng.lat, e.latlng.lng)
  833. let marker = window.L.marker([e.latlng.lat, e.latlng.lng], {
  834. icon: icon
  835. }).addTo(this.map)
  836. _that.latLngLayers.push(marker)
  837. _that.latLngGroup = window.L.layerGroup(_that.latLngLayers)
  838. this.map.addLayer(_that.latLngGroup)
  839. })
  840. }
  841. //鼠标绘制区域
  842. if (this.showAreaLatLng != undefined) {
  843. var editableLayers = new window.L.FeatureGroup()
  844. this.map.addLayer(editableLayers)
  845. let options = {
  846. position: 'topleft',
  847. draw: {
  848. polyline: null,
  849. polygon: {},
  850. circle: null,
  851. rectangle: null,
  852. circlemarker: null,
  853. marker: null,
  854. remove: {}
  855. },
  856. edit: {
  857. featureGroup: editableLayers,
  858. remove: true
  859. }
  860. }
  861. var drawControl = new window.L.Control.Draw(options)
  862. this.map.addControl(drawControl)
  863. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  864. let editableLayer = e.layer
  865. let layerType = e.layerType
  866. editableLayer.on('dblclick', function(e) {
  867. if (layerType === 'polygon' || layerType ===
  868. 'rectangle') {
  869. let latlng = editableLayer.getLatLngs()[0]
  870. _that.showAreaLatLng(latlng)
  871. }
  872. })
  873. editableLayers.addLayer(editableLayer)
  874. })
  875. }
  876. //鼠标绘制线段
  877. if (this.showLineLatLng != undefined) {
  878. var editableLayers = new window.L.FeatureGroup()
  879. this.map.addLayer(editableLayers)
  880. let options = {
  881. position: 'topleft',
  882. draw: {
  883. polyline: {},
  884. polygon: null,
  885. circle: null,
  886. rectangle: null,
  887. circlemarker: null,
  888. marker: null,
  889. remove: {}
  890. },
  891. edit: {
  892. featureGroup: editableLayers,
  893. remove: true
  894. }
  895. }
  896. var drawControl = new window.L.Control.Draw(options)
  897. this.map.addControl(drawControl)
  898. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  899. let editableLayer = e.layer
  900. let layerType = e.layerType
  901. editableLayer.on('dblclick', function(e) {
  902. if (layerType === 'polyline') {
  903. let latlng = editableLayer.getLatLngs()
  904. _that.showLineLatLng(latlng)
  905. }
  906. })
  907. editableLayers.addLayer(editableLayer)
  908. })
  909. }
  910. let stamenLayer = window.L.supermap.tiledMapLayer(stamenurl).addTo(this.map)
  911. let osmLayer = window.L.supermap.tiledMapLayer(osmurl).addTo(this.map)
  912. L.control.sideBySide(stamenLayer, osmLayer).addTo(this.map)
  913. }
  914. })
  915. }
  916. },
  917. // 获取面积
  918. /**
  919. * polygon [{lat:30,lng:104},{lat:30,lng:104},{lat:30,lng:104}]
  920. */
  921. formatArea: function(polygon) {
  922. //L.GeometryUtil.geodesicArea(),返回number类型的数据,单位是平方米,这里做了一下转化
  923. var seeArea = window.L.GeometryUtil.geodesicArea(polygon)
  924. let area = (seeArea / 10e5).toFixed(2) + 'k㎡'
  925. return area
  926. },
  927. // 获取长度
  928. /**
  929. * line[{lat:30,lng:104},{lat:30,lng:104},{lat:30,lng:104}]
  930. */
  931. formatLength: function(line) {
  932. let dis = 0
  933. for (let i = 0; i < line.length - 1; i++) {
  934. let start = line[i]
  935. let end = line[i + 1]
  936. dis += window.L.latLng([start.lat, start.lng]).distanceTo([end.lat, end.lng]) //计算两个点之间的距离,并累加
  937. }
  938. //结果得到的也是number类型,单位是 米
  939. return (dis / 10e2).toFixed(2) + 'km'
  940. },
  941. setMarkers: function(markersList) { //地图标点
  942. const _that = this
  943. for (let i = 0; i < markersList.length; i++) {
  944. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  945. .isAggregation //是否聚合点位
  946. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  947. let icon = new window.L.Icon({
  948. iconUrl: iconList[markersList[i].icon],
  949. iconSize: [48, 48],
  950. iconAnchor: [24, 40],
  951. popupAnchor: [-3, -40],
  952. shadowSize: [41, 41]
  953. })
  954. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  955. icon: icon
  956. })
  957. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  958. let html = markersList[i].bindPopupHtml
  959. if (keepBindPopup) {
  960. markerClick.bindPopup(html, {
  961. autoClose: false,
  962. closeOnClick: null,
  963. closeButton: false
  964. }).openPopup(markerClick.getLatLng())
  965. } else {
  966. markerClick.on('mouseover', function() {
  967. let html = markersList[i].bindPopupHtml
  968. this.bindPopup(html).openPopup(this.getLatLng())
  969. }).on('mouseout', function() {
  970. this.closePopup()
  971. })
  972. }
  973. }
  974. if (markersList[i].click != null && markersList[i].click !== '') {
  975. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  976. markerClick.on('click', function() {
  977. let clickName = markersList[i].click
  978. _that.$emit(clickName, markersList[i].parameter)
  979. })
  980. } else {
  981. markerClick.on('click', function() {
  982. let clickName = markersList[i].click
  983. _that.$emit(clickName)
  984. })
  985. }
  986. }
  987. if (isAggregation) {
  988. _that.isAggregationLayers.addLayer(markerClick)
  989. _that.isAggregationMyGroup = window.L.layerGroup(_that.isAggregationLayers)
  990. } else {
  991. _that.layers.push(markerClick)
  992. _that.myGroup = window.L.layerGroup(_that.layers)
  993. }
  994. }
  995. if (_that.myGroup != undefined && _that.myGroup != false) {
  996. _that.map.addLayer(_that.myGroup)
  997. }
  998. _that.map.addLayer(_that.isAggregationLayers)
  999. },
  1000. setMarkersByType: function(markersList, type) { //地图标点(根据类型,可取消落点 clearMByType方法)
  1001. const _that = this
  1002. let lay = []
  1003. let myGroup = []
  1004. for (let i = 0; i < markersList.length; i++) {
  1005. let keepBindPopup = markersList[i].keepBindPopup //提示气泡是否一直显示
  1006. let icon = new window.L.Icon({
  1007. iconUrl: iconList[markersList[i].icon],
  1008. iconSize: [48, 48],
  1009. iconAnchor: [24, 40],
  1010. popupAnchor: [-3, -40],
  1011. shadowSize: [41, 41]
  1012. })
  1013. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  1014. icon: icon
  1015. })
  1016. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  1017. let html = markersList[i].bindPopupHtml
  1018. if (keepBindPopup) {
  1019. markerClick.bindPopup(html, {
  1020. autoClose: false,
  1021. closeOnClick: null,
  1022. closeButton: false
  1023. }).openPopup(markerClick.getLatLng())
  1024. } else {
  1025. markerClick.on('mouseover', function() {
  1026. let html = markersList[i].bindPopupHtml
  1027. this.bindPopup(html).openPopup(this.getLatLng())
  1028. }).on('mouseout', function() {
  1029. this.closePopup()
  1030. })
  1031. }
  1032. }
  1033. if (markersList[i].click != null && markersList[i].click !== '') {
  1034. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  1035. markerClick.on('click', function() {
  1036. let clickName = markersList[i].click
  1037. _that.$emit(clickName, markersList[i].parameter)
  1038. })
  1039. } else {
  1040. markerClick.on('click', function() {
  1041. let clickName = markersList[i].click
  1042. _that.$emit(clickName)
  1043. })
  1044. }
  1045. }
  1046. lay.push(markerClick)
  1047. _that.layersBytype.push({ type: type, marker: markerClick })
  1048. myGroup = window.L.layerGroup(lay)
  1049. _that.myGroupBytype.push({ type: type, myGroup: myGroup })
  1050. this.map.addLayer(myGroup)
  1051. }
  1052. },
  1053. setMarkersRadius: function(markersList) { //地图标点带范围
  1054. const _that = this
  1055. for (let i = 0; i < markersList.length; i++) {
  1056. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  1057. .isAggregation //是否聚合点位
  1058. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  1059. _that.polygon = window.L.circle([markersList[i].lat, markersList[i].lng], {
  1060. radius: markersList[i].radius
  1061. })
  1062. let icon = new window.L.Icon({ //传感器
  1063. iconUrl: iconList[markersList[i].icon],
  1064. iconSize: [48, 48],
  1065. iconAnchor: [24, 40],
  1066. popupAnchor: [-3, -40],
  1067. shadowSize: [41, 41]
  1068. })
  1069. let marker = window.L.marker([markersList[i].lat, markersList[i].lng], {
  1070. icon: icon
  1071. })
  1072. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  1073. let html = markersList[i].bindPopupHtml
  1074. if (keepBindPopup) {
  1075. marker.bindPopup(html, {
  1076. autoClose: false,
  1077. closeOnClick: null,
  1078. closeButton: false
  1079. }).openPopup(marker.getLatLng())
  1080. } else {
  1081. marker.on('mouseover', function() {
  1082. let html = markersList[i].bindPopupHtml
  1083. this.bindPopup(html).openPopup(this.getLatLng())
  1084. }).on('mouseout', function() {
  1085. this.closePopup()
  1086. })
  1087. }
  1088. }
  1089. if (markersList[i].click != null && markersList[i].click != '') {
  1090. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  1091. marker.on('click', function() {
  1092. let clickName = markersList[i].click
  1093. _that.$emit(clickName, markersList[i].parameter)
  1094. })
  1095. } else {
  1096. marker.on('click', function() {
  1097. let clickName = markersList[i].click
  1098. _that.$emit(clickName)
  1099. })
  1100. }
  1101. }
  1102. marker.addTo(this.map)
  1103. if (isAggregation) {
  1104. _that.isAggregationLayers.addLayer(marker)
  1105. _that.radiusLayers.push(_that.polygon)
  1106. this.map.addLayer(_that.isAggregationLayers)
  1107. _that.isAggregationMyGroup = window.L.layerGroup(_that.radiusLayers)
  1108. this.map.addLayer(_that.isAggregationMyGroup)
  1109. } else {
  1110. _that.layers.push(marker)
  1111. _that.layers.push(_that.polygon)
  1112. _that.myGroup = window.L.layerGroup(_that.layers)
  1113. this.map.addLayer(_that.myGroup)
  1114. }
  1115. }
  1116. },
  1117. setConnectList: function(connectList, color) { //地图画线
  1118. const _that = this
  1119. let points = []
  1120. for (let i = 0; i < connectList.length; i++) {
  1121. points.push([connectList[i].lat, connectList[i].lng]) //创建点
  1122. }
  1123. let polyline = window.L.polyline(points, {
  1124. color: color
  1125. })
  1126. if (this.connectLayer != undefined && this.connectLayer != false) {
  1127. _that.connectLayer.addLayer(polyline)
  1128. } else {
  1129. _that.connectLayer = window.L.featureGroup().addTo(this.map)
  1130. _that.connectLayer.addLayer(polyline)
  1131. }
  1132. },
  1133. setConnectTwoList: function(connectList, color) { //地图画线图层2
  1134. const _that = this
  1135. let points = []
  1136. for (let i = 0; i < connectList.length; i++) {
  1137. points.push([connectList[i].lat, connectList[i].lng]) //创建点
  1138. }
  1139. let polyline = window.L.polyline(points, {
  1140. color: color
  1141. })
  1142. if (this.connectLayerTwo != undefined && this.connectLayerTwo != false) {
  1143. _that.connectLayerTwo.addLayer(polyline)
  1144. } else {
  1145. _that.connectLayerTwo = window.L.featureGroup().addTo(this.map)
  1146. _that.connectLayerTwo.addLayer(polyline)
  1147. }
  1148. },
  1149. setGraphicsList: function(graphicsList, color) { //地图图形
  1150. const _that = this
  1151. let points = []
  1152. for (let i = 0; i < graphicsList.length; i++) {
  1153. points.push([graphicsList[i].lat, graphicsList[i].lng]) //创建点
  1154. }
  1155. let polygon = window.L.polygon(points, {
  1156. color: color
  1157. })
  1158. polygon.addTo(this.map)
  1159. if (this.graphicsLayer != undefined && this.graphicsLayer != false) {
  1160. _that.graphicsLayer.addLayer(polygon)
  1161. } else {
  1162. _that.graphicsLayer = window.L.featureGroup().addTo(this.map)
  1163. _that.graphicsLayer.addLayer(polygon)
  1164. }
  1165. },
  1166. dropLocation: function(lat, lng) { //落点定位
  1167. this.map.flyTo([lat, lng], 14, { duration: 2 })
  1168. // this.controlLevel(12)
  1169. // setTimeout(() => {
  1170. // this.map.panTo([lat, lng])
  1171. // }, 1000)
  1172. },
  1173. controlLevel: function(level) { //控制地图缩放级别
  1174. this.map.setZoom(level)
  1175. },
  1176. layerSwitching: function(url, isClear) { //图层切换 url 图层地址 isClear 是否清除图层
  1177. if (isClear) {
  1178. if (this.deckglLayer != null) {
  1179. this.deckglLayer.remove()
  1180. }
  1181. }
  1182. this.deckglLayer = window.L.supermap.tiledMapLayer(url, {})
  1183. this.map.addLayer(this.deckglLayer)
  1184. },
  1185. layerSwitchingList: function(urlList) { //图层切换数组 urlList 图层地址(数组)
  1186. if (this.deckglLayerList != null && this.deckglLayerList.length > 0) {
  1187. for (let i = 0; i < this.deckglLayerList.length; i++) {
  1188. this.deckglLayerList[i].remove()
  1189. }
  1190. }
  1191. if (urlList != null && urlList.length > 0) {
  1192. for (let i = 0; i < urlList.length; i++) {
  1193. this.deckglLayer = window.L.supermap.tiledMapLayer(urlList[i], {})
  1194. this.deckglLayerList.push(this.deckglLayer)
  1195. this.map.addLayer(this.deckglLayer)
  1196. }
  1197. }
  1198. },
  1199. /** ----------------------------------动态绘制开始------------------------------------- */
  1200. clearLayers: function() {
  1201. this.plottingLayer.removeAllFeatures()
  1202. },
  1203. PlottingDrawCancel: function() {
  1204. this.plottingdrawControl.handler.disable()
  1205. },
  1206. dynamicPlotting: function() {
  1207. setTimeout(() => {
  1208. var host = 'https://iserver.supermap.io'
  1209. var serverUrl = host + '/iserver/services/plot-jingyong/rest/plot/'
  1210. var me = this
  1211. this.plottingLayer = window.L.supermap.plotting.plottingLayer('plot',
  1212. serverUrl)
  1213. this.plottingLayer.spatialAnalystUrl =
  1214. host + '/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst'
  1215. this.plottingLayer.addTo(this.map)
  1216. this.plottingdrawControl = window.L.supermap.plotting.drawControl(this
  1217. .plottingLayer)
  1218. this.plottingdrawControl.addTo(this.map)
  1219. var editControl = window.L.supermap.plotting.editControl()
  1220. editControl.addTo(this.map)
  1221. window.L.supermap.plotting.initPlotPanel('plotPanel', serverUrl, this
  1222. .plottingdrawControl)
  1223. }, 2000)
  1224. }
  1225. /** ----------------------------------动态绘制结束------------------------------------- */
  1226. }
  1227. }
  1228. </script>
  1229. <style lang="scss" scoped>
  1230. @import '@/assets/styles/base.scss';
  1231. .panel{
  1232. margin-bottom: .5rem;
  1233. button{
  1234. margin-top: .5rem;
  1235. }
  1236. .input-group{
  1237. display: flex;
  1238. flex-direction: row;
  1239. align-items: center;
  1240. .input-group-addon{
  1241. color: $inBlue;
  1242. }
  1243. .form-control{
  1244. padding: 0 .3rem;
  1245. margin-left: .5rem;
  1246. height: 1.5rem;
  1247. line-height: 1.5rem;
  1248. background-color: #112543;
  1249. color: $inBlue;
  1250. border: 1px $searchBorder;
  1251. }
  1252. }
  1253. }
  1254. .button-group {
  1255. button {
  1256. padding: 0 0.3rem;
  1257. height: 1.5rem;
  1258. background-color: #112543;
  1259. color: #2bacf7;
  1260. border: 1px solid #33467f;
  1261. }
  1262. button:hover {
  1263. border: 1px solid #33467f;
  1264. background-color: #112543;
  1265. text-shadow: 0 0 15px rgba($color: $inBlueHover, $alpha: 1.0);
  1266. }
  1267. }
  1268. </style>