supermap.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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:55vh;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>
  21. </template>
  22. <script>
  23. // import 'leaflet-side-by-side'
  24. // import '@supermap/iclient-leaflet'
  25. // import 'leaflet/dist/leaflet.css'
  26. // import 'leaflet.markercluster/dist/leaflet.markercluster-src.js'
  27. // import 'leaflet.markercluster/dist/MarkerCluster.css'
  28. // import 'leaflet.markercluster/dist/MarkerCluster.Default.css'
  29. // import 'leaflet-draw'
  30. // import 'leaflet-draw/dist/leaflet.draw.css'
  31. // import L from 'leaflet'
  32. import {
  33. getSuperMap,
  34. iconList
  35. } from '@/api/components/supermap.js'
  36. // import {setToken} from '../plugins/auth'
  37. import modal from '@/plugins/modal'
  38. export default {
  39. name: 'sookaSuperMap',
  40. data() {
  41. return {
  42. plottingdrawControl: null,
  43. plottingLayer: null,
  44. mapDivId: '',
  45. map: null,
  46. layers: [],
  47. layersBytype: [],
  48. isAggregationLayers: [],
  49. radiusLayers: [],
  50. myGroup: [],
  51. myGroupBytype: [],
  52. isAggregationMyGroup: [],
  53. polygon: null,
  54. connectLayer: [],
  55. connectLayerTwo: [],
  56. graphicsLayer: [],
  57. latLngLayers: [],
  58. latLngGroup: [],
  59. isEditableLayers: false, //绘图控件
  60. drawControl: null, //绘图控件
  61. deckglLayer: null, //图层Layer
  62. deckglLayerList: [] //图层Layer(数组)
  63. }
  64. },
  65. watch: {
  66. isEditableLayers: {
  67. handler(newValue, oldValue) {
  68. if (newValue) {
  69. var editableLayers = new window.L.FeatureGroup()
  70. this.map.addLayer(editableLayers)
  71. let options = {
  72. position: 'topleft',
  73. draw: {
  74. polyline: {},
  75. polygon: {},
  76. circle: {},
  77. rectangle: {},
  78. marker: {},
  79. remove: {}
  80. },
  81. edit: {
  82. featureGroup: editableLayers,
  83. remove: true
  84. }
  85. }
  86. this.drawControl = new window.L.Control.Draw(options)
  87. this.map.addControl(this.drawControl)
  88. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  89. let editableLayer = e.layer
  90. let layerType = e.layerType
  91. editableLayer.on('dblclick', function(e) {
  92. if (layerType === 'polygon' || layerType === 'rectangle') {
  93. let latlng = editableLayer.getLatLngs()[0]
  94. //一个自定义的计算面积的函数
  95. var seeArea = window.L.GeometryUtil.geodesicArea(latlng)
  96. let area = (seeArea / 10e5).toFixed(2) + 'k㎡'
  97. modal.msg(area)
  98. } else if (layerType === 'polyline') {
  99. let latlng = editableLayer.getLatLngs()
  100. //一个自定义的计算长度的函数
  101. let dis = 0
  102. for (let i = 0; i < latlng.length - 1; i++) {
  103. let start = latlng[i]
  104. let end = latlng[i + 1]
  105. dis += window.L.latLng([start.lat, start.lng]).distanceTo([end.lat,
  106. end.lng
  107. ]) //计算两个点之间的距离,并累加
  108. }
  109. //结果得到的也是number类型,单位是KM
  110. modal.msg((dis / 10e2).toFixed(2) + 'km')
  111. }
  112. })
  113. if (layerType === 'marker') {
  114. let icon = new window.L.Icon({
  115. iconUrl: iconList['marker'],
  116. iconSize: [48, 48],
  117. iconAnchor: [24, 40],
  118. popupAnchor: [-3, -40],
  119. shadowSize: [41, 41]
  120. })
  121. editableLayer.options.icon = icon
  122. }
  123. editableLayers.addLayer(editableLayer)
  124. })
  125. } else {
  126. this.map.removeControl(this.drawControl)
  127. }
  128. }
  129. }
  130. },
  131. mounted() {
  132. this.initMap()
  133. //添加画图的提示信息
  134. window.L.drawLocal.draw.toolbar = {
  135. actions: {
  136. title: '取消绘图',
  137. text: '取消'
  138. },
  139. finish: {
  140. title: '完成绘图',
  141. text: '完成'
  142. },
  143. undo: {
  144. title: '删除最后绘制的点',
  145. text: '删除最后一个点'
  146. },
  147. buttons: {
  148. polyline: '绘制折线',
  149. polygon: '绘制多边形',
  150. rectangle: '绘制矩形',
  151. circle: '绘制圆圈',
  152. marker: '绘制标记',
  153. circlemarker: '绘制圆圈标记'
  154. }
  155. }
  156. window.L.drawLocal.draw.handlers = {
  157. circle: {
  158. tooltip: {
  159. start: '单击并拖动以绘制圆形'
  160. },
  161. radius: '半径'
  162. },
  163. circlemarker: {
  164. tooltip: {
  165. start: '点击地图放置圆圈标记'
  166. }
  167. },
  168. marker: {
  169. tooltip: {
  170. start: '点击地图放置标记'
  171. }
  172. },
  173. polygon: {
  174. tooltip: {
  175. start: '点击开始绘制形状',
  176. cont: '点击继续绘制形状',
  177. end: '单击第一个点以关闭此形状'
  178. }
  179. },
  180. polyline: {
  181. error: '<strong>Error:</strong> shape edges cannot cross!',
  182. tooltip: {
  183. start: '点击开始画线',
  184. cont: '点击继续画线',
  185. end: '单击最后一点以完成线'
  186. }
  187. },
  188. rectangle: {
  189. tooltip: {
  190. start: '单击并拖动以绘制矩形'
  191. }
  192. },
  193. simpleshape: {
  194. tooltip: {
  195. end: '释放鼠标完成绘图'
  196. }
  197. }
  198. }
  199. window.L.drawLocal.edit = {
  200. toolbar: {
  201. actions: {
  202. save: {
  203. title: '保存更改',
  204. text: '保存'
  205. },
  206. cancel: {
  207. title: '取消编辑,放弃所有更改',
  208. text: '取消'
  209. },
  210. clearAll: {
  211. title: '清除所有图层',
  212. text: '清除所有'
  213. }
  214. },
  215. buttons: {
  216. edit: '编辑图层',
  217. editDisabled: '没有可编辑的图层',
  218. remove: '删除图层',
  219. removeDisabled: '没有可删除的图层'
  220. }
  221. },
  222. handlers: {
  223. edit: {
  224. tooltip: {
  225. text: '拖动手柄或标记以编辑要素',
  226. subtext: '单击取消以撤消更改'
  227. }
  228. },
  229. remove: {
  230. tooltip: {
  231. text: '单击要删除的功能'
  232. }
  233. }
  234. }
  235. }
  236. },
  237. props: {
  238. mapDiv: null,
  239. codes: null,
  240. mapSite: {},
  241. isdynamicPlotting: false,//动态标绘表格
  242. isSideBySide: false,
  243. showLatLng: null,
  244. showAreaLatLng: null,
  245. showLineLatLng: null
  246. },
  247. methods: {
  248. clearM: async function(isAggregation) { //清理地图标点
  249. if (isAggregation) {
  250. if (this.isAggregationMyGroup != undefined && this.isAggregationMyGroup != false) {
  251. this.isAggregationMyGroup.clearLayers()
  252. }
  253. if (this.isAggregationLayers != null && this.isAggregationLayers.length > 0) {
  254. this.map.removeLayer(this.isAggregationLayers)
  255. this.isAggregationLayers = []
  256. this.radiusLayers = []
  257. this.isAggregationLayers = window.L.markerClusterGroup({
  258. //设置为true时显示聚类所占据的范围
  259. showCoverageOnHover: true,
  260. //设置为true时会向低一级聚类缩放
  261. zoomToBoundsOnClick: true,
  262. //增加点位时增加聚合动画(否则会出问题)
  263. animateAddingMarkers: true,
  264. //最大缩放级别点击聚合图标展开图标
  265. spiderfyOnMaxZoom: true
  266. })
  267. }
  268. } else {
  269. if (this.myGroup != undefined && this.myGroup != false) {
  270. this.myGroup.clearLayers()
  271. }
  272. this.layers = []
  273. }
  274. },
  275. clearMByType: async function(type) { //清理地图标点(根据类型,可取消落点)
  276. if (this.myGroupBytype != undefined && this.myGroupBytype != false) {
  277. for (var i = this.myGroupBytype.length - 1; i >= 0; i--) {
  278. if (this.myGroupBytype[i].type == type) {
  279. this.myGroupBytype[i].myGroup.clearLayers()
  280. this.myGroupBytype.splice(i, 1)
  281. }
  282. }
  283. }
  284. if (this.layersBytype != null && this.layersBytype.length > 0) {
  285. for (var i = this.layersBytype.length - 1; i >= 0; i--) {
  286. if (this.layersBytype[i].type == type) {
  287. this.layersBytype.splice(i, 1)
  288. }
  289. }
  290. }
  291. },
  292. clearC: async function() { //清理地图画线
  293. if (this.connectLayer != undefined && this.connectLayer != false) {
  294. this.connectLayer.clearLayers()
  295. }
  296. this.connectLayer = []
  297. },
  298. clearCTwo: async function() { //清理地图画线two
  299. if (this.connectLayerTwo != undefined && this.connectLayerTwo != false) {
  300. this.connectLayerTwo.clearLayers()
  301. }
  302. this.connectLayerTwo = []
  303. },
  304. clearG: async function() { //清理地图图形
  305. if (this.graphicsLayer != undefined && this.graphicsLayer != false) {
  306. this.graphicsLayer.clearLayers()
  307. }
  308. this.graphicsLayer = []
  309. },
  310. clearP: async function() { //清理点击事件落点
  311. if (this.latLngGroup != undefined && this.latLngGroup != false) {
  312. this.latLngGroup.clearLayers()
  313. }
  314. this.latLngLayers = []
  315. },
  316. initMap: function() {
  317. let _that = this
  318. this.mapDivId = this.mapDiv
  319. let mapSite = this.mapSite
  320. let isSideBySide = this.isSideBySide
  321. let isdynamicPlotting = this.isdynamicPlotting
  322. // setToken("eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImY5Zjg3ZjVmLWQ4NTctNDQxZC04NmQ5LTg4OWExZWRlODE4ZSIsInVzZXJuYW1lIjoiYWRtaW4ifQ.26mAzmaM9pUza9585aLnRMyRd4GxvrWbCxN0erYsuiBDYQiYnyc-TwXVNDI7Xrpt3Bqmbnul-XMszOxYQi12LA");
  323. _that.isAggregationLayers = window.L.markerClusterGroup({
  324. //设置为true时显示聚类所占据的范围
  325. showCoverageOnHover: true,
  326. //设置为true时会向低一级聚类缩放
  327. zoomToBoundsOnClick: true,
  328. //增加点位时增加聚合动画(否则会出问题)
  329. animateAddingMarkers: true,
  330. //最大缩放级别点击聚合图标展开图标
  331. spiderfyOnMaxZoom: true
  332. })
  333. if (!isSideBySide) { //只有一个地图
  334. if (this.codes.length != 1) {
  335. modal.msgError('请输入一个地图code!')
  336. return
  337. }
  338. getSuperMap(this.codes).then(resp => {
  339. let mapList = resp.data
  340. if (mapList != null && mapList.length > 0) {
  341. let url = mapList[0].url
  342. let centerLat = mapList[0].centerLat
  343. let centerLng = mapList[0].centerLng
  344. let zoom = mapList[0].zoom //默认比例
  345. let maxZoom = mapList[0].maxZoom //最大比例
  346. let minZoom = mapList[0].minZoom //最小比例
  347. let zoomControl = mapList[0].zoomControl == null ? true : mapList[0]
  348. .zoomControl //地图缩放+-号是否显示
  349. let attributionControl = mapList[0].attributionControl == null ? true : mapList[0]
  350. .attributionControl //logo是否显示
  351. let logoControl = mapList[0].logoControl == null ? false : mapList[0]
  352. .logoControl //logo是否显示
  353. let dragging = mapList[0].dragging == null ? true : mapList[0]
  354. .dragging //地图是否允许鼠标拖拽
  355. let defaultConfigure = {
  356. crs: window.L.CRS.EPSG4326,
  357. center: [centerLat, centerLng],
  358. maxZoom: maxZoom,
  359. minZoom: minZoom,
  360. zoom: zoom,
  361. editable: true,
  362. zoomControl: zoomControl,
  363. attributionControl: attributionControl,
  364. dragging: dragging,
  365. logoControl: logoControl
  366. }
  367. let loadConfiguration = Object.assign(defaultConfigure, mapSite)
  368. this.map = window.L.map(this.mapDiv, loadConfiguration)
  369. //鼠标双击落点
  370. if (this.showLatLng != undefined) {
  371. let icon = new window.L.Icon({
  372. iconUrl: iconList['marker'],
  373. iconSize: [48, 48],
  374. iconAnchor: [24, 40],
  375. popupAnchor: [-3, -40],
  376. shadowSize: [41, 41]
  377. })
  378. this.map.on('dblclick', function(e) {
  379. _that.clearP()
  380. _that.showLatLng(e.latlng.lat, e.latlng.lng)
  381. let marker = window.L.marker([e.latlng.lat, e.latlng.lng], {
  382. icon: icon
  383. }).addTo(this.map)
  384. _that.latLngLayers.push(marker)
  385. _that.latLngGroup = window.L.layerGroup(_that.latLngLayers)
  386. this.map.addLayer(_that.latLngGroup)
  387. })
  388. }
  389. //鼠标绘制区域
  390. if (this.showAreaLatLng != undefined) {
  391. var editableLayers = new window.L.FeatureGroup()
  392. this.map.addLayer(editableLayers)
  393. let options = {
  394. position: 'topleft',
  395. draw: {
  396. polyline: null,
  397. polygon: {},
  398. circle: null,
  399. rectangle: null,
  400. circlemarker: null,
  401. marker: null,
  402. remove: {}
  403. },
  404. edit: {
  405. featureGroup: editableLayers,
  406. remove: true
  407. }
  408. }
  409. var drawControl = new window.L.Control.Draw(options)
  410. this.map.addControl(drawControl)
  411. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  412. let editableLayer = e.layer
  413. let layerType = e.layerType
  414. editableLayer.on('dblclick', function(e) {
  415. if (layerType === 'polygon' || layerType ===
  416. 'rectangle') {
  417. let latlng = editableLayer.getLatLngs()[0]
  418. _that.showAreaLatLng(latlng)
  419. }
  420. })
  421. editableLayers.addLayer(editableLayer)
  422. })
  423. }
  424. //鼠标绘制线段
  425. if (this.showLineLatLng != undefined) {
  426. var editableLayers = new window.L.FeatureGroup()
  427. this.map.addLayer(editableLayers)
  428. let options = {
  429. position: 'topleft',
  430. draw: {
  431. polyline: {},
  432. polygon: null,
  433. circle: null,
  434. rectangle: null,
  435. circlemarker: null,
  436. marker: null,
  437. remove: {}
  438. },
  439. edit: {
  440. featureGroup: editableLayers,
  441. remove: true
  442. }
  443. }
  444. var drawControl = new window.L.Control.Draw(options)
  445. this.map.addControl(drawControl)
  446. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  447. let editableLayer = e.layer
  448. let layerType = e.layerType
  449. editableLayer.on('dblclick', function(e) {
  450. if (layerType === 'polyline') {
  451. let latlng = editableLayer.getLatLngs()
  452. _that.showLineLatLng(latlng)
  453. }
  454. })
  455. editableLayers.addLayer(editableLayer)
  456. })
  457. }
  458. // url = 'https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China_4326'
  459. window.L.supermap.tiledMapLayer(url).addTo(this.map)
  460. }
  461. })
  462. } else { //卷帘地图
  463. if (this.codes.length != 2) {
  464. modal.msgError('请输入两个地图code!')
  465. return
  466. }
  467. getSuperMap(this.codes).then(resp => {
  468. let mapList = resp.data
  469. if (mapList != null && mapList.length == 2) {
  470. let stamenurl = mapList[0].url
  471. let osmurl = mapList[1].url
  472. let centerLat = mapList[0].centerLat
  473. let centerLng = mapList[0].centerLng
  474. let zoom = mapList[0].zoom //默认比例
  475. let maxZoom = mapList[0].maxZoom //最大比例
  476. let minZoom = mapList[0].minZoom //最小比例
  477. let zoomControl = mapList[0].zoomControl == null ? true : mapList[0]
  478. .zoomControl //地图缩放+-号是否显示
  479. let attributionControl = mapList[0].attributionControl == null ? true : mapList[0]
  480. .attributionControl //logo是否显示
  481. let logoControl = mapList[0].logoControl == null ? false : mapList[0]
  482. .logoControl //logo是否显示
  483. let dragging = mapList[0].dragging == null ? true : mapList[0]
  484. .dragging //地图是否允许鼠标拖拽
  485. let defaultConfigure = {
  486. crs: window.L.CRS.EPSG4326,
  487. center: [centerLat, centerLng],
  488. maxZoom: maxZoom,
  489. minZoom: minZoom,
  490. zoom: zoom,
  491. editable: true,
  492. zoomControl: zoomControl,
  493. attributionControl: attributionControl,
  494. dragging: dragging,
  495. logoControl: logoControl
  496. }
  497. let loadConfiguration = Object.assign(defaultConfigure, mapSite)
  498. this.map = window.L.map(this.mapDiv, loadConfiguration)
  499. //鼠标双击落点
  500. if (this.showLatLng != undefined) {
  501. let icon = new window.L.Icon({
  502. iconUrl: iconList['marker'],
  503. iconSize: [48, 48],
  504. iconAnchor: [24, 40],
  505. popupAnchor: [-3, -40],
  506. shadowSize: [41, 41]
  507. })
  508. this.map.on('dblclick', function(e) {
  509. _that.clearP()
  510. _that.showLatLng(e.latlng.lat, e.latlng.lng)
  511. let marker = window.L.marker([e.latlng.lat, e.latlng.lng], {
  512. icon: icon
  513. }).addTo(this.map)
  514. _that.latLngLayers.push(marker)
  515. _that.latLngGroup = window.L.layerGroup(_that.latLngLayers)
  516. this.map.addLayer(_that.latLngGroup)
  517. })
  518. }
  519. //鼠标绘制区域
  520. if (this.showAreaLatLng != undefined) {
  521. var editableLayers = new window.L.FeatureGroup()
  522. this.map.addLayer(editableLayers)
  523. let options = {
  524. position: 'topleft',
  525. draw: {
  526. polyline: null,
  527. polygon: {},
  528. circle: null,
  529. rectangle: null,
  530. circlemarker: null,
  531. marker: null,
  532. remove: {}
  533. },
  534. edit: {
  535. featureGroup: editableLayers,
  536. remove: true
  537. }
  538. }
  539. var drawControl = new window.L.Control.Draw(options)
  540. this.map.addControl(drawControl)
  541. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  542. let editableLayer = e.layer
  543. let layerType = e.layerType
  544. editableLayer.on('dblclick', function(e) {
  545. if (layerType === 'polygon' || layerType ===
  546. 'rectangle') {
  547. let latlng = editableLayer.getLatLngs()[0]
  548. _that.showAreaLatLng(latlng)
  549. }
  550. })
  551. editableLayers.addLayer(editableLayer)
  552. })
  553. }
  554. //鼠标绘制线段
  555. if (this.showLineLatLng != undefined) {
  556. var editableLayers = new window.L.FeatureGroup()
  557. this.map.addLayer(editableLayers)
  558. let options = {
  559. position: 'topleft',
  560. draw: {
  561. polyline: {},
  562. polygon: null,
  563. circle: null,
  564. rectangle: null,
  565. circlemarker: null,
  566. marker: null,
  567. remove: {}
  568. },
  569. edit: {
  570. featureGroup: editableLayers,
  571. remove: true
  572. }
  573. }
  574. var drawControl = new window.L.Control.Draw(options)
  575. this.map.addControl(drawControl)
  576. this.map.on(window.L.Draw.Event.CREATED, function(e) {
  577. let editableLayer = e.layer
  578. let layerType = e.layerType
  579. editableLayer.on('dblclick', function(e) {
  580. if (layerType === 'polyline') {
  581. let latlng = editableLayer.getLatLngs()
  582. _that.showLineLatLng(latlng)
  583. }
  584. })
  585. editableLayers.addLayer(editableLayer)
  586. })
  587. }
  588. let stamenLayer = window.L.supermap.tiledMapLayer(stamenurl).addTo(this.map)
  589. let osmLayer = window.L.supermap.tiledMapLayer(osmurl).addTo(this.map)
  590. L.control.sideBySide(stamenLayer, osmLayer).addTo(this.map)
  591. }
  592. })
  593. }
  594. },
  595. // 获取面积
  596. /**
  597. * polygon [{lat:30,lng:104},{lat:30,lng:104},{lat:30,lng:104}]
  598. */
  599. formatArea: function(polygon) {
  600. //L.GeometryUtil.geodesicArea(),返回number类型的数据,单位是平方米,这里做了一下转化
  601. var seeArea = window.L.GeometryUtil.geodesicArea(polygon)
  602. let area = (seeArea / 10e5).toFixed(2) + 'k㎡'
  603. return area
  604. },
  605. // 获取长度
  606. /**
  607. * line[{lat:30,lng:104},{lat:30,lng:104},{lat:30,lng:104}]
  608. */
  609. formatLength: function(line) {
  610. let dis = 0
  611. for (let i = 0; i < line.length - 1; i++) {
  612. let start = line[i]
  613. let end = line[i + 1]
  614. dis += window.L.latLng([start.lat, start.lng]).distanceTo([end.lat, end.lng]) //计算两个点之间的距离,并累加
  615. }
  616. //结果得到的也是number类型,单位是 米
  617. return (dis / 10e2).toFixed(2) + 'km'
  618. },
  619. setMarkers: function(markersList) { //地图标点
  620. const _that = this
  621. for (let i = 0; i < markersList.length; i++) {
  622. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  623. .isAggregation //是否聚合点位
  624. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  625. let icon = new window.L.Icon({
  626. iconUrl: iconList[markersList[i].icon],
  627. iconSize: [48, 48],
  628. iconAnchor: [24, 40],
  629. popupAnchor: [-3, -40],
  630. shadowSize: [41, 41]
  631. })
  632. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  633. icon: icon
  634. }).addTo(this.map)
  635. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  636. let html = markersList[i].bindPopupHtml
  637. if (keepBindPopup) {
  638. markerClick.bindPopup(html, {
  639. autoClose: false,
  640. closeOnClick: null,
  641. closeButton: false
  642. }).openPopup(markerClick.getLatLng())
  643. } else {
  644. markerClick.on('mouseover', function() {
  645. let html = markersList[i].bindPopupHtml
  646. this.bindPopup(html).openPopup(this.getLatLng())
  647. }).on('mouseout', function() {
  648. this.closePopup()
  649. })
  650. }
  651. }
  652. if (markersList[i].click != null && markersList[i].click !== '') {
  653. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  654. markerClick.on('click', function() {
  655. let clickName = markersList[i].click
  656. _that.$emit(clickName, markersList[i].parameter)
  657. })
  658. } else {
  659. markerClick.on('click', function() {
  660. let clickName = markersList[i].click
  661. _that.$emit(clickName)
  662. })
  663. }
  664. }
  665. if (isAggregation) {
  666. _that.isAggregationLayers.addLayer(markerClick)
  667. _that.isAggregationMyGroup = window.L.layerGroup(_that.isAggregationLayers)
  668. this.map.addLayer(_that.isAggregationLayers)
  669. } else {
  670. _that.layers.push(markerClick)
  671. _that.myGroup = window.L.layerGroup(_that.layers)
  672. this.map.addLayer(_that.myGroup)
  673. }
  674. }
  675. },
  676. setMarkersByType: function(markersList, type) { //地图标点(根据类型,可取消落点 clearMByType方法)
  677. const _that = this
  678. let lay = []
  679. let myGroup = []
  680. for (let i = 0; i < markersList.length; i++) {
  681. let keepBindPopup = markersList[i].keepBindPopup //提示气泡是否一直显示
  682. let icon = new window.L.Icon({
  683. iconUrl: iconList[markersList[i].icon],
  684. iconSize: [48, 48],
  685. iconAnchor: [24, 40],
  686. popupAnchor: [-3, -40],
  687. shadowSize: [41, 41]
  688. })
  689. let markerClick = window.L.marker([markersList[i].lat, markersList[i].lng], {
  690. icon: icon
  691. }).addTo(this.map)
  692. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  693. let html = markersList[i].bindPopupHtml
  694. if (keepBindPopup) {
  695. markerClick.bindPopup(html, {
  696. autoClose: false,
  697. closeOnClick: null,
  698. closeButton: false
  699. }).openPopup(markerClick.getLatLng())
  700. } else {
  701. markerClick.on('mouseover', function() {
  702. let html = markersList[i].bindPopupHtml
  703. this.bindPopup(html).openPopup(this.getLatLng())
  704. }).on('mouseout', function() {
  705. this.closePopup()
  706. })
  707. }
  708. }
  709. if (markersList[i].click != null && markersList[i].click !== '') {
  710. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  711. markerClick.on('click', function() {
  712. let clickName = markersList[i].click
  713. _that.$emit(clickName, markersList[i].parameter)
  714. })
  715. } else {
  716. markerClick.on('click', function() {
  717. let clickName = markersList[i].click
  718. _that.$emit(clickName)
  719. })
  720. }
  721. }
  722. lay.push(markerClick)
  723. _that.layersBytype.push({ type: type, marker: markerClick })
  724. myGroup = window.L.layerGroup(lay)
  725. _that.myGroupBytype.push({ type: type, myGroup: myGroup })
  726. this.map.addLayer(myGroup)
  727. }
  728. },
  729. setMarkersRadius: function(markersList) { //地图标点带范围
  730. const _that = this
  731. for (let i = 0; i < markersList.length; i++) {
  732. let isAggregation = markersList[i].isAggregation == null ? false : markersList[i]
  733. .isAggregation //是否聚合点位
  734. let keepBindPopup = isAggregation == true ? false : markersList[i].keepBindPopup //提示气泡是否一直显示
  735. _that.polygon = window.L.circle([markersList[i].lat, markersList[i].lng], {
  736. radius: markersList[i].radius
  737. })
  738. let icon = new window.L.Icon({ //传感器
  739. iconUrl: iconList[markersList[i].icon],
  740. iconSize: [48, 48],
  741. iconAnchor: [24, 40],
  742. popupAnchor: [-3, -40],
  743. shadowSize: [41, 41]
  744. })
  745. let marker = window.L.marker([markersList[i].lat, markersList[i].lng], {
  746. icon: icon
  747. })
  748. if (markersList[i].bindPopupHtml != null && markersList[i].bindPopupHtml !== '') {
  749. let html = markersList[i].bindPopupHtml
  750. if (keepBindPopup) {
  751. marker.bindPopup(html, {
  752. autoClose: false,
  753. closeOnClick: null,
  754. closeButton: false
  755. }).openPopup(marker.getLatLng())
  756. } else {
  757. marker.on('mouseover', function() {
  758. let html = markersList[i].bindPopupHtml
  759. this.bindPopup(html).openPopup(this.getLatLng())
  760. }).on('mouseout', function() {
  761. this.closePopup()
  762. })
  763. }
  764. }
  765. if (markersList[i].click != null && markersList[i].click != '') {
  766. if (markersList[i].parameter != null && markersList[i].parameter !== '') {
  767. marker.on('click', function() {
  768. let clickName = markersList[i].click
  769. _that.$emit(clickName, markersList[i].parameter)
  770. })
  771. } else {
  772. marker.on('click', function() {
  773. let clickName = markersList[i].click
  774. _that.$emit(clickName)
  775. })
  776. }
  777. }
  778. marker.addTo(this.map)
  779. if (isAggregation) {
  780. _that.isAggregationLayers.addLayer(marker)
  781. _that.radiusLayers.push(_that.polygon)
  782. this.map.addLayer(_that.isAggregationLayers)
  783. _that.isAggregationMyGroup = window.L.layerGroup(_that.radiusLayers)
  784. this.map.addLayer(_that.isAggregationMyGroup)
  785. } else {
  786. _that.layers.push(marker)
  787. _that.layers.push(_that.polygon)
  788. _that.myGroup = window.L.layerGroup(_that.layers)
  789. this.map.addLayer(_that.myGroup)
  790. }
  791. }
  792. },
  793. setConnectList: function(connectList, color) { //地图画线
  794. const _that = this
  795. let points = []
  796. for (let i = 0; i < connectList.length; i++) {
  797. points.push([connectList[i].lat, connectList[i].lng]) //创建点
  798. }
  799. let polyline = window.L.polyline(points, {
  800. color: color
  801. })
  802. if (this.connectLayer != undefined && this.connectLayer != false) {
  803. _that.connectLayer.addLayer(polyline)
  804. } else {
  805. _that.connectLayer = window.L.featureGroup().addTo(this.map)
  806. _that.connectLayer.addLayer(polyline)
  807. }
  808. },
  809. setConnectTwoList: function(connectList, color) { //地图画线图层2
  810. const _that = this
  811. let points = []
  812. for (let i = 0; i < connectList.length; i++) {
  813. points.push([connectList[i].lat, connectList[i].lng]) //创建点
  814. }
  815. let polyline = window.L.polyline(points, {
  816. color: color
  817. })
  818. if (this.connectLayerTwo != undefined && this.connectLayerTwo != false) {
  819. _that.connectLayerTwo.addLayer(polyline)
  820. } else {
  821. _that.connectLayerTwo = window.L.featureGroup().addTo(this.map)
  822. _that.connectLayerTwo.addLayer(polyline)
  823. }
  824. },
  825. setGraphicsList: function(graphicsList, color) { //地图图形
  826. const _that = this
  827. let points = []
  828. for (let i = 0; i < graphicsList.length; i++) {
  829. points.push([graphicsList[i].lat, graphicsList[i].lng]) //创建点
  830. }
  831. let polygon = window.L.polygon(points, {
  832. color: color
  833. })
  834. polygon.addTo(this.map)
  835. if (this.graphicsLayer != undefined && this.graphicsLayer != false) {
  836. _that.graphicsLayer.addLayer(polygon)
  837. } else {
  838. _that.graphicsLayer = window.L.featureGroup().addTo(this.map)
  839. _that.graphicsLayer.addLayer(polygon)
  840. }
  841. },
  842. dropLocation: function(lat, lng) { //落点定位
  843. this.map.flyTo([lat, lng], 14, { duration: 2 })
  844. // this.controlLevel(12)
  845. // setTimeout(() => {
  846. // this.map.panTo([lat, lng])
  847. // }, 1000)
  848. },
  849. controlLevel: function(level) { //控制地图缩放级别
  850. this.map.setZoom(level)
  851. },
  852. layerSwitching: function(url, isClear) { //图层切换 url 图层地址 isClear 是否清除图层
  853. if (isClear) {
  854. if (this.deckglLayer != null) {
  855. this.deckglLayer.remove()
  856. }
  857. }
  858. this.deckglLayer = window.L.supermap.tiledMapLayer(url, {})
  859. this.map.addLayer(this.deckglLayer)
  860. },
  861. layerSwitchingList: function(urlList) { //图层切换数组 urlList 图层地址(数组)
  862. if (this.deckglLayerList != null && this.deckglLayerList.length > 0) {
  863. for (let i = 0; i < this.deckglLayerList.length; i++) {
  864. this.deckglLayerList[i].remove()
  865. }
  866. }
  867. if (urlList != null && urlList.length > 0) {
  868. for (let i = 0; i < urlList.length; i++) {
  869. this.deckglLayer = window.L.supermap.tiledMapLayer(urlList[i], {})
  870. this.deckglLayerList.push(this.deckglLayer)
  871. this.map.addLayer(this.deckglLayer)
  872. }
  873. }
  874. },
  875. /** ----------------------------------动态绘制开始------------------------------------- */
  876. clearLayers: function() {
  877. this.plottingLayer.removeAllFeatures()
  878. },
  879. PlottingDrawCancel: function() {
  880. this.plottingdrawControl.handler.disable()
  881. },
  882. dynamicPlotting: function() {
  883. setTimeout(() => {
  884. var host = 'https://iserver.supermap.io'
  885. var serverUrl = host + '/iserver/services/plot-jingyong/rest/plot/'
  886. var me = this
  887. this.plottingLayer = window.L.supermap.plotting.plottingLayer('plot',
  888. serverUrl)
  889. this.plottingLayer.spatialAnalystUrl =
  890. host + '/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst'
  891. this.plottingLayer.addTo(this.map)
  892. this.plottingdrawControl = window.L.supermap.plotting.drawControl(this
  893. .plottingLayer)
  894. this.plottingdrawControl.addTo(this.map)
  895. var editControl = window.L.supermap.plotting.editControl()
  896. editControl.addTo(this.map)
  897. window.L.supermap.plotting.initPlotPanel('plotPanel', serverUrl, this
  898. .plottingdrawControl)
  899. }, 2000)
  900. }
  901. /** ----------------------------------动态绘制结束------------------------------------- */
  902. }
  903. }
  904. </script>
  905. <style lang="scss" scoped>
  906. @import '@/assets/styles/base.scss';
  907. .button-group {
  908. button {
  909. padding: 0 0.3rem;
  910. height: 1.5rem;
  911. background-color: #112543;
  912. color: #2bacf7;
  913. border: 1px solid #33467f;
  914. }
  915. button:hover {
  916. border: 1px solid #33467f;
  917. background-color: #112543;
  918. text-shadow: 0 0 15px rgba($color: $inBlueHover, $alpha: 1.0);
  919. }
  920. }
  921. </style>