supermap.vue 48 KB

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