MapHolder.vue 12 KB

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