supermap.vue 50 KB

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