MapHolder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div id="map2DViewer">
  3. <CaseAuditPopup v-show="auditPopupShow" ref="auditPopup" />
  4. <BasemapChange />
  5. </div>
  6. </template>
  7. <script>
  8. import publicFun from "@/utils/publicFunction.js";
  9. import { get } from "@/utils/request";
  10. import CaseAuditPopup from "@/components/popup/CaseAuditPopup.vue";
  11. import LabelCasePopup from "@/components/popup/LabelCasePopup.vue";
  12. import BasemapChange from "@/components/map/BasemapChange.vue";
  13. export default {
  14. name: "MapHolder",
  15. components: { CaseAuditPopup, LabelCasePopup, BasemapChange },
  16. data() {
  17. return {
  18. // 卷帘对比开关
  19. JLControlShowStatus: false,
  20. town: "祝桥镇,南汇新城镇,川沙新镇,老港镇,惠南镇,航头镇,泥城镇,书院镇,新场镇,大团镇,唐镇,曹路镇,宣桥镇,张江镇,合庆镇,周浦镇,康桥镇,三林镇,高桥镇,高东镇,金桥镇,北蔡镇,万祥镇,高行镇",
  21. auditPopupShow: false,
  22. auditPopupStatus: "normal",
  23. popup: null,
  24. currentCid: null,
  25. currentHtml: null,
  26. };
  27. },
  28. mounted() {
  29. // 监听全局事件总线中的卷帘对比事件(JLControl)
  30. this.$bus.$on("JLControl", () => {
  31. this.JLControl();
  32. });
  33. this.$bus.$on("caseAuditEvent", () => {
  34. this.caseAuditEvent();
  35. });
  36. // this.$bus.$on("labelCaseEvent", () => {
  37. // this.labelCaseEvent();
  38. // });
  39. //地图初始化
  40. this.mapInit();
  41. // 初始化绘制工具
  42. // 可视化区域图
  43. this.getJSonData();
  44. // 地图常用渲染方法
  45. // console.log(this.$store.state.mapMethodsCollection,"methods");
  46. this.$store.state.mapMethodsCollection.set("RENDER", {
  47. addPolygonLayer: this.addPolygonLayer,
  48. setView: this.setView,
  49. deletePolygonLayer: this.deletePolygonLayer,
  50. });
  51. },
  52. beforeDestroyed() {
  53. // 当容器销毁时,需要停止监听该事件
  54. this.$bus.$off("JLControl");
  55. // 疑点审计
  56. this.$bus.$off("caseAuditEvent");
  57. // 标记疑点
  58. // this.$bus.$off("labelCaseEvent");
  59. },
  60. computed: {
  61. // 获取标记疑点按钮的状态
  62. getLabelCaseBtnStatus() {
  63. //疑点审计 1,0
  64. let index = this.$store.state.bottomMenuIndexs.index;
  65. let subIndex = this.$store.state.bottomMenuIndexs.subIndex;
  66. return { index, subIndex };
  67. },
  68. },
  69. watch: {
  70. getLabelCaseBtnStatus(val) {
  71. console.log(val, "标记疑点");
  72. if (val.index === 1 && val.subIndex === 1) {
  73. console.log("激活标记疑点弹窗");
  74. this.initDraw();
  75. } else {
  76. console.log("移除疑点标记事件");
  77. this.stopLabelCase();
  78. }
  79. },
  80. },
  81. methods: {
  82. // 开始标记疑点事件
  83. startLabelCase() {
  84. map2DViewer.setDrawTool({ action: "start" });
  85. },
  86. // 停止标记疑点事件
  87. stopLabelCase() {
  88. map2DViewer.setDrawTool({
  89. action: "remove",
  90. });
  91. },
  92. // 地图弹窗修改
  93. createDynamicDiv(str) {
  94. // 相关属性数据
  95. // 表格里的数据
  96. let popuppef = this.$refs.auditPopup;
  97. let tableArr = popuppef.tableArr;
  98. console.log(tableArr, "shuju");
  99. // 根据ref获取组件的dom元素
  100. this.currentHtml = this.$refs.auditPopup.$el.innerHTML;
  101. console.log($(`#${str}_id`), "8888");
  102. if (this.currentHtml) {
  103. let div = document.createElement("div");
  104. div.id = str + "_id";
  105. div.className = "case-audit";
  106. // 动态创建div后赋值模板样式
  107. div.innerHTML = this.currentHtml;
  108. $(() => {
  109. // 法律法规点击事件
  110. if ($(`#${str}_id a`)) {
  111. $(`#${str}_id a`).click((e) => {
  112. console.log(e, "显示疑点相关的弹窗");
  113. this.$store.state.lawPopupShow = true;
  114. });
  115. }
  116. // input添加点击事件
  117. if ($(`#${str}_id input`)[1]) {
  118. $(`#${str}_id input`).click((e) => {
  119. switch (e.target.defaultValue) {
  120. case "修改":
  121. this.modifyBtnEvent();
  122. break;
  123. case "确认":
  124. this.confirmBtnEvent();
  125. break;
  126. }
  127. });
  128. }
  129. });
  130. return div;
  131. }
  132. },
  133. modifyBtnEvent() {
  134. console.log("用户点击了地图中的修改按钮!");
  135. },
  136. confirmBtnEvent() {
  137. console.log("用户点击地图中的确认按钮");
  138. },
  139. // 卷帘对比
  140. JLControl() {
  141. this.JLControlShowStatus = !this.JLControlShowStatus;
  142. if (this.JLControlShowStatus) {
  143. map2DViewer.jlMap = L.tileLayer(
  144. "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d"
  145. ).addTo(map2DViewer.map);
  146. map2DViewer.jlControl = L.control
  147. .sideBySide(map2DViewer.map, map2DViewer.jlMap)
  148. .addTo(map2DViewer.map);
  149. } else {
  150. map2DViewer.map.removeControl(map2DViewer.jlControl);
  151. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  152. delete map2DViewer.jlMap;
  153. map2DViewer.jlControl = null;
  154. }
  155. },
  156. // 疑点审计
  157. caseAuditEvent() {
  158. // console.log("case audit");
  159. // 每次点击按钮后重绘弹窗
  160. if (this.currentHtml && this.currentCid) {
  161. setTimeout(() => {
  162. this.popup
  163. .setContent(this.createDynamicDiv(this.currentCid))
  164. .openOn(map2DViewer.map);
  165. }, 300);
  166. }
  167. },
  168. // 标记疑点
  169. labelCaseEvent() {
  170. // 开始绘制图形
  171. console.log("label case");
  172. // map2DViewer.setDrawTool({ action: "start" });
  173. },
  174. // 初始化引入绘制工具
  175. initDraw() {
  176. // 引入疑点标记绘制方法
  177. map2DViewer.drawToolFire = function (data) {
  178. console.log(data, "绘制的图形");
  179. };
  180. map2DViewer.setDrawTool({
  181. action: "add",
  182. offset: [150, 50],
  183. background: "#fff",
  184. color: "red",
  185. font_size: "14px",
  186. closeButton: true,
  187. iconUrl: "../../static/plugins/draw-plugin/images/marker-icon.png",
  188. });
  189. },
  190. mapInit: function () {
  191. // var crs = new L.Proj.CRS(
  192. // "EPSG:2401",
  193. // "+proj=tmerc +lat_0=0 +lon_0=121.2751921 +k=1 +x_0=0 +y_0=-3457147.81 +ellps=krass +units=m +no_defs",
  194. // {
  195. // resolutions: [
  196. // 529.1666666666666, 264.5833333333333, 132.29166666666666, 52.916666666666664, 26.458333333333332,
  197. // 13.229166666666666, 5.291666666666666, 2.645833333333333, 1.3229166666666665, 0.5291666666666666,
  198. // 0.2645833333333333, 0.13229166666666664
  199. // ],
  200. // origin: [-66000, 75000],
  201. // bounds: L.bounds([-65000, -76000], [75000, 72000])
  202. // }
  203. // );
  204. map2DViewer.map = L.map("map2DViewer", {
  205. // crs: crs,
  206. // center: [31.074472887639914, 121.72521988031804],
  207. // zoom: 1,
  208. // minZoom: 1,
  209. // maxZoom: 12
  210. attributionControl: false,
  211. zoomControl: false,
  212. minZoom: 10,
  213. maxZoom: 16,
  214. }).setView(systemConfig.mapViewer.center, systemConfig.mapViewer.zoom);
  215. //添加默认图层
  216. var guid = publicFun.buildGuid("baseLayer");
  217. var layer = L.esri
  218. .tiledMapLayer({
  219. url:
  220. systemConfig.mapService +
  221. "?servertype=Street_Purplish_Blue&token=" +
  222. systemConfig.token,
  223. // url: "http://aimap.pudong.sh:5236/maps/rest/services/basemap-shanghai-gem-blue-sh2000/mapserver",
  224. // tileSize: 512
  225. })
  226. .addTo(map2DViewer.map);
  227. layer.guid = guid;
  228. map2DViewer.layers[guid] = layer;
  229. },
  230. // 读取浦东新区GeoJSON格式的区域数据
  231. getJSonData() {
  232. if (!map2DViewer.map) {
  233. this.mapInit();
  234. } else {
  235. get("./static/json/pdgeojson.json", "").then((geoJson) => {
  236. geoJson.features.map((feature) => {
  237. if (
  238. this.town.indexOf(feature.properties.NAME.replace("镇", "")) > -1
  239. ) {
  240. let center = turf.center(feature.geometry);
  241. this.renderPolygon(feature);
  242. }
  243. });
  244. });
  245. }
  246. },
  247. setView: function (coord, zoom) {
  248. // console.log(coord, "位置");
  249. let center = L.latLng(coord[0], coord[1]);
  250. map2DViewer.map.setView(center, zoom);
  251. },
  252. renderPolygon: function (feature) {
  253. let center = turf.center(feature.geometry);
  254. let itemvalue = JSON.parse((Math.random() * 1000).toFixed(0));
  255. let polygonData = JSON.parse(JSON.stringify(feature));
  256. let coordinates = polygonData.geometry.coordinates[0];
  257. let polygon = L.polygon(this.latLngsToReverse(coordinates), {
  258. color: "#87d8fd",
  259. weight: 3,
  260. fillColor: this.getColor(itemvalue),
  261. opacity: 1,
  262. fillOpacity: 0.4,
  263. }).addTo(map2DViewer.map);
  264. center = JSON.parse(JSON.stringify(center)).geometry.coordinates;
  265. center.reverse();
  266. let wmarker = L.circleMarker(center, {
  267. radius: 10,
  268. weight: 1,
  269. fillOpacity: 0,
  270. color: "#e6d273",
  271. });
  272. wmarker.bindLabel(feature.properties.NAME, {
  273. noHide: true,
  274. clickable: true,
  275. offset: [-25, 10],
  276. });
  277. wmarker.addTo(map2DViewer.map);
  278. L.circleMarker(center, {
  279. radius: 8,
  280. weight: 1,
  281. fillOpacity: 0,
  282. color: "#e6d273",
  283. }).addTo(map2DViewer.map);
  284. L.circleMarker(center, {
  285. radius: 5,
  286. weight: 1,
  287. fillOpacity: 1,
  288. color: "#e6d273",
  289. }).addTo(map2DViewer.map);
  290. },
  291. latLngsToReverse: function (latlngsAry) {
  292. var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry));
  293. if (typeof tempLatlngsAry[0] != "object") {
  294. return tempLatlngsAry.reverse();
  295. } else {
  296. for (var i = 0, l = tempLatlngsAry.length; i < l; i++) {
  297. tempLatlngsAry[i] = this.latLngsToReverse(tempLatlngsAry[i]);
  298. }
  299. }
  300. return tempLatlngsAry;
  301. },
  302. getColor: function (val) {
  303. var that = this;
  304. if (val < 350) {
  305. return "#e565ff";
  306. } else if (val < 700 && val >= 350) {
  307. return "#0055ff";
  308. } else {
  309. return "#00ffd5";
  310. }
  311. },
  312. // 综合分析 - 图层绘制面
  313. addPolygonLayer(data, cid, color) {
  314. // cid -- 'yongjiu'
  315. // console.log(data, cid, color);
  316. data.map((feature) => {
  317. let polygonData = JSON.parse(JSON.stringify(feature));
  318. let coordinates = polygonData.geometry.coordinates[0];
  319. let infos = polygonData.properties;
  320. let polygon = L.polygon(coordinates, {
  321. color: color,
  322. weight: 3,
  323. fillColor: color,
  324. opacity: 1,
  325. fillOpacity: 0.4,
  326. }).addTo(map2DViewer.map);
  327. map2DViewer.polygons[`${cid}_layer`].push(polygon);
  328. polygon.infos = infos;
  329. polygon.on("click", (e) => {
  330. // console.log(e, "polygon");
  331. this.auditPopupShow = true;
  332. this.popup = L.popup({ maxWidth: 700, maxHeight: 600 })
  333. .setLatLng(e.latlng)
  334. .setContent(this.createDynamicDiv("cid"));
  335. // .openOn(map2DViewer.map);
  336. this.auditPopupShow = false;
  337. this.popup.openOn(map2DViewer.map);
  338. this.currentCid = cid;
  339. });
  340. });
  341. // console.log(map2DViewer.polygons[`${cid}_layer`]);
  342. },
  343. //综合分析 - 标记疑点 - 删除面
  344. deletePolygonLayer(layer) {
  345. map2DViewer.polygons[layer].forEach((polygon) => {
  346. map2DViewer.map.removeLayer(polygon);
  347. });
  348. },
  349. },
  350. };
  351. </script>
  352. <style scoped>
  353. #map2DViewer {
  354. position: absolute;
  355. width: 100%;
  356. height: calc(100% - 60px);
  357. background-color: #003452;
  358. z-index: 1;
  359. top: 60px;
  360. left: 0px;
  361. }
  362. </style>