MapHolder.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. <template>
  2. <div id="map2DViewer">
  3. <!-- 特殊地图属性弹窗 -- 有审计功能 -->
  4. <CaseAuditPopup v-show="auditPopupShow" ref="auditRef" />
  5. <!-- 通用地图属性弹窗 -- 无审计功能 -->
  6. <NormalAttrPopup v-show="normalAttrPopupShow" ref="normalRef" />
  7. <LabelCasePopup v-show="labelDetailsPopupShow" ref="labelRef" />
  8. <BasemapChange />
  9. </div>
  10. </template>
  11. <script>
  12. import publicFun from "@/utils/publicFunction.js";
  13. import transformCoord from "@/utils/coordinate";
  14. import { get } from "@/utils/request";
  15. import { streetLocation, townData } from "@/config/common";
  16. import CaseAuditPopup from "@/components/popup/CaseAuditPopup.vue";
  17. import NormalAttrPopup from "@/components/popup/NormalAttrPopup.vue";
  18. import LabelCasePopup from "@/components/popup/LabelCasePopup.vue";
  19. import BasemapChange from "@/components/map/BasemapChange.vue";
  20. export default {
  21. name: "MapHolder",
  22. components: {
  23. CaseAuditPopup,
  24. NormalAttrPopup,
  25. LabelCasePopup,
  26. BasemapChange,
  27. },
  28. data() {
  29. return {
  30. town: "祝桥镇,南汇新城镇,川沙新镇,老港镇,惠南镇,航头镇,泥城镇,书院镇,新场镇,大团镇,唐镇,曹路镇,宣桥镇,张江镇,合庆镇,周浦镇,康桥镇,三林镇,高桥镇,高东镇,金桥镇,北蔡镇,万祥镇,高行镇",
  31. auditPopupShow: false,
  32. normalAttrPopupShow: false,
  33. labelDetailsPopupShow: false,
  34. auditPopupStatus: "normal",
  35. popup: null,
  36. labelPopup: null,
  37. normalPopup: null,
  38. // 疑点审计
  39. currentCid: null,
  40. currentHtml: null,
  41. currentProperties: null,
  42. currentSourceType: null,
  43. // 标记疑点
  44. currentLabelCid: null,
  45. currentLabelHtml: null,
  46. tableObj: {},
  47. // 疑点审计的保存后的疑点状态集合
  48. caseStatusMap: new Map(),
  49. };
  50. },
  51. created() {},
  52. mounted() {
  53. // 监听全局事件总线中的卷帘对比事件(JLControl)
  54. this.$bus.$off("JLControl");
  55. this.$bus.$on("JLControl", () => {
  56. this.JLControl();
  57. });
  58. // 监听全局事件总线中的卷帘对比重绘事件(reJLControl)
  59. this.$bus.$off("reJLControl");
  60. this.$bus.$on("reJLControl", () => {
  61. this.reJLControl();
  62. });
  63. this.$bus.$off("caseAuditEvent");
  64. this.$bus.$on("caseAuditEvent", () => {
  65. this.caseAuditEvent();
  66. });
  67. //地图初始化
  68. this.mapInit();
  69. this.$store.state.mapMethodsCollection.set("RENDER", {
  70. addPolygonLayer: this.addPolygonLayer,
  71. setView: this.setView,
  72. deletePolygonLayer: this.deletePolygonLayer,
  73. addSinglePolygon: this.addSinglePolygon,
  74. deleteSinglePolygon: this.deleteSinglePolygon,
  75. deleteGroupFromMap: this.deleteGroupFromMap,
  76. drawGeometry: this.drawGeometry,
  77. deleteGeometry: this.deleteGeometry,
  78. });
  79. },
  80. beforeDestroyed() {
  81. // 当容器销毁时,需要停止监听该事件
  82. this.$bus.$off("JLControl");
  83. // 疑点审计
  84. this.$bus.$off("caseAuditEvent");
  85. map2DViewer.map.closePopup();
  86. },
  87. computed: {
  88. // 监听底部菜单栏的状态
  89. getLabelCaseBtnStatus() {
  90. //疑点审计 1,0
  91. let _index = this.$store.state.bottomMenuIndexs.index;
  92. let _subIndex = this.$store.state.bottomMenuIndexs.subIndex;
  93. return { index: _index, subIndex: _subIndex };
  94. },
  95. // 监听当前菜单
  96. getCurrentMenu() {
  97. return this.$store.state.navSelect;
  98. },
  99. },
  100. watch: {
  101. getLabelCaseBtnStatus(val) {
  102. // console.log(val, "标记疑点");
  103. if (val.index === 1 && val.subIndex === 1) {
  104. // 删除地图上所有弹窗
  105. this.$store.state.attrTableShow = false;
  106. this.$store.state.updateCasePopupShow = false;
  107. // 删除地图上的所有标记
  108. if (map2DViewer.myLabels) {
  109. for (let i in map2DViewer.myLabels) {
  110. // console.log(i, "图层名");
  111. this.deleteGeometry(map2DViewer.myLabels[i]);
  112. map2DViewer.myLabels[i] = null;
  113. }
  114. }
  115. this.initDraw();
  116. } else {
  117. this.stopLabelCase();
  118. if (this.labelPopup) {
  119. map2DViewer.map.closePopup();
  120. this.labelPopup = null;
  121. }
  122. }
  123. },
  124. "$store.state.navSelect": {
  125. handler(val) {
  126. if (val.index !== "3") {
  127. if (map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  128. map2DViewer.map.removeControl(map2DViewer.jlControl);
  129. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  130. delete map2DViewer.jlMap;
  131. map2DViewer.jlControl = null;
  132. }
  133. this.$store.state.bottomMenuIndexs.index = -1;
  134. this.$store.state.bottomMenuIndexs.subIndex = -1;
  135. this.$store.commit("changeJlActiveState", false);
  136. }
  137. // 切换页面时判断是否需要显示区域图
  138. this.$nextTick(() => {
  139. this.getJSonData();
  140. });
  141. },
  142. // immediate: true
  143. },
  144. },
  145. methods: {
  146. // 开始标记疑点事件
  147. startLabelCase() {
  148. map2DViewer.setDrawTool({ action: "start" });
  149. },
  150. // 停止标记疑点事件
  151. stopLabelCase() {
  152. if (map2DViewer.measureTool) {
  153. map2DViewer.setDrawTool({
  154. action: "remove",
  155. });
  156. }
  157. },
  158. reStartLabelCase() {
  159. this.stopLabelCase();
  160. this.initDraw();
  161. },
  162. /**
  163. * 无审计功能的地图弹窗
  164. * @str
  165. * @properties
  166. * @sourceType
  167. */
  168. createNormalDiv(str, geojsonData, sourceType) {
  169. // debugger;
  170. let currentInnerHtml = this.$refs.normalRef.$el.innerHTML;
  171. // 搜索geojson数据中的固定字段 -- 镇域名称,面积,土地类型,图斑编号
  172. // this.$refs.normalRef.tableObj = geojsonData;
  173. if (currentInnerHtml) {
  174. let div = document.createElement("div");
  175. div.id = str + "_id";
  176. div.className = "case-audit";
  177. // 动态创建div后赋值模板样式
  178. div.innerHTML = currentInnerHtml;
  179. $(() => {
  180. // 法律法规点击事件
  181. if ($(`#${str}_id a`)) {
  182. $(`#${str}_id a`)
  183. .eq(0)
  184. .click((e) => {
  185. this.$store.state.lawPopupShow = true;
  186. this.$store.state.lawSourceType = sourceType;
  187. });
  188. $(`#${str}_id a`)
  189. .eq(1)
  190. .click((e) => {
  191. // 触发综合分析右侧面板点击事件
  192. this.$bus.$emit("viewDetailsPopup", geojsonData);
  193. });
  194. }
  195. });
  196. return div;
  197. }
  198. },
  199. /**
  200. * 有审计功能的地图弹窗
  201. * @str
  202. * @properties
  203. * @sourceType
  204. */
  205. createAuditDiv(str, geojsonData, sourceType) {
  206. // 根据ref获取组件的dom元素
  207. this.currentHtml = this.$refs.auditRef.$el.innerHTML;
  208. // 搜索geojson数据中的固定字段 -- 镇域名称,面积,土地类型,图斑编号
  209. // this.$refs.auditRef.tableObj = JSON.parse(geojsonData).properties;
  210. if (this.currentHtml) {
  211. let div = document.createElement("div");
  212. div.id = str + "_id";
  213. div.className = "case-audit";
  214. // 动态创建div后赋值模板样式
  215. div.innerHTML = this.currentHtml;
  216. $(() => {
  217. if ($(`#${str}_id .center-table-item-special select`)) {
  218. if (this.caseStatusMap.has(str)) {
  219. $(`#${str}_id .center-table-item-special select`).val(
  220. this.caseStatusMap.get(str)
  221. );
  222. }
  223. }
  224. // 法律法规点击事件
  225. if ($(`#${str}_id a`)) {
  226. $(`#${str}_id a`)
  227. .eq(0)
  228. .click((e) => {
  229. this.$store.state.lawPopupShow = true;
  230. this.$store.state.lawSourceType = sourceType;
  231. });
  232. $(`#${str}_id a`)
  233. .eq(1)
  234. .click((e) => {
  235. // 触发综合分析右侧面板点击事件
  236. this.$bus.$emit("viewDetailsPopup", geojsonData);
  237. });
  238. }
  239. // input添加点击事件
  240. if ($(`#${str}_id input`)[1]) {
  241. $(`#${str}_id input`).click((e) => {
  242. switch (e.target.defaultValue) {
  243. case "取消":
  244. this.cancelBtnEvent();
  245. break;
  246. case "确认":
  247. this.confirmBtnEvent(str);
  248. break;
  249. }
  250. });
  251. }
  252. });
  253. return div;
  254. }
  255. },
  256. /**
  257. * 标记疑点完成时保存描述信息的弹窗
  258. * @str -- id
  259. * @coord -- 坐标信息
  260. * @data -- 其余数据
  261. * @geoType -- 几何体类型
  262. */
  263. createLabelDiv(str, coord, data, geoType) {
  264. console.log(str, coord, data, geoType, "createLabelDiv");
  265. console.log(str, "label - str");
  266. this.currentLabelHtml = this.$refs.labelRef.$el.innerHTML;
  267. if (this.currentLabelHtml) {
  268. let div = document.createElement("div");
  269. div.id = `${str}_id`;
  270. div.className = "label-case";
  271. // 动态创建div后赋值模板样式
  272. div.innerHTML = this.currentLabelHtml;
  273. $(() => {
  274. console.log($(`#${str}_id textarea`).val(), "textarea");
  275. $(`#${str}_id`).css("height", "100%");
  276. $(`#${str}_id input`).click((e) => {
  277. console.log(e.target.defaultValue);
  278. switch (e.target.defaultValue) {
  279. case "取消":
  280. this.cancelBtnEvent();
  281. break;
  282. case "保存":
  283. this.saveBtnEvent(str, data, geoType);
  284. break;
  285. }
  286. });
  287. });
  288. return div;
  289. }
  290. },
  291. modifyBtnEvent() {
  292. console.log("用户点击了地图中的修改按钮!");
  293. },
  294. confirmBtnEvent(str) {
  295. // isTrue
  296. let selectVal = $(`#${str}_id .center-table-item-special select`).val();
  297. this.caseStatusMap.set(str, selectVal);
  298. let obj = {
  299. c_date_time: this.$dayjs().valueOf(),
  300. c_boolean: selectVal === "isTrue" ? true : false,
  301. // 修改人员名称
  302. c_editor_name: localStorage.getItem("USER_NAME"),
  303. // 修改人员ID
  304. c_editorid: localStorage.getItem("USER_ID"),
  305. };
  306. let modifyParams = new FormData();
  307. modifyParams = {
  308. columnId: 47,
  309. modelId: 49,
  310. content: JSON.stringify(obj),
  311. };
  312. this.$Post(this.urlsCollection.updateContent, modifyParams).then(
  313. (res) => {
  314. if (res.code === 200) {
  315. this.$message.success("数据修改成功");
  316. map2DViewer.map.closePopup();
  317. }
  318. }
  319. );
  320. },
  321. cancelBtnEvent() {
  322. map2DViewer.map.closePopup();
  323. this.labelPopup = null;
  324. this.popup = null;
  325. },
  326. /**
  327. * 点击保存事件时保存点数据
  328. * @str
  329. * @data -- 绘制几何体时获取的数据;
  330. * @geoType 几何体类型 类型: 0 点;1 线;2 面;3 矩形;4 圆形;5 其他;
  331. */
  332. saveBtnEvent(str, data, geoType) {
  333. if (localStorage.getItem("USER_ID")) {
  334. let title = $(`#${str}_id select`).val();
  335. let des = $(`#${str}_id textarea`).val();
  336. let geoName = "";
  337. let currentName = $(`#${str}_id input`).eq(0).val();
  338. if (myLabelNameMap.has(currentName)) {
  339. this.$message.info("该名称已存在,请重新输入!");
  340. } else {
  341. geoName = $(`#${str}_id input`).eq(0).val();
  342. let coordinates = [data.points];
  343. let geometry = publicFun.generateGeoJSON(
  344. title,
  345. des,
  346. geoType,
  347. coordinates,
  348. geoName
  349. );
  350. let params = new FormData();
  351. let newGeojson = JSON.stringify(geometry);
  352. myLabelNameMap.set(geoName, newGeojson);
  353. params = {
  354. geojson: newGeojson,
  355. type: geoType,
  356. userId: Number(localStorage.getItem("USER_ID")),
  357. sourceId: 0,
  358. };
  359. this.$Post(this.urlsCollection.addConllection, params).then(
  360. (res) => {
  361. if (res.code == 200) {
  362. // 标记成功后删除保存的原有名称
  363. myLabelNameMap.delete(geoName);
  364. map2DViewer.map.closePopup();
  365. // 根据用户获取标记
  366. let paramData = new FormData();
  367. paramData = {
  368. userId: Number(localStorage.getItem("USER_ID")),
  369. sourceId: 0,
  370. pageSize: 10,
  371. };
  372. // 暂存map中刚刚保存的数据
  373. this.$Post(this.urlsCollection.selectByUser, paramData).then(
  374. (userRes) => {
  375. if (userRes.code === 200) {
  376. if (userRes.content.length > 0) {
  377. this.$store.state.myLabelPointsArr = [];
  378. this.$store.state.myLabelPointsArr =
  379. userRes.content.map((v) => {
  380. if (JSON.stringify(geometry) === v.geojson) {
  381. sessionStorage.setItem("myLabelPointsId", v.id);
  382. }
  383. return {
  384. id: v.id,
  385. geojson: v.geojson,
  386. type: v.type,
  387. };
  388. });
  389. // 判断刚刚暂存的数据,并调用小眼睛的方法
  390. }
  391. }
  392. // 更新时调用一次搜索接口
  393. }
  394. );
  395. }
  396. // 保存后需要删除地图上的标记
  397. this.reStartLabelCase();
  398. },
  399. (error) => {
  400. console.log("标记疑点保存失败!", error);
  401. this.reStartLabelCase();
  402. }
  403. );
  404. }
  405. }
  406. },
  407. // 卷帘对比
  408. JLControl() {
  409. if (!map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  410. map2DViewer.jlMap = L.tileLayer(
  411. "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d"
  412. ).addTo(map2DViewer.map);
  413. map2DViewer.jlControl = L.control
  414. .sideBySide(map2DViewer.map, map2DViewer.jlMap)
  415. .addTo(map2DViewer.map);
  416. } else if (map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  417. map2DViewer.map.removeControl(map2DViewer.jlControl);
  418. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  419. delete map2DViewer.jlMap;
  420. map2DViewer.jlControl = null;
  421. }
  422. },
  423. // 卷帘对比重绘
  424. reJLControl() {
  425. if (map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  426. map2DViewer.map.removeControl(map2DViewer.jlControl);
  427. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  428. delete map2DViewer.jlMap;
  429. map2DViewer.jlControl = null;
  430. this.JLControl();
  431. }
  432. },
  433. // 疑点审计
  434. caseAuditEvent() {
  435. // 每次点击按钮后重绘弹窗
  436. if (this.currentHtml && this.currentCid) {
  437. setTimeout(() => {
  438. this.popup.setContent(
  439. this.createAuditDiv(
  440. this.currentCid,
  441. this.currentProperties,
  442. this.currentSourceType
  443. )
  444. );
  445. // .openOn(map2DViewer.map);
  446. }, 300);
  447. }
  448. },
  449. // 初始化引入绘制工具
  450. initDraw() {
  451. if (!map2DViewer.measureTool) {
  452. // 引入疑点标记绘制方法
  453. map2DViewer.drawToolFire = (data) => {
  454. // 纬经度
  455. if (data && data.points.length >= 1) {
  456. let geoType = null;
  457. // 类型: 0 点;1 线;2 面;3 矩形;4 圆形;5 其他;
  458. if (data.points.length === 1 && data.area === 0) {
  459. geoType = 0;
  460. }
  461. if (data.points.length === 2 && data.distance > 0) {
  462. geoType = 4;
  463. }
  464. if (data.points.length > 2 && data.area === 0) {
  465. geoType = 1;
  466. }
  467. if (data.points.length > 2 && data.area != 0 && data.area != "") {
  468. geoType = 2;
  469. }
  470. let coord = data.points[data.points.length - 1];
  471. if (coord && coord.length >= 2) {
  472. let newCoord = { lat: coord[0], lng: coord[1] };
  473. this.labelDetailsPopupShow = true;
  474. this.labelPopup = L.popup({ maxWidth: 700, maxHeight: 600 })
  475. .setLatLng(newCoord)
  476. .setContent(this.createLabelDiv("label", coord, data, geoType))
  477. .openOn(map2DViewer.map);
  478. this.labelDetailsPopupShow = false;
  479. }
  480. }
  481. };
  482. map2DViewer.setDrawTool({
  483. action: "add",
  484. offset: [150, 50],
  485. background: "#fff",
  486. color: "red",
  487. font_size: "14px",
  488. closeButton: true,
  489. iconUrl: "../../static/plugins/draw-plugin/images/marker-icon.png",
  490. });
  491. }
  492. },
  493. mapInit: function () {
  494. // var crs = new L.Proj.CRS(
  495. // "EPSG:2401",
  496. // "+proj=tmerc +lat_0=0 +lon_0=121.2751921 +k=1 +x_0=0 +y_0=-3457147.81 +ellps=krass +units=m +no_defs",
  497. // {
  498. // resolutions: [
  499. // 529.1666666666666, 264.5833333333333, 132.29166666666666, 52.916666666666664, 26.458333333333332,
  500. // 13.229166666666666, 5.291666666666666, 2.645833333333333, 1.3229166666666665, 0.5291666666666666,
  501. // 0.2645833333333333, 0.13229166666666664
  502. // ],
  503. // origin: [-66000, 75000],
  504. // bounds: L.bounds([-65000, -76000], [75000, 72000])
  505. // }
  506. // );
  507. map2DViewer.map = L.map("map2DViewer", {
  508. // crs: crs,
  509. // center: [31.074472887639914, 121.72521988031804],
  510. // zoom: 1,
  511. // minZoom: 1,
  512. // maxZoom: 12
  513. attributionControl: false,
  514. zoomControl: false,
  515. minZoom: 10,
  516. maxZoom: 16,
  517. }).setView(systemConfig.mapViewer.center, systemConfig.mapViewer.zoom);
  518. //添加默认图层
  519. let guid = publicFun.buildGuid("baseLayer");
  520. let layer = L.esri
  521. .tiledMapLayer({
  522. url:
  523. // systemConfig.mapService +
  524. // "?servertype=Street_Purplish_Blue&token=" +
  525. // systemConfig.token,
  526. // url: "http://aimap.pudong.sh:5236/maps/rest/services/basemap-shanghai-gem-blue-sh2000/mapserver",
  527. // tileSize: 512
  528. systemConfig.blueBlackMap,
  529. })
  530. .addTo(map2DViewer.map);
  531. // layer.setStyle({opacity:0,fillOpacity:0})
  532. map2DViewer.layers["darkmap"] = layer;
  533. // 加载天地图
  534. let imageryLayer = L.tileLayer(systemConfig.imageryLayer);
  535. map2DViewer.layers["imagery"] = imageryLayer;
  536. },
  537. // 传入街道参数,重新渲染区域图层
  538. getJSonDataToStreet(url, param) {
  539. // 先删除历史图层
  540. if (map2DViewer.map.hasLayer(map2DViewer.groups["浦东新区_polygon"])) {
  541. map2DViewer.groups["浦东新区_label"].remove();
  542. map2DViewer.groups["浦东新区_polygon"].remove();
  543. }
  544. // 请求并渲染新的区域图层
  545. get("./static/json/simplified_pdgeojson.json", "").then((geoJson) => {
  546. // 存放所有的面数据
  547. map2DViewer.groups["浦东新区_polygon"] = L.featureGroup();
  548. map2DViewer.groups["浦东新区_label"] = L.featureGroup();
  549. map2DViewer.groups["浦东新区_polygon"].addTo(map2DViewer.map);
  550. map2DViewer.groups["浦东新区_label"].addTo(map2DViewer.map);
  551. geoJson.features.map((feature) => {
  552. if (
  553. this.town.indexOf(feature.properties.NAME.replace("镇", "")) > -1
  554. ) {
  555. this.renderPolygon(feature);
  556. }
  557. });
  558. });
  559. },
  560. // 可视化单一的镇域面
  561. getSingleJsonData(name) {},
  562. // 默认获取浦东新区全区的图层数据
  563. getJSonData() {
  564. if (!map2DViewer.map) {
  565. this.mapInit();
  566. } else if (
  567. // 切换到首页和疑点筛查页且图层不存在时重新渲染区域图
  568. (this.$ifMenu("1", "") || this.$ifMenu("2", "")) &&
  569. !map2DViewer.map.hasLayer(map2DViewer.groups["浦东新区_polygon"])
  570. ) {
  571. this.getJSonDataToStreet("", "");
  572. // 切换到首页时需定位到当前图层
  573. if (this.$store.state.homeSpecialTown === "全部") {
  574. this.setView(
  575. townLocationMap.get(this.$store.state.homeSpecialTown),
  576. 10
  577. );
  578. } else {
  579. let polygon = townPolygonMap.get(this.$store.state.homeSpecialTown);
  580. map2DViewer.map.fitBounds(polygon.getBounds());
  581. }
  582. } else if (
  583. !(this.$ifMenu("1", "") || this.$ifMenu("2", "")) &&
  584. map2DViewer.map.hasLayer(map2DViewer.groups["浦东新区_polygon"])
  585. ) {
  586. // 当前页不是首页和疑点筛查页时移除区域图且图层存在时
  587. map2DViewer.groups["浦东新区_label"].remove();
  588. map2DViewer.groups["浦东新区_polygon"].remove();
  589. }
  590. },
  591. setView: function (coord, zoom) {
  592. // console.log(coord, "位置");
  593. let center = L.latLng(coord[0], coord[1]);
  594. map2DViewer.map.setView(center, zoom);
  595. },
  596. renderPolygon: function (feature) {
  597. let center = turf.center(feature.geometry);
  598. // let itemvalue = JSON.parse((Math.random() * 1000).toFixed(0));
  599. let name = feature.properties.NAME;
  600. let polygonData = JSON.parse(JSON.stringify(feature));
  601. let coordinates = polygonData.geometry.coordinates[0];
  602. // 几何体
  603. let polygon = L.polygon(this.latLngsToReverse(coordinates), {
  604. color: "#87d8fd",
  605. weight: 3,
  606. fillColor: this.getColor(name),
  607. opacity: 1,
  608. fillOpacity: 0.4,
  609. }).addTo(map2DViewer.groups["浦东新区_polygon"]);
  610. center = JSON.parse(JSON.stringify(center)).geometry.coordinates;
  611. center.reverse();
  612. // 坐标
  613. townLocationMap.set(name, center);
  614. townPolygonMap.set(name, polygon);
  615. let wmarker = L.circleMarker(center, {
  616. radius: 10,
  617. weight: 1,
  618. fillOpacity: 0,
  619. color: "#e6d273",
  620. });
  621. wmarker.bindLabel(feature.properties.NAME, {
  622. noHide: true,
  623. clickable: true,
  624. offset: [-25, 10],
  625. });
  626. wmarker.addTo(map2DViewer.groups["浦东新区_label"]);
  627. let circle1 = L.circleMarker(center, {
  628. radius: 8,
  629. weight: 1,
  630. fillOpacity: 0,
  631. color: "#e6d273",
  632. }).addTo(map2DViewer.groups["浦东新区_polygon"]);
  633. let circle2 = L.circleMarker(center, {
  634. radius: 5,
  635. weight: 1,
  636. fillOpacity: 1,
  637. color: "#e6d273",
  638. }).addTo(map2DViewer.groups["浦东新区_polygon"]);
  639. },
  640. latLngsToReverse: function (latlngsAry) {
  641. var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry));
  642. if (typeof tempLatlngsAry[0] != "object") {
  643. return tempLatlngsAry.reverse();
  644. } else {
  645. for (var i = 0, l = tempLatlngsAry.length; i < l; i++) {
  646. tempLatlngsAry[i] = this.latLngsToReverse(tempLatlngsAry[i]);
  647. }
  648. }
  649. return tempLatlngsAry;
  650. },
  651. getColor(name) {
  652. if (townData.A.indexOf(name) > -1) {
  653. return "#e565ff";
  654. } else if (townData.B.indexOf(name) > -1) {
  655. return "#0055ff";
  656. } else if (townData.C.indexOf(name) > -1) {
  657. return "#00ffd5";
  658. }
  659. },
  660. /**
  661. * 获取图层信息 -- 所有模型和预设模型
  662. * @geometry 字符串格式的geojson数据
  663. * @cid columnId
  664. * @color 随机色
  665. * @uniqueId label_columnId
  666. * @mainType 所有图层/预设模型
  667. * @sourceType 土地资源/林地资源/生态资源/水资源/全部
  668. */
  669. addSinglePolygon(geometry, cid, color, uniqueId, mainType, sourceType) {
  670. let uniqueIdList = [];
  671. if (this.$store.state.selectSelectDataMap["singlePolygon"][uniqueId]) {
  672. uniqueIdList =
  673. this.$store.state.selectSelectDataMap["singlePolygon"][uniqueId];
  674. }
  675. let singlePolygonItem = {
  676. uniqueId: uniqueId,
  677. geometry: geometry,
  678. cid: cid,
  679. };
  680. uniqueIdList.push(singlePolygonItem);
  681. this.$store.state.selectSelectDataMap["singlePolygon"][uniqueId] =
  682. uniqueIdList;
  683. let coordinates = "";
  684. if (uniqueId === "一般耕地_47") {
  685. let coord = JSON.parse(geometry).geometry.coordinates[0];
  686. coordinates = coord.map((v) => {
  687. return [v[1], v[0]];
  688. });
  689. } else {
  690. coordinates = JSON.parse(geometry).geometry.coordinates[0];
  691. coordinates = coordinates.map((v) => {
  692. let data = transformCoord.shcj_to_wgs84(v[1], [v[0]]);
  693. data = [data[1], data[0]];
  694. return data;
  695. });
  696. }
  697. // 纬经度
  698. // [22474.568725585938, -16689.47381591797]
  699. // x,y转换
  700. let polygon = L.polygon(coordinates, {
  701. color: color,
  702. weight: 3,
  703. fillColor: color,
  704. opacity: 1,
  705. fillOpacity: 0.4,
  706. }).addTo(map2DViewer.analysisGroups[uniqueId]);
  707. polygon.on("click", (e) => {
  708. let geojsonData = geometry;
  709. // 所有图层下的疑点图层 -- 常规展示
  710. if (mainType === "所有图层") {
  711. this.normalAttrPopupShow = true;
  712. this.normalPopup = L.popup({ maxWidth: 700, maxHeight: 600 })
  713. .setLatLng(e.latlng)
  714. .setContent(this.createNormalDiv(cid, geojsonData, sourceType));
  715. this.normalAttrPopupShow = false;
  716. this.normalPopup.openOn(map2DViewer.map);
  717. }
  718. // 预设模型下图层 -- 需要考虑审计功能
  719. if (mainType === "预设模型") {
  720. this.auditPopupShow = true;
  721. this.popup = L.popup({ maxWidth: 700, maxHeight: 600 })
  722. .setLatLng(e.latlng)
  723. .setContent(this.createAuditDiv(cid, geojsonData, sourceType));
  724. this.auditPopupShow = false;
  725. this.popup.openOn(map2DViewer.map);
  726. this.currentCid = cid;
  727. this.currentProperties = geojsonData;
  728. this.currentSourceType = sourceType;
  729. }
  730. });
  731. },
  732. // 综合分析 - 图层绘制面
  733. addPolygonLayer(data, cid, color) {
  734. data.map((feature) => {
  735. let polygonData = JSON.parse(JSON.stringify(feature));
  736. let coordinates = polygonData.geometry.coordinates[0];
  737. let infos = polygonData.properties;
  738. let polygon = L.polygon(coordinates, {
  739. color: color,
  740. weight: 3,
  741. fillColor: color,
  742. opacity: 1,
  743. fillOpacity: 0.4,
  744. }).addTo(map2DViewer.map);
  745. map2DViewer.polygons[`${cid}_layer`].push(polygon);
  746. polygon.infos = infos;
  747. polygon.on("click", (e) => {
  748. // console.log(e, "polygon");
  749. this.auditPopupShow = true;
  750. // console.log(e.latlng, "获取当前弹窗坐标111");
  751. this.popup = L.popup({ maxWidth: 700, maxHeight: 600 })
  752. .setLatLng(e.latlng)
  753. .setContent(this.createAuditDiv(cid));
  754. // .openOn(map2DViewer.map);
  755. this.auditPopupShow = false;
  756. this.popup.openOn(map2DViewer.map);
  757. this.currentCid = cid;
  758. });
  759. });
  760. },
  761. deleteSinglePolygon(polygon) {
  762. map2DViewer.map.removeLayer(polygon);
  763. },
  764. // 综合分析 - 图层显示
  765. deleteGroupFromMap(uniqueId) {
  766. if (map2DViewer.analysisGroups[uniqueId]) {
  767. map2DViewer.map.removeLayer(map2DViewer.analysisGroups[uniqueId]);
  768. }
  769. },
  770. //综合分析 - 标记疑点 - 删除面
  771. deletePolygonLayer(layer) {
  772. console.log(layer, "layer");
  773. map2DViewer.polygons[layer].forEach((polygon) => {
  774. map2DViewer.map.removeLayer(polygon);
  775. });
  776. },
  777. drawPoints(data) {
  778. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  779. let point = L.marker(data.coord, {
  780. opacity: 1,
  781. }).addTo(map2DViewer.groups["我的标记图层组"]);
  782. map2DViewer.myLabels[`label_${data.id}`] = point;
  783. }
  784. },
  785. drawLine(data, color) {
  786. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  787. let coordinates = JSON.parse(data.geojson).geometry.coordinates[0];
  788. let polyline = L.polyline(coordinates, {
  789. color: color,
  790. weight: 3,
  791. fillOpacity: color,
  792. opacity: 1,
  793. fillOpacity: 0.4,
  794. }).addTo(map2DViewer.groups["我的标记图层组"]);
  795. // zoom the map to the polyline
  796. map2DViewer.myLabels[`label_${data.id}`] = polyline;
  797. }
  798. },
  799. drawPolygon(data, color) {
  800. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  801. let coordinates = JSON.parse(data.geojson).geometry.coordinates[0];
  802. let polygon = L.polygon(coordinates, {
  803. color: color,
  804. weight: 3,
  805. fillOpacity: color,
  806. opacity: 1,
  807. fillOpacity: 0.4,
  808. }).addTo(map2DViewer.groups["我的标记图层组"]);
  809. map2DViewer.myLabels[`label_${data.id}`] = polygon;
  810. }
  811. },
  812. drawCircle(data, color) {
  813. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  814. let coordinates = JSON.parse(data.geojson).geometry.coordinates[0];
  815. if ((coordinates.length = 2)) {
  816. let from = turf.point(coordinates[0].reverse());
  817. let to = turf.point(coordinates[1].reverse());
  818. let options = { units: "kilometers" };
  819. let distance = turf.distance(from, to, options);
  820. distance = parseFloat(distance * 1000).toFixed(6);
  821. let circle = L.circle(coordinates[0].reverse(), {
  822. color: color,
  823. weight: 3,
  824. fillOpacity: color,
  825. opacity: 1,
  826. fillOpacity: 0.4,
  827. radius: Number(distance),
  828. }).addTo(map2DViewer.groups["我的标记图层组"]);
  829. map2DViewer.myLabels[`label_${data.id}`] = circle;
  830. }
  831. }
  832. },
  833. /**
  834. * 综合分析 -- 我的标记 -- 绘制单一几何体方法
  835. * @type 判断需要绘制的几何体类型
  836. */
  837. drawGeometry(type, data) {
  838. let color = "#ff0000";
  839. switch (type) {
  840. case "点":
  841. this.drawPoints(data);
  842. break;
  843. case "线":
  844. this.drawLine(data, color);
  845. break;
  846. case "面":
  847. this.drawPolygon(data, color);
  848. break;
  849. case "圆":
  850. this.drawCircle(data, color);
  851. break;
  852. }
  853. },
  854. deleteGeometry(geometry) {
  855. if (geometry) {
  856. geometry.removeFrom(map2DViewer.map);
  857. }
  858. },
  859. },
  860. };
  861. </script>
  862. <style lang="less" scoped>
  863. #map2DViewer {
  864. position: absolute;
  865. width: 100%;
  866. height: calc(100% - 60px);
  867. background-color: #003452;
  868. z-index: 1;
  869. top: 60px;
  870. left: 0px;
  871. }
  872. </style>