MapHolder.vue 35 KB

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