supermap.vue 48 KB

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