MapHolder.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div id="map2DViewer">
  3. <CaseAuditPopup v-show="auditPopupShow" ref="auditPopup" />
  4. </div>
  5. </template>
  6. <script>
  7. import publicFun from "@/utils/publicFunction.js";
  8. import { get } from "@/utils/request";
  9. import CaseAuditPopup from "@/components/popup/CaseAuditPopup.vue";
  10. import LabelCasePopup from "@/components/popup/LabelCasePopup.vue";
  11. export default {
  12. name: "MapHolder",
  13. components: { CaseAuditPopup, LabelCasePopup },
  14. data() {
  15. return {
  16. // 卷帘对比开关
  17. JLControlShowStatus: false,
  18. town: "祝桥镇,南汇新城镇,川沙新镇,老港镇,惠南镇,航头镇,泥城镇,书院镇,新场镇,大团镇,唐镇,曹路镇,宣桥镇,张江镇,合庆镇,周浦镇,康桥镇,三林镇,高桥镇,高东镇,金桥镇,北蔡镇,万祥镇,高行镇",
  19. auditPopupShow: false,
  20. auditPopupStatus: "normal",
  21. popup: null,
  22. currentCid: null,
  23. currentHtml: null,
  24. };
  25. },
  26. mounted() {
  27. // let a = new Vue()
  28. // console.log(a,"print Vue");
  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.getJSonData();
  43. // 地图常用渲染方法
  44. // console.log(this.$store.state.mapMethodsCollection,"methods");
  45. this.$store.state.mapMethodsCollection.set("RENDER", {
  46. addPolygonLayer: this.addPolygonLayer,
  47. setView: this.setView,
  48. deletePolygonLayer: this.deletePolygonLayer,
  49. });
  50. },
  51. beforeDestroyed() {
  52. // 当容器销毁时,需要停止监听该事件
  53. this.$bus.$off("JLControl");
  54. // 疑点审计
  55. this.$bus.$off("caseAuditEvent");
  56. // 标记疑点
  57. this.$bus.$off("labelCaseEvent");
  58. },
  59. methods: {
  60. // 地图弹窗修改
  61. createDynamicDiv(str) {
  62. // 根据ref获取组件的dom元素
  63. this.currentHtml = this.$refs.auditPopup.$el.innerHTML;
  64. console.log($(`#${str}_id`), "8888");
  65. if (this.currentHtml) {
  66. let div = document.createElement("div");
  67. div.id = str + "_id";
  68. div.className = "case-audit";
  69. // 动态创建div后赋值模板样式
  70. div.innerHTML = this.currentHtml;
  71. $(() => {
  72. // 法律法规点击事件
  73. if ($(`#${str}_id a`)) {
  74. $(`#${str}_id a`).click((e) => {
  75. console.log(e, "a label");
  76. });
  77. }
  78. // input添加点击事件
  79. if ($(`#${str}_id input`)[1]) {
  80. $(`#${str}_id input`).click((e) => {
  81. switch (e.target.defaultValue) {
  82. case "修改":
  83. this.modifyBtnEvent();
  84. break;
  85. case "确认":
  86. this.confirmBtnEvent();
  87. break;
  88. }
  89. });
  90. }
  91. });
  92. return div;
  93. }
  94. },
  95. modifyBtnEvent() {
  96. console.log("用户点击了地图中的修改按钮!");
  97. },
  98. confirmBtnEvent() {
  99. console.log("用户点击地图中的确认按钮");
  100. },
  101. // 卷帘对比
  102. JLControl() {
  103. this.JLControlShowStatus = !this.JLControlShowStatus;
  104. if (this.JLControlShowStatus) {
  105. map2DViewer.jlMap = L.tileLayer(
  106. "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d"
  107. ).addTo(map2DViewer.map);
  108. map2DViewer.jlControl = L.control
  109. .sideBySide(map2DViewer.map, map2DViewer.jlMap)
  110. .addTo(map2DViewer.map);
  111. } else {
  112. map2DViewer.map.removeControl(map2DViewer.jlControl);
  113. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  114. delete map2DViewer.jlMap;
  115. map2DViewer.jlControl = null;
  116. }
  117. },
  118. // 疑点审计
  119. caseAuditEvent() {
  120. // console.log("case audit");
  121. // 每次点击按钮后重绘弹窗
  122. if (this.currentHtml && this.currentCid) {
  123. setTimeout(() => {
  124. this.popup
  125. .setContent(this.createDynamicDiv(this.currentCid))
  126. .openOn(map2DViewer.map);
  127. }, 300);
  128. }
  129. },
  130. // 标记疑点
  131. labelCaseEvent() {
  132. // 开始绘制图形
  133. console.log("label case");
  134. },
  135. mapInit: function () {
  136. map2DViewer.map = L.map("map2DViewer", {
  137. attributionControl: false,
  138. zoomControl: false,
  139. minZoom: 10,
  140. maxZoom: 16,
  141. }).setView(systemConfig.mapViewer.center, systemConfig.mapViewer.zoom);
  142. //添加默认图层
  143. var guid = publicFun.buildGuid("baseLayer");
  144. var layer = L.esri
  145. .tiledMapLayer({
  146. url:
  147. // "http://aimap.pudong.sh:5236/maps/rest/services/basemap-shanghai-gem-blue-sh2000/mapserver/"
  148. systemConfig.mapService +
  149. "?servertype=Street_Purplish_Blue&token=" +
  150. systemConfig.token,
  151. })
  152. .addTo(map2DViewer.map);
  153. layer.guid = guid;
  154. map2DViewer.layers[guid] = layer;
  155. },
  156. // 读取浦东新区GeoJSON格式的区域数据
  157. getJSonData() {
  158. if (!map2DViewer.map) {
  159. this.mapInit();
  160. } else {
  161. get("./static/json/pdgeojson.json", "").then((geoJson) => {
  162. geoJson.features.map((feature) => {
  163. if (
  164. this.town.indexOf(feature.properties.NAME.replace("镇", "")) > -1
  165. ) {
  166. let center = turf.center(feature.geometry);
  167. this.renderPolygon(feature);
  168. }
  169. });
  170. });
  171. }
  172. },
  173. setView: function (coord, zoom) {
  174. // console.log(coord, "位置");
  175. let center = L.latLng(coord[0], coord[1]);
  176. map2DViewer.map.setView(center, zoom);
  177. },
  178. renderPolygon: function (feature) {
  179. let center = turf.center(feature.geometry);
  180. let itemvalue = JSON.parse((Math.random() * 1000).toFixed(0));
  181. let polygonData = JSON.parse(JSON.stringify(feature));
  182. let coordinates = polygonData.geometry.coordinates[0];
  183. let polygon = L.polygon(this.latLngsToReverse(coordinates), {
  184. color: "#87d8fd",
  185. weight: 3,
  186. fillColor: this.getColor(itemvalue),
  187. opacity: 1,
  188. fillOpacity: 0.4,
  189. }).addTo(map2DViewer.map);
  190. center = JSON.parse(JSON.stringify(center)).geometry.coordinates;
  191. center.reverse();
  192. let wmarker = L.circleMarker(center, {
  193. radius: 10,
  194. weight: 1,
  195. fillOpacity: 0,
  196. color: "#e6d273",
  197. });
  198. wmarker.bindLabel(feature.properties.NAME, {
  199. noHide: true,
  200. clickable: true,
  201. offset: [-25, 10],
  202. });
  203. wmarker.addTo(map2DViewer.map);
  204. L.circleMarker(center, {
  205. radius: 8,
  206. weight: 1,
  207. fillOpacity: 0,
  208. color: "#e6d273",
  209. }).addTo(map2DViewer.map);
  210. L.circleMarker(center, {
  211. radius: 5,
  212. weight: 1,
  213. fillOpacity: 1,
  214. color: "#e6d273",
  215. }).addTo(map2DViewer.map);
  216. },
  217. latLngsToReverse: function (latlngsAry) {
  218. var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry));
  219. if (typeof tempLatlngsAry[0] != "object") {
  220. return tempLatlngsAry.reverse();
  221. } else {
  222. for (var i = 0, l = tempLatlngsAry.length; i < l; i++) {
  223. tempLatlngsAry[i] = this.latLngsToReverse(tempLatlngsAry[i]);
  224. }
  225. }
  226. return tempLatlngsAry;
  227. },
  228. getColor: function (val) {
  229. var that = this;
  230. if (val < 350) {
  231. return "#e565ff";
  232. } else if (val < 700 && val >= 350) {
  233. return "#0055ff";
  234. } else {
  235. return "#00ffd5";
  236. }
  237. },
  238. // 综合分析 - 图层绘制面
  239. addPolygonLayer(data, cid, color) {
  240. // cid -- 'yongjiu'
  241. // console.log(data, cid, color);
  242. data.map((feature) => {
  243. let polygonData = JSON.parse(JSON.stringify(feature));
  244. let coordinates = polygonData.geometry.coordinates[0];
  245. let infos = polygonData.properties;
  246. let polygon = L.polygon(coordinates, {
  247. color: color,
  248. weight: 3,
  249. fillColor: color,
  250. opacity: 1,
  251. fillOpacity: 0.4,
  252. }).addTo(map2DViewer.map);
  253. map2DViewer.polygons[`${cid}_layer`].push(polygon);
  254. polygon.infos = infos;
  255. polygon.on("click", (e) => {
  256. // console.log(e, "polygon");
  257. this.auditPopupShow = true;
  258. this.popup = L.popup({ maxWidth: 700, maxHeight: 600 })
  259. .setLatLng(e.latlng)
  260. .setContent(this.createDynamicDiv("cid"));
  261. // .openOn(map2DViewer.map);
  262. this.auditPopupShow = false;
  263. this.popup.openOn(map2DViewer.map);
  264. this.currentCid = cid;
  265. });
  266. });
  267. // console.log(map2DViewer.polygons[`${cid}_layer`]);
  268. },
  269. //综合分析 - 标记疑点 - 删除面
  270. deletePolygonLayer(layer) {
  271. map2DViewer.polygons[layer].forEach((polygon) => {
  272. map2DViewer.map.removeLayer(polygon);
  273. });
  274. },
  275. },
  276. };
  277. </script>
  278. <style scoped>
  279. #map2DViewer {
  280. position: absolute;
  281. width: 100%;
  282. height: calc(100% - 60px);
  283. background-color: #003452;
  284. z-index: 1;
  285. top: 60px;
  286. left: 0px;
  287. }
  288. </style>