map-data.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. import axios from 'axios';
  2. export default {
  3. data() {
  4. return {
  5. // icon1: require('@a/img/icon/szWater.png'),
  6. // icon2: require('@a/img/icon/sqWater.png'),
  7. icon1: require('@a/img/icon/qx.png'),
  8. icon2: require('@a/img/icon/jy.png'),
  9. icon3: require('@a/img/icon/hz.png'),
  10. map: null,
  11. time: false,
  12. mapPolList: [],
  13. colorList: [
  14. ['#99e', "#F33"],
  15. ['#ee6', "#c38"],
  16. ['#c38', "#F33"],
  17. ['#6E7', '#F33'],
  18. ['#6A7', "#F33"],
  19. ['#EF7', "#F33"],
  20. ['#AF7', "#F33"],
  21. ['#BAC', "#F33"],
  22. ['#BEF', "#F33"],
  23. ['#BBB', "#F33"],
  24. ['#EFA', "#F33"],
  25. ['#FE6', "#F33"],
  26. ['#7F6', "#F33"],
  27. ['#7dc', "#F33"],
  28. ],
  29. colorIndList: [-1, 7, 21, 26, 31, 37, 46, 52, 57, 66, 68, 71, 74, 100],
  30. oldPopup: null,
  31. oldPopupId: null,
  32. }
  33. },
  34. computed: {
  35. mapWidth: function() {
  36. //这里的this指向的是当前的vue实例
  37. return this.$refs.mapF.$el.offsetWidth / 2 + 'px'
  38. },
  39. mapHeight: function() {
  40. //这里的this指向的是当前的vue实例
  41. return this.$refs.mapF.$el.offsetHeight / 2 - 40 + 'px'
  42. }
  43. },
  44. mounted() {
  45. window.vue = this;
  46. window.jMap = null;
  47. window.jmapQuery = null;
  48. },
  49. methods: {
  50. /**
  51. * @地图初始化
  52. */
  53. async initMap() {
  54. window.vue = this;
  55. window.jMap = null;
  56. window.jmapQuery = null;
  57. window.jMap = new JMap();
  58. var map_params = {
  59. camera: {
  60. x: 121.4175597,
  61. y: 31.1192480,
  62. radius: 18000.0,
  63. offset: { heading: -4, pitch: -70, range: 0 }
  64. },
  65. map_complete_callback: () => {
  66. window.jmapQuery = new JMapQuery(window.jMap);
  67. // ToDo...
  68. },
  69. map_left_click_callback: (obj, type, movement) => {
  70. },
  71. map_right_click_callback: (obj) => {
  72. },
  73. };
  74. // let res = await this.$axios.get("/api/atlas/encrypt")
  75. let res = await this.$axios.get(this.$api.dt) //sing
  76. // 加载地图
  77. window.jMap.createMap("mapF", res.data, window.location.origin, map_params, {});
  78. // 地图样式
  79. window.jMap.switchBaseLayer('dark')
  80. //window.jMap.switchBaseLayer('light')
  81. // 增加街镇边界
  82. let options = {
  83. click: (val) => {
  84. console.log(val)
  85. },
  86. isZoom: false,
  87. style: {
  88. outline: true,
  89. outlineColor: 'red',
  90. // material:'rgb(0,0,0)',
  91. // perPostionHeight: false,
  92. height: 5,
  93. width: 5,
  94. label: {
  95. // show: true,
  96. text: '',
  97. font: '16px Helvetica',
  98. fillColor: 'blue',
  99. pixelOffset: [0, -20],
  100. backgroundColor: 'rgb(0,0,0)',
  101. showBackground: false
  102. }
  103. },
  104. // where:"name != '江川路街道'"
  105. }
  106. window.jMap.addLayer('mh_dyn_district', [1], options)
  107. // 街镇标题
  108. if (document.body.clientWidth > 1940) {
  109. var qp = new JMapQueryParam({
  110. queryMapService: 'mh_dyn_district',
  111. queryMapLayers: [1],
  112. outFields: ['code', 'name', 'center_x', 'center_y'],
  113. callBack: (res) => {
  114. res.features.forEach(async val => {
  115. await window.jMap.FlagInfo.show({
  116. id: val.attributes.code,
  117. position: { x: Number(val.attributes.center_x), y: Number(val.attributes.center_y), z: 0 },
  118. element: `<div class='ysc-dynamic-layer ys-css3-box' onclick="vue.clickFlag(${val.attributes.code})">
  119. <div class='biaozhu' style="font-size:32px !important">${val.attributes.name} ${val.attributes.code}</div>
  120. </div>`
  121. }, { isZoom: false, })
  122. });
  123. }
  124. })
  125. } else {
  126. var qp = new JMapQueryParam({
  127. queryMapService: 'mh_dyn_district',
  128. queryMapLayers: [1],
  129. outFields: ['code', 'name', 'center_x', 'center_y'],
  130. callBack: (res) => {
  131. res.features.forEach(async val => {
  132. await window.jMap.FlagInfo.show({
  133. id: val.attributes.code,
  134. position: { x: Number(val.attributes.center_x), y: Number(val.attributes.center_y), z: 0 },
  135. element: `<div class='ysc-dynamic-layer ys-css3-box' onclick="vue.clickFlag(${val.attributes.code})">
  136. <div class='biaozhu' style="font-size:18px !important">${val.attributes.name} ${val.attributes.code}</div>
  137. </div>`
  138. }, { isZoom: false, })
  139. });
  140. }
  141. })
  142. }
  143. // new JMapQuery(window.jMap).execQuery(qp)
  144. //window.jMap.bindBuildingClick(callbackFunction)
  145. // 点击三维建筑模型触发的回调函数
  146. },
  147. callbackFunction(obj) {
  148. // console.log(obj); // obj为返回值
  149. },
  150. /**
  151. * @聚合撒点
  152. * @param {数据list} data
  153. * @param {页面类型} pageType
  154. * @param {类型} type
  155. */
  156. initMarkers(data, pageType, type) {
  157. var _this = this;
  158. var tag = 1; //1.自定义图标 2.完全自定义 3.默认
  159. var style = ''; //地图最大化小图标
  160. var points = []; //地图撒点处理数据存储
  161. var target = {
  162. clusterId: '100001',
  163. clusterData: [{
  164. attributes: {
  165. name: "西环新村居委环绿公寓健身点"
  166. },
  167. position: {
  168. x: 121.36056108992341,
  169. y: 31.108652530290897,
  170. z: 0
  171. },
  172. image: {
  173. url: 'images/cluster.png',
  174. width: 22,
  175. height: 35
  176. }
  177. }, ]
  178. };
  179. var options = {
  180. style: { pixelRange: 10 },
  181. isZoom: true,
  182. click: clusterMapCallBack
  183. };
  184. jMap.ClusterMap.show(target, options);
  185. function clusterMapCallBack(clusterPointArr, clickPoint) {}
  186. },
  187. clickFlag(val) {
  188. },
  189. randomColor() {
  190. var color = "#";
  191. //for循环中,如果后面仅有一条语句,{}可省略不写
  192. //随机生成6位0-15之间的数字,再用toString(16)将数字转成16进制
  193. for (var i = 0; i < 6; i++) color += parseInt(Math.random() * 16).toString(16);
  194. return color;
  195. },
  196. removeMarkers(lnglats) {
  197. this.map.remove(lnglats);
  198. },
  199. /**
  200. * @创建标点和点击事件
  201. * @param {*} lnglats
  202. * @param {*} type
  203. */
  204. addMarker(lnglats, type) {
  205. console.log(lnglats)
  206. let icon = ''
  207. if (type == "selfManagement") {
  208. var lnglats = lnglats
  209. }
  210. var target = lnglats.map((val, ind) => {
  211. if (type == 'selfManagement') {
  212. if (val.ajlx == "火灾") {
  213. icon = this.icon3
  214. } else
  215. if (val.ajlx == "抢险救援") {
  216. icon = this.icon1
  217. } else if (val.ajlx == "社会救助") {
  218. icon = this.icon2
  219. } else {
  220. icon = this.icon2
  221. }
  222. } else {
  223. icon = val.waterAdministrative === '单位' ? this.icon1 : val.waterAdministrative === '市政' ? this.icon2 : val.waterAdministrative === '社区' || val.waterAdministrative === '居民' ? this.icon3 : this.icon1
  224. }
  225. if (type == "selfManagement" || type == "water") {
  226. let marker = {
  227. id: ind + 1,
  228. attrbutes: val,
  229. position: { x: val.gisX, y: val.gisY, z: 0 },
  230. image: { url: icon, width: 100, height: 100 },
  231. // image: { url: icon, width: 240, height: 240 },
  232. };
  233. return marker
  234. } else {
  235. let marker = {
  236. id: ind + 1,
  237. attrbutes: val,
  238. position: { x: val.gisBaiDuX, y: val.gisBaiDuY, z: 0 },
  239. image: { url: icon, width: 240, height: 240 },
  240. };
  241. return marker
  242. }
  243. })
  244. window.jMap.Locate.pointLocate(target, { //撒点
  245. isZoom: false,
  246. animate: { "show": true },
  247. scaleByDistance: { minScaling: 0, maxScaling: 1, minDistance: 1000, maxDistance: 30000 },
  248. click: (val) => {
  249. if (type == "selfManagement") {
  250. this.$axios.get(this.$api.jqzhcz.one +
  251. "?" +
  252. this.$qs.stringify({
  253. id: val.attrbutes.id,
  254. })
  255. ).then(res => {
  256. this.elementInfo(res.data, type)
  257. })
  258. } else {
  259. this.elementInfo(value, type)
  260. }
  261. }
  262. })
  263. },
  264. /**
  265. * @无经纬度创建标点和点击事件
  266. * @param {*} lnglats
  267. */
  268. addMarkerAddress(lnglats) {
  269. let target = lnglats.map((val, ind) => {
  270. if (!val.addressId) {
  271. let addressInfo = window.jMap.queryMphInfo(val.address)[val.address][0]
  272. return {
  273. ...val,
  274. addressId: addressInfo.address_id, // 地址id
  275. province: addressInfo.province, // 市
  276. district: addressInfo.district, // 区
  277. sub_district: addressInfo.sub_district, // 街镇
  278. streetname: addressInfo.streetname, // 路
  279. address: addressInfo.address, // 户
  280. committee: addressInfo.committee, // 居委会
  281. }
  282. }
  283. })
  284. target = target.reduce((item, next) => {
  285. !item.some(val => val.addressId === next.addressId) && item.push(next)
  286. return item
  287. }, []);
  288. for (let item = 0; item < Math.floor(target.length / 100); item++) {
  289. setTimeout(() => {
  290. window.jMap.locateMph(
  291. target.slice(item * 100, (item + 1) * 100).map(val => val.addressId).join(), {
  292. isZoom: false,
  293. scaleByDistance: { minScaling: 0, maxScaling: 1, minDistance: 1000, maxDistance: 30000 },
  294. click: (value) => {
  295. this.elementInfo(value, 'fire')
  296. }
  297. }
  298. )
  299. }, 0)
  300. }
  301. },
  302. leftBtnClick() {
  303. this.leftBtn = !this.leftBtn;
  304. },
  305. rightBtnClick() {
  306. this.rightBtn = !this.rightBtn
  307. },
  308. elementInfo(value, type) {
  309. if (this.timer) {
  310. clearTimeout(this.timer)
  311. }
  312. this.timer = setTimeout(() => {
  313. window.jMap.Popup.hide()
  314. }, 8000)
  315. // setTimeout(()=>{
  316. // if(this.time){
  317. // }
  318. // },8000)
  319. if (!value.ajbh) {
  320. value.ajbh = '--'
  321. }
  322. if (!value.tzsj) {
  323. value.tzsj = '--'
  324. }
  325. if (!value.bcxx) {
  326. value.bcxx = '--'
  327. }
  328. if (!value.ajlx) {
  329. value.ajlx = '--'
  330. }
  331. if (!value.afdz) {
  332. value.afdz = '--'
  333. }
  334. if (!value.zhongdui) {
  335. value.zhongdui = '--'
  336. }
  337. if (!value.ajzt) {
  338. value.ajzt = '--'
  339. }
  340. if (!value.dcsj) {
  341. value.dcsj = '--'
  342. }
  343. if (!value.cssj) {
  344. value.cssj = '--'
  345. }
  346. if (!value.kzsj) {
  347. value.kzsj = '--'
  348. }
  349. if (!value.xmsj) {
  350. value.xmsj = '--'
  351. }
  352. if (!value.fdsj) {
  353. value.fdsj = '--'
  354. }
  355. if (!value.streettown) {
  356. value.streettown = '--'
  357. }
  358. let element = ''
  359. if (type === 'water') {
  360. element = `<div class="ysc-dynamic-layer ys-css3-box" onclick="vue.removePopup">
  361. <div class="tableTooltip mapTab">
  362. <div class="tableTitle">
  363. <div>${value.attrbutes.type}</div>
  364. </div>
  365. <el-row class="tableContent">
  366. <div class="max">水源位置:${value.attrbutes.address}</div>
  367. <div>电话:${value.attrbutes.phone}</div>
  368. <div class="max">支队名称:${value.attrbutes.detachmentName}</div>
  369. <div>管辖机构:${value.attrbutes.jurisdictionalAgency}</div>
  370. <div>水源类型:${value.attrbutes.type}</div>
  371. <div>取水形式:${value.attrbutes.getWaterType}</div>
  372. <div>水源性质:${value.attrbutes.waterAdministrative}</div>
  373. <div>状态:${value.attrbutes.status == 1 ? '可用' : '不可用'}</div>
  374. <div>供水单位:${value.attrbutes.waterUnit}</div>
  375. </el-row>
  376. </div>
  377. </div>`
  378. } else if (type === 'fire') {
  379. element = `<div class="ysc-dynamic-layer ys-css3-box" onclick="vue.removePopup">
  380. <div class="tableTooltip mapTab">
  381. <div class="tableTitle">
  382. <div>${'单位及执法情况'}</div>
  383. </div>
  384. <el-row class="tableContent">
  385. <div>单位地址:${'XX路135弄'}</div>
  386. <div>法人:${'张三'}</div>
  387. <div>管理人:${'李四'}</div>
  388. <div>历史检查次数:<a>${'6次'}</a></div>
  389. <div class="divTitle">行政许可记录</div>
  390. <div>审核时间:${'2021-06-26'}</div>
  391. <div>验收时间:${'2021-06-26'}</div>
  392. <div>安检时间:${'2021-06-26'}</div>
  393. <div>历史隐患数:${'2处'}</div>
  394. <div class="divTitle">历史处罚情况</div>
  395. <div>历史火灾数:${'2'}</div>
  396. <div>单位自主管理情况:<a>点击查看</a></div>
  397. </el-row>
  398. </div>
  399. </div>`
  400. } else {
  401. element = `<div class="ysc-dynamic-layer ys-css3-box" onclick="vue.removePopup">
  402. <div class="tableTooltip mapTab">
  403. <div class="tableTitle">
  404. <div>${value.ajlx}</div>
  405. </div>
  406. <el-row class="tableContent">
  407. <div class="max">案件编号:${value.ajbh}</div>
  408. <div class="max">报警时间:${value.tzsj} </div>
  409. <div class="max">案件描述:${value.bcxx}</div>
  410. <div class="max">案件类型:${value.ajlx}</div>
  411. <div class="max">发生地址:${value.afdz}</div>
  412. <div class="max2">主责中队:${value.zhongdui}</div>
  413. <div class="max2">案件状态:${value.ajzt}</div>
  414. <div class="max">到场时间:${value.dcsj}</div>
  415. <div class="max">出水时间:${value.cssj}</div>
  416. <div class="max">控制时间:${value.kzsj}</div>
  417. <div class="max">熄灭时间:${value.xmsj}</div>
  418. <div class="max">返队时间:${value.fdsj}</div>
  419. <div class="max2">所属街道:${value.streettown}</div>
  420. </el-row>
  421. </div>
  422. </div>`
  423. }
  424. this.addMarkerInfo(element, value, type)
  425. },
  426. // 标点点击弹窗
  427. // addMarkerInfo(element, value, type, isBtn = false) {
  428. addMarkerInfo(element, value, type, isBtn = false) {
  429. // window.jMap.Popup && window.jMap.Popup.hide([this.oldPopup && this.oldPopup.id]);
  430. if (this.oldPopup && value.id === this.oldPopup.id) {
  431. window.jMap.Popup.hide();
  432. return this.oldPopup = null
  433. }
  434. if (type == "selfManagement" || type == "water") {
  435. window.jMap.Popup.show({
  436. id: value.id,
  437. //position: value.wgs84position, //使用自定义窗体
  438. position: { x: value.gisX, y: value.gisY }, //使用自定义窗体
  439. element: element,
  440. }, { isZoom: false, offset: [0, -40] });
  441. } else {
  442. window.jMap.Popup.show({
  443. id: value.id,
  444. //position: value.wgs84position, //使用自定义窗体
  445. position: { x: value.gisX, y: value.gisY }, //使用自定义窗体
  446. element: element,
  447. }, { isZoom: false, offset: [0, -40] });
  448. }
  449. if (!isBtn) {
  450. window.jMap.goTo({
  451. x: Number(value.wgs84position.x),
  452. y: Number(value.wgs84position.y),
  453. radius: 1000
  454. }, {
  455. duration: 3,
  456. offset: {
  457. heading: -4,
  458. pitch: -70,
  459. range: 0
  460. }
  461. })
  462. window.jMap.Buffer.generate({
  463. geometry: [{ position: [{ x: Number(value.wgs84position.x), y: Number(value.wgs84position.y) }], type: 'point' }],
  464. distance: 1000
  465. }, {
  466. callBack: (el) => {
  467. for (const i in el) {
  468. var target = {
  469. id: i,
  470. position: CoordUtil.arrayToJson(el[i].rings[0])
  471. }
  472. }
  473. window.jMap.Locate.regionLocate(target, {
  474. style: {
  475. color: 'rgba(235, 98, 98, .1)',
  476. transparency: .3
  477. }
  478. })
  479. },
  480. })
  481. }
  482. this.oldPopup = value
  483. },
  484. removePopup(e) {
  485. console.log(e)
  486. },
  487. }
  488. }