Map.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. <template>
  2. <div id="mapContainer"></div>
  3. <LeftMenu :dataList="dataList"></LeftMenu>
  4. <VueJsonEditor v-if="editWinFlag" :editDataList="editDataList"></VueJsonEditor>
  5. <Table :tableData="tableData" :columnModel="columnModel" :searchText="tableSearchText" v-if="tableShow" :isview="tableShow" :close="handleClose"></Table>
  6. <editManage
  7. v-if="isContentShow"
  8. :isShow="isContentShow"
  9. :column-model="columnModel"
  10. :column="columnData"
  11. :dialog-title="dialogTitle"
  12. :item="contentItem"
  13. :is-view="isContentView"
  14. :close="handleEditClose"
  15. ></editManage>
  16. <!-- 十字准线元素 -->
  17. <div class="map-center-crosshair" v-if="btn_Aim_show"></div>
  18. <div class="tips">
  19. <div id="tipsText" @click="copyDivText('#tipsText')">位置信息:{{mouseCenter}}</div>
  20. </div>
  21. <div class="select-item" v-if="btn_data_show">
  22. <el-select
  23. v-model="selectText"
  24. multiple
  25. collapse-tags
  26. collapse-tags-tooltip
  27. placeholder="请选择"
  28. size="small"
  29. @change="handleSelChange"
  30. style="width: 270px"
  31. >
  32. <el-option
  33. v-for="item in options"
  34. :key="item.value"
  35. :label="item.label"
  36. :value="item.value"
  37. />
  38. </el-select>
  39. </div>
  40. <div class="right-btn">
  41. <el-icon size="20" :color="btn_Aim_show == true ? '#067bc9' : '#000'" title="中心基准线" class="icon" @click="toggleItem('1');">
  42. <Aim />
  43. </el-icon>
  44. <el-divider></el-divider>
  45. <el-icon size="20" :color="btn_data_show == true ? '#067bc9' : '#000'" title="图层数据" class="icon" @click="toggleItem('2');">
  46. <Coin />
  47. </el-icon>
  48. <el-divider></el-divider>
  49. <el-icon size="20" :color="editFlag == true ? '#067bc9' : '#000'" title="编辑图层数据" class="icon" @click="toggleItem('3');">
  50. <Edit />
  51. </el-icon>
  52. <el-divider></el-divider>
  53. <el-icon size="20" :color="btn_area_show == true ? '#067bc9' : '#000'" title="辖区数据" class="icon" @click="toggleItem('4');">
  54. <PictureRounded />
  55. </el-icon>
  56. </div>
  57. </template>
  58. <script>
  59. import axios from 'axios'
  60. import qs from 'qs'
  61. import { ElMessage } from "element-plus";
  62. import LeftMenu from "@/components/LeftMenu.vue";
  63. import VueJsonEditor from '@/components/JsonEditor.vue';
  64. import Table from '@/components/Table.vue';
  65. import UTIL from '@/utils/util'
  66. import commonAPI from '@/api/common'
  67. import api from '@/api/content'
  68. import editManage from '@/components/editManage.vue';
  69. export default {
  70. name: "Map",
  71. components: {
  72. VueJsonEditor,
  73. LeftMenu,
  74. Table,
  75. editManage,
  76. },
  77. data() {
  78. return {
  79. mouseCenter: "121.184665, 31.158609",
  80. center: [121.184665, 31.158609],
  81. dataList: "",
  82. areaDataList: [],
  83. tableData:[],
  84. columnModel:[],
  85. tableShow:false,
  86. tableSearchText:"",
  87. hoveredPolygonId: null,
  88. areaMarkers: [],
  89. btn_data_show: true,
  90. btn_Aim_show: false,
  91. btn_area_show: true,
  92. mapEditDraw: null,
  93. editDataList: {},
  94. editFlag: false,
  95. editWinFlag: false,
  96. dialogTitle: "员工信息",
  97. isContentShow: false,
  98. isContentView: false,
  99. // columnModel: {},
  100. columnData: {
  101. title: "",
  102. },
  103. contentItem: {},
  104. arrParam: ["补查查询串","补查相似度","补查原因","补查匹配地址","补查点坐标","补查匹配名称","补查buffer_m","补查状态"], //过滤字段
  105. selectText: [],
  106. options: [],
  107. fontText:["concat"]// "concat", ["get", "GUID"], "\n", ["get", "match_status"],"\n", ["get", "range_shape"]
  108. };
  109. },
  110. mounted() {
  111. let that = this;
  112. that.initData();
  113. },
  114. methods: {
  115. saveFeature(data){
  116. if(!data.properties.dms_id){
  117. ElMessage.error("请选择正确数据进行保存");
  118. return;
  119. }
  120. let content = {};
  121. content["id"] = data.properties.dms_id;
  122. content["c_polygon"] = UTIL.geojsonToWkt(data.geometry);
  123. content["c_properties"] = data.properties;
  124. let params = {
  125. content: JSON.stringify(content),
  126. columnId: 1719,
  127. modelId: 1753,
  128. };
  129. // console.log(params);
  130. commonAPI.updateContent(params).then(res => {
  131. if(res.code == 200){
  132. ElMessage.success("保存成功");
  133. this.getVectorData();
  134. // 清空绘制工具
  135. this.mapEditDraw.clearAll();
  136. }else{
  137. ElMessage.error(res.msg);
  138. }
  139. })
  140. },
  141. closeJsonEditor(){
  142. // 清空编辑数据
  143. this.editDataList = {};
  144. this.editWinFlag = false;
  145. // 确保vector-data数据源存在且为有效的GeoJSON对象
  146. if (window.mapboxMap.getSource('vector-data') && this.dataList) {
  147. window.mapboxMap.getSource('vector-data').setData(this.dataList);
  148. }
  149. // 确保states数据源存在且为有效的GeoJSON对象
  150. if (window.mapboxMap.getSource('states') && this.areaDataList) {
  151. window.mapboxMap.getSource('states').setData(this.areaDataList);
  152. }
  153. // 清空绘制工具
  154. this.mapEditDraw.clearAll();
  155. },
  156. toggleItem(item){
  157. if(item == "1"){
  158. if(this.btn_Aim_show){
  159. this.btn_Aim_show = false;
  160. }else{
  161. this.btn_Aim_show = true;
  162. }
  163. }else if(item == "2"){
  164. if(this.btn_data_show){
  165. this.btn_data_show = false;
  166. window.mapboxMap.setLayoutProperty('data-fill-layer', 'visibility', 'none')
  167. window.mapboxMap.setLayoutProperty('data-line-layer', 'visibility', 'none')
  168. window.mapboxMap.setLayoutProperty('data-symbol-layer', 'visibility', 'none')
  169. }else{
  170. this.btn_data_show = true;
  171. window.mapboxMap.setLayoutProperty('data-fill-layer', 'visibility', 'visible')
  172. window.mapboxMap.setLayoutProperty('data-line-layer', 'visibility', 'visible')
  173. window.mapboxMap.setLayoutProperty('data-symbol-layer', 'visibility', 'visible')
  174. }
  175. }else if(item == "3"){
  176. this.editDataList = {};
  177. this.editFlag = !this.editFlag;
  178. if(!this.editFlag){
  179. this.editWinFlag = false;
  180. }
  181. this.toggleEditMode(this.editFlag);
  182. window.mapboxMap.getSource('states').setData(this.areaDataList);
  183. window.mapboxMap.getSource('vector-data').setData(this.dataList);
  184. this.btn_area_show = false;
  185. window.mapboxMap.setLayoutProperty('state-fills', 'visibility', 'none')
  186. window.mapboxMap.setLayoutProperty('state-borders', 'visibility', 'none')
  187. window.mapboxMap.setLayoutProperty('state-borders-layer-3', 'visibility', 'none')
  188. window.mapboxMap.setLayoutProperty('state-borders-layer-2', 'visibility', 'none')
  189. window.mapboxMap.setLayoutProperty('state-borders-layer-1', 'visibility', 'none')
  190. }else if(item == "4"){
  191. if(this.btn_area_show){
  192. this.btn_area_show = false;
  193. window.mapboxMap.setLayoutProperty('state-fills', 'visibility', 'none')
  194. window.mapboxMap.setLayoutProperty('state-borders', 'visibility', 'none')
  195. window.mapboxMap.setLayoutProperty('state-borders-layer-3', 'visibility', 'none')
  196. window.mapboxMap.setLayoutProperty('state-borders-layer-2', 'visibility', 'none')
  197. window.mapboxMap.setLayoutProperty('state-borders-layer-1', 'visibility', 'none')
  198. }else{
  199. this.btn_area_show = true;
  200. window.mapboxMap.setLayoutProperty('state-fills', 'visibility', 'visible')
  201. window.mapboxMap.setLayoutProperty('state-borders', 'visibility', 'visible')
  202. window.mapboxMap.setLayoutProperty('state-borders-layer-3', 'visibility', 'visible')
  203. window.mapboxMap.setLayoutProperty('state-borders-layer-2', 'visibility', 'visible')
  204. window.mapboxMap.setLayoutProperty('state-borders-layer-1', 'visibility', 'visible')
  205. }
  206. }
  207. },
  208. initData() {
  209. this.creatMap();
  210. this.getModelById();
  211. },
  212. //根据模型id查询模型详情
  213. getModelById() {
  214. let that = this;
  215. let requestParams = {
  216. modelId: webConfig.columnArr[0].mid, // 申勤员工ID
  217. };
  218. api.getColumnModel(requestParams).then((res) => {
  219. // console.log(res);
  220. if (res.code === 200) {
  221. that.columnModel = res.content;
  222. that.columnModel.modelId = webConfig.columnArr[0].mid;
  223. that.columnModel.columnId = webConfig.columnArr[0].id;
  224. that.columnData = that.columnModel;
  225. }
  226. });
  227. },
  228. //根据内容id查询内容详情
  229. getContentById(item) {
  230. let that = this;
  231. let requestParams = {
  232. columnId: item.column_id,
  233. contentId: item.id,
  234. };
  235. // console.log(item);
  236. api.getContentById(requestParams).then((data) => {
  237. if (data.code === 200) {
  238. that.contentItem = data.content;
  239. // that.contentItem.phone = that.formatPhoneNumber(that.contentItem.phone);
  240. that.isContentShow = true;
  241. that.isContentView = false;
  242. }
  243. });
  244. },
  245. //关闭编辑弹窗
  246. handleEditClose() {
  247. let guid = sessionStorage.getItem('guid');
  248. if(guid){
  249. this.handleMoreClick(guid);
  250. }else{
  251. this.$parent.getDmsDataList();
  252. this.isContentShow = false;
  253. this.isContentView = false;
  254. this.contentItem = {};
  255. }
  256. },
  257. handleClose() {
  258. this.tableShow = false;
  259. },
  260. creatMap() {
  261. let that = this;
  262. mapboxgl.accessToken = webConfig.MAPBOX_ACCESS_TOKEN;
  263. window.mapboxMap = new mapboxgl.Map({
  264. container: 'mapContainer',
  265. //style: 'mapbox://styles/mapbox/standard',
  266. //stype:'mapbox://styles/mapbox/streets-v11',
  267. //style: 'mapbox://styles/mapbox/satellite-v9', // 使用卫星图作为基础样式,你也可以选择其他基础样式或者设置为空字符串''来创建空白底图
  268. style: {
  269. "version": 8,
  270. "sources": {},
  271. "layers": [],
  272. "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf" // 添加字体服务
  273. },
  274. projection: 'equirectangular', // globe 球体投影 mercator 平面墨卡托投影 equirectangular WGS84平面投影
  275. zoom: 12, // 初始大小
  276. minZoom:9,
  277. maxZoom:18,
  278. center: that.center, // 中心点
  279. locale: 'zh-CN', // 设置语言为中文
  280. doubleClickZoom: false // 禁用双击缩放
  281. });
  282. window.mapboxMap.addControl(new mapboxgl.NavigationControl(), 'bottom-right');
  283. window.mapboxMap.on('load', function() {
  284. // 加载单个图标
  285. // window.mapboxMap.loadImage('./static/image/location3.png', // 可换成你的图片地址
  286. // function (error, image) {
  287. // if (error) throw error;
  288. // window.mapboxMap.addImage('location-icon', image);
  289. // })
  290. // 定义你要加载的多个图标
  291. const icons = [
  292. { name: "location-icon", url: "./static/image/location.png" },
  293. { name: "location-icon2", url: "./static/image/location2.png" },
  294. { name:"location-icon3", url: "./static/image/location3.png" },
  295. { name:"location-center", url: "./static/image/center.png" }
  296. ];
  297. //批量加载所有图标(核心代码)
  298. icons.map(icon => {
  299. return new Promise((resolve, reject) => {
  300. window.mapboxMap.loadImage(icon.url, (error, image) => {
  301. if (error) reject(error);
  302. window.mapboxMap.addImage(icon.name, image); // 注册图标
  303. resolve();
  304. });
  305. });
  306. });
  307. that.initBaseMap();
  308. // 初始化
  309. that.mapEditDraw = new MapDraw.init(window.mapboxMap, {
  310. // 编辑完成 → 自动接收最新图形
  311. onEditComplete: (data) => {
  312. // console.log("===mapEditDraw返回数据===:", data);
  313. if(data.properties.dms_id){// 对dms_id进行判断
  314. that.editDataList = data;
  315. }
  316. // 你可以在这里提交后端接口,将数据保存到数据库
  317. }
  318. });
  319. window.mapEditDraw = that.mapEditDraw;
  320. // console.log("mapEditDraw:", that.mapEditDraw);
  321. })
  322. that.drawAreaFeature();
  323. this.getVectorData();
  324. },
  325. initBaseMap(type){
  326. let that = this;
  327. // window.mapboxMap.setStyle('');
  328. let titleStyle = webConfig.MAPBOX_TILES_NORMAL;
  329. if(type == "zwb"){
  330. titleStyle = webConfig.MAPBOX_TILES_NORMAL;
  331. }else if(type == "asb"){
  332. titleStyle = webConfig.MAPBOX_TILES_BLUE;
  333. }else if(type == "yxt"){
  334. titleStyle = webConfig.MAPBOX_TILES_YXT;
  335. // window.mapboxMap.setStyle('mapbox://styles/mapbox/satellite-v9');
  336. }
  337. // if(type != "yxt"){
  338. if(window.mapboxMap.getSource('custom-tiles')){
  339. window.mapboxMap.getSource('custom-tiles').setTiles([titleStyle]);
  340. }else{
  341. window.mapboxMap.addSource('custom-tiles', {
  342. 'type': 'raster',
  343. 'tiles': [titleStyle], // 这里使用你的Tile服务URL
  344. 'tileSize': 512 // 瓦片大小,通常为256x256像素
  345. });
  346. window.mapboxMap.addLayer({
  347. 'id': 'custom-tiles-layer',
  348. 'type': 'raster',
  349. 'source': 'custom-tiles',
  350. 'source-layer': 'custom-tiles', // 如果需要的话,指定源层名
  351. 'minzoom': 0,
  352. 'maxzoom': 20
  353. });
  354. }
  355. // }
  356. window.mapboxMap.on('mouseenter', ['data-fill-layer'], function () {
  357. window.mapboxMap.getCanvas().style.cursor = 'pointer';
  358. });
  359. window.mapboxMap.on('mouseleave', ['data-fill-layer'], function (e) {
  360. window.mapboxMap.getCanvas().style.cursor = '';
  361. });
  362. window.mapboxMap.on('mouseleave', ['state-fills'], function (e) {
  363. window.mapboxMap.getCanvas().style.cursor = '';
  364. if (that.hoveredPolygonId !== null && that.hoveredPolygonId != undefined) {
  365. window.mapboxMap.setFeatureState(
  366. { source: 'states', id: that.hoveredPolygonId },
  367. { hover: false }
  368. );
  369. }
  370. that.hoveredPolygonId = null;
  371. });
  372. window.mapboxMap.on('mousemove', ['state-fills'], function(e) {
  373. let that = this;
  374. if (e.features.length > 0) {
  375. if (that.hoveredPolygonId !== null && that.hoveredPolygonId != undefined) {
  376. window.mapboxMap.setFeatureState(
  377. { source: 'states', id: that.hoveredPolygonId },
  378. { hover: false }
  379. );
  380. }
  381. that.hoveredPolygonId = e.features[0].id;
  382. window.mapboxMap.setFeatureState(
  383. { source: 'states', id: that.hoveredPolygonId },
  384. { hover: true }
  385. );
  386. }
  387. });
  388. window.mapboxMap.on('move', () => {
  389. let that = this;
  390. if(that.btn_Aim_show == true){
  391. that.getCenterPoint();
  392. }
  393. })
  394. window.mapboxMap.on('mousemove', (e) => {
  395. let that = this;
  396. if(that.btn_Aim_show == false){
  397. that.mouseCenter = `${e.lngLat.lng.toFixed(6)}, ${e.lngLat.lat.toFixed(6)}`;
  398. }
  399. })
  400. window.mapboxMap.on('zoom', () => {
  401. let that = this;
  402. const zoom = window.mapboxMap.getZoom();
  403. // that.areaMarkers.forEach(marker => {
  404. // marker.style.display = zoom >= 14 ? 'none' : 'block';
  405. // });
  406. // const markers = document.querySelectorAll('.mapboxgl-marker');
  407. // markers.forEach(marker => {
  408. // marker.style.display = zoom >= 14 ? 'none' : 'block';
  409. // });
  410. });
  411. // window.mapboxMap.on('click', function(e) {
  412. // // that.editDataList = fet;
  413. // console.log("仅获取 click 的要素:", e);
  414. // if (that.editFlag) return;
  415. // // 关键:只查询 data-fill-layer,过滤掉所有其他图层
  416. // const features = window.mapboxMap.queryRenderedFeatures(e.point, {
  417. // layers: ['data-fill-layer'] // 只取这个图层
  418. // });
  419. // // console.log("仅获取e的要素:", e);
  420. // if (!features.length) return;
  421. // // 现在最多只有 1 个要素 → 绝对不会乱
  422. // const feature = features[0];
  423. // console.log("仅获取 feature 的要素:", feature);
  424. // // 深拷贝 Geometry:绝对避免引用错乱
  425. // const fet = {
  426. // type: "Feature",
  427. // geometry: JSON.parse(JSON.stringify(feature.geometry)),
  428. // properties: { ...feature.properties }
  429. // };
  430. // // console.log("仅获取 data-fill-layer 的要素:", fet);
  431. // // 以下弹窗(注意要使用 fet.properties)
  432. // let str = "";
  433. // for (let item in fet.properties) {
  434. // if (UTIL.isChinese(item)) {
  435. // str += `<p style="margin:2px 0;">${item}:${fet.properties[item]}</p>`;
  436. // }
  437. // }
  438. // const popupContent = `
  439. // <div style="font-size:14px;line-height:1.6;padding:10px;">
  440. // <h4 style="margin:0 0 6px 0;color:#222;">详细信息</h4>
  441. // ${str}
  442. // </div>
  443. // `;
  444. // if (window.popup) window.popup.remove();
  445. // window.popup = new mapboxgl.Popup({
  446. // closeButton: true,
  447. // className: 'custom-popup',
  448. // maxWidth: '500px'
  449. // })
  450. // .setLngLat(e.lngLat)
  451. // .setHTML(popupContent)
  452. // .addTo(window.mapboxMap);
  453. // });
  454. window.mapboxMap.on('click', that.mapClickValue);
  455. },
  456. mapClickValue(e){
  457. let that = this;
  458. // that.editDataList = fet;
  459. // console.log("仅获取 click 的要素:", e);
  460. // 关键:只查询 data-fill-layer,过滤掉所有其他图层
  461. const features = window.mapboxMap.queryRenderedFeatures(e.point, {
  462. layers: ['data-fill-layer'] // 只取这个图层
  463. });
  464. that.tableShow = false;
  465. if (that.editFlag){
  466. if (features.length){
  467. that.editWinFlag = true;
  468. }else{
  469. // that.editWinFlag = false;
  470. }
  471. return;
  472. };
  473. // console.log("仅获取e的要素:", e);
  474. if (!features.length) return;
  475. // 现在最多只有 1 个要素 → 绝对不会乱
  476. const feature = features[0];
  477. // console.log("仅获取 feature 的要素:", feature);
  478. // 深拷贝 Geometry:绝对避免引用错乱
  479. const fet = {
  480. type: "Feature",
  481. geometry: JSON.parse(JSON.stringify(feature.geometry)),
  482. properties: { ...feature.properties }
  483. };
  484. // console.log("仅获取 data-fill-layer 的要素:", fet);
  485. // 以下弹窗(注意要使用 fet.properties)
  486. let str = "";
  487. for (let item in fet.properties) {
  488. // console.log(item);
  489. if (UTIL.isChinese(item) && !that.arrParam.includes(item)) {
  490. str += `<p style="margin:2px 0;">${item}:${fet.properties[item]}</p>`;
  491. }
  492. }
  493. const popupContent = `
  494. <div style="font-size:14px;line-height:1.6;padding:10px;">
  495. <h4 style="margin:0 0 6px 0;color:#222;"><span>内容信息</span><span class="more" id="popup-more-btn">员工信息>></span></h4>
  496. ${str}
  497. </div>
  498. `;
  499. if (window.popup) window.popup.remove();
  500. window.popup = new mapboxgl.Popup({
  501. closeButton: true,
  502. className: 'custom-popup',
  503. maxWidth: '500px'
  504. })
  505. .setLngLat(e.lngLat)
  506. .setHTML(popupContent)
  507. .addTo(window.mapboxMap);
  508. setTimeout(() => {
  509. const moreBtn = document.getElementById('popup-more-btn');
  510. if (moreBtn) {
  511. moreBtn.addEventListener('click', () => {
  512. // that.tableShow = false;
  513. that.handleMoreClick(fet.properties.GUID);
  514. sessionStorage.setItem('guid', fet.properties.GUID);
  515. });
  516. }
  517. }, 0);
  518. },
  519. // 处理弹窗中"更多"按钮点击
  520. handleMoreClick(guid) {
  521. const that = this;
  522. //1743 项目数据 1742 申勤员工
  523. // 排序条件orderByType 1 升序 2 降序
  524. let requestParams = {
  525. columnId: webConfig.columnArr[0].id,
  526. states: "0,1,2,3",
  527. orderBy: JSON.stringify([{ field: "update_time", orderByType: 2 }]),
  528. pageSize: 9999,
  529. page: 0,
  530. };
  531. console.log("guid:", guid);
  532. requestParams.search = JSON.stringify([
  533. ...(requestParams.search ? JSON.parse(requestParams.search) : []),
  534. {
  535. field: "c_xmguid", // 申勤员工 c_xmguid 项目数据 c_guid
  536. searchType: 2,
  537. content: { value: guid },
  538. },
  539. ]);
  540. commonAPI.getDmsDataList(requestParams).then((res) => {
  541. if (res.code == 200){
  542. let data = res.content.data;
  543. data = data.map(item => {
  544. // 给每个属性名称添加 c_ 前缀
  545. const newItem = {};
  546. for (const key in item) {
  547. // 如果已经有c_
  548. if (key.includes("c_")) {
  549. let itemkey = key.replace(/c_/g, "");
  550. newItem['c_' + itemkey] = item[key];
  551. }else{
  552. newItem[key] = item[key];
  553. }
  554. }
  555. return newItem;
  556. })
  557. // console.log("data:", data);
  558. that.tableData = data;
  559. that.tableData.sort((a, b) => a.c_xm.localeCompare(b.c_xm, 'zh-CN'))
  560. that.tableSearchText = "";
  561. if(!that.tableShow){
  562. that.tableShow = true;
  563. }
  564. that.contentItem = data;
  565. that.isContentShow = false;
  566. that.isContentView = false;
  567. }else{
  568. this.$message({ message: '无员工数据', type: 'info' })
  569. }
  570. });
  571. },
  572. upTableData(data){
  573. // console.log("data:", data);
  574. const that = this;
  575. that.tableData = data;
  576. that.tableData.sort((a, b) => a.c_xm.localeCompare(b.c_xm, 'zh-CN'))
  577. },
  578. setTableShow(data,text){
  579. // console.log("data:", data);
  580. const that = this;
  581. that.tableShow = false;
  582. // 使用 $nextTick 确保组件先销毁再重建
  583. that.$nextTick(() => {
  584. that.tableShow = true;
  585. that.tableSearchText = text;
  586. that.tableData = data;
  587. that.tableData.sort((a, b) => a.c_xm.localeCompare(b.c_xm, 'zh-CN'))
  588. });
  589. // console.log("that.tableSearchText:", that.tableSearchText);
  590. },
  591. // 复制指定元素内的文本
  592. copyDivText(selector) {
  593. const el = document.querySelector(selector);
  594. if (!el) return ElMessage({
  595. message: "未找到内容",
  596. type: "error",
  597. duration: 1500
  598. });;
  599. // 创建临时文本域
  600. const text = el.innerText.trim();
  601. this.$copyText(text);
  602. // navigator.clipboard.writeText(text).then(() => {
  603. // ElMessage({
  604. // message: "复制成功",
  605. // type: "success",
  606. // duration: 1500
  607. // });
  608. // }).catch(err => {
  609. // ElMessage({
  610. // message: "复制失败",
  611. // type: "error",
  612. // duration: 1500
  613. // });
  614. // });
  615. },
  616. toggleEditMode(isEdit){
  617. let that = this;
  618. that.editFlag = isEdit;
  619. // console.log("isEdit:", isEdit);
  620. // if(isEdit){
  621. // this.editWinFlag = true;
  622. // window.mapboxMap.off('click', that.mapClickValue)
  623. // this.mapEditDraw.setEditLayerIds(['data-fill-layer']);
  624. // }else{
  625. // window.mapboxMap.on('click', that.mapClickValue);
  626. // this.mapEditDraw.setEditLayerIds([]);
  627. // }
  628. window.mapboxMap.off('click', that.mapClickValue)
  629. window.mapboxMap.on('click', that.mapClickValue);
  630. this.mapEditDraw.setEditLayerIds(['data-fill-layer']);
  631. that.mapEditDraw.isEdit(isEdit);
  632. },
  633. getCenterPoint(){
  634. let that = this;
  635. let center = window.mapboxMap.getCenter();
  636. that.mouseCenter = `${center.lng.toFixed(6)}, ${center.lat.toFixed(6)}`;
  637. // that.drawCenterPoint(center);
  638. },
  639. drawCenterPoint(center){
  640. let jsondata = {
  641. type: 'FeatureCollection',
  642. features: [
  643. {
  644. type: 'Feature',
  645. properties: {
  646. icon: 'location-center'
  647. },
  648. geometry: {
  649. type: 'Point',
  650. coordinates: [center.lng, center.lat]
  651. }
  652. }
  653. ]
  654. };
  655. if(window.mapboxMap.getSource('center-point-source')){
  656. window.mapboxMap.getSource('center-point-source').setData(jsondata);
  657. }else{
  658. window.mapboxMap.addSource('center-point-source', {
  659. type: 'geojson',
  660. data: jsondata
  661. });
  662. window.mapboxMap.addLayer({
  663. id: 'location-layer',
  664. type: 'symbol', // symbol = 图标/文字图层
  665. source: 'center-point-source',
  666. layout: {
  667. 'icon-image': 'location-center', // 使用自定义图标
  668. 'icon-size': 0.5, // 图标大小
  669. 'icon-allow-overlap': true, // 允许图标重叠
  670. 'icon-rotate': 0, // 旋转角度
  671. 'icon-offset': [0, -20] // 图标偏移(上下左右)
  672. },
  673. paint: {
  674. 'icon-opacity': 1 // 透明度
  675. }
  676. },null);
  677. }
  678. window.mapboxMap.moveLayer('location-layer');
  679. },
  680. drawAreaFeature(){
  681. let that = this;
  682. // 初始化底图
  683. fetch("./static/data/area.geojson").then((response)=>{ return response.json();})
  684. .then((data)=>{
  685. let dataJson = data;
  686. dataJson.features.map((item, index) => {
  687. item['id'] = index
  688. // item.properties['color'] = '#9b46e1'
  689. // item.properties['height'] = Math.floor(Math.random() * (1000 - 9500 + 1)) + 9500
  690. let name = item.properties.name;
  691. let center = turf.center(item).geometry.coordinates; // 自动计算面中心点
  692. // 创建 HTML 元素
  693. let el = document.createElement('div');
  694. el.className = 'area-name';
  695. el.innerText = name;
  696. // 添加到地图
  697. let marker = new mapboxgl.Marker(el, { anchor: 'center' })
  698. .setLngLat(center)
  699. .addTo(window.mapboxMap);
  700. that.areaMarkers.push(marker);
  701. });
  702. that.areaDataList = dataJson;
  703. window.mapboxMap.addSource('states', {
  704. 'type': 'geojson',
  705. 'data': dataJson,
  706. 'lineMetrics': true
  707. });
  708. window.mapboxMap.addLayer({
  709. 'id': 'state-fills',
  710. 'type': 'fill-extrusion',
  711. 'source': 'states',
  712. 'maxzoom': 14,
  713. 'layout': {},
  714. 'paint': {
  715. 'fill-extrusion-color': [
  716. 'case',
  717. ['boolean', ['feature-state', 'hover'], false],
  718. // 'rgba(155,70,225,0.80)',// 鼠标移入颜色
  719. // 'rgba(250,121,3,0.80)', // 默认颜色
  720. 'rgba(0, 150, 255, 0.8)', // 默认颜色
  721. 'rgba(25,172,230,0.8)' // 默认颜色
  722. ],
  723. "fill-extrusion-opacity":0.2,
  724. // 从source 'height'属性获取填充-挤出-高度。
  725. 'fill-extrusion-height': ['get', 'height'],
  726. // 开启垂直渐变(自动上下明暗过渡)
  727. 'fill-extrusion-vertical-gradient': true,
  728. }
  729. });
  730. window.mapboxMap.addLayer({
  731. id: 'state-borders-layer-1',
  732. type: 'line',
  733. source: 'states',
  734. paint: {
  735. 'line-color': 'rgba(0, 150, 255, 0.15)',
  736. 'line-width': 20, // 最宽
  737. 'line-blur': 10, // 最虚
  738. }
  739. });
  740. // //第2层:中间层,中等宽度、中等模糊、中等透明度
  741. window.mapboxMap.addLayer({
  742. id: 'state-borders-layer-2',
  743. type: 'line',
  744. source: 'states',
  745. paint: {
  746. 'line-color': 'rgba(0, 150, 255, 0.3)',
  747. 'line-width': 10,
  748. 'line-blur': 5,
  749. }
  750. });
  751. // // 4. 第3层:内层,较窄、较低模糊、较高透明度
  752. window.mapboxMap.addLayer({
  753. id: 'state-borders-layer-3',
  754. type: 'line',
  755. source: 'states',
  756. paint: {
  757. 'line-color': 'rgba(0, 150, 255, 0.8)',
  758. 'line-width': 5,
  759. 'line-blur': 3,
  760. }
  761. });
  762. window.mapboxMap.addLayer({
  763. 'id': 'state-borders',
  764. 'type': 'line',
  765. 'source': 'states',
  766. 'layout': {},
  767. 'paint': {
  768. 'line-color': '#05f1fc',
  769. 'line-width': 1
  770. }
  771. });
  772. }).catch((error)=>{})
  773. },
  774. getVectorData() {
  775. let that = this;
  776. let param = {
  777. "columnId": 1744,
  778. "token": localStorage.getItem("token")
  779. }
  780. axios.post(webConfig.DMS_URL + '/content/getVectorData', qs.stringify(param),
  781. {
  782. headers: {
  783. 'Content-Type': 'application/x-www-form-urlencoded',
  784. 'token': localStorage.getItem("token")
  785. }
  786. })
  787. .then(function (response) {
  788. if(response.data.message == '无效token'){
  789. that.$message.success('token过期,请重新登录');
  790. that.$router.push({ path: '/' });
  791. }else{
  792. that.createVectorLayer(response.data);
  793. }
  794. })
  795. .catch(function (error) {
  796. console.log(error);
  797. });
  798. },
  799. createVectorLayer(vectorData) {
  800. let that = this;
  801. // console.log(vectorData);
  802. that.options = [];
  803. for (let o in vectorData.features[0].properties) {
  804. that.options.push({
  805. value: o,
  806. label: o,
  807. })
  808. }
  809. that.dataList = vectorData;
  810. if(window.mapboxMap.getSource('vector-data')){
  811. window.mapboxMap.getSource('vector-data').setData(vectorData);
  812. }else{
  813. window.mapboxMap.addSource('vector-data', {
  814. type: 'geojson',
  815. data: vectorData
  816. });
  817. window.mapboxMap.addLayer({
  818. 'id': 'data-fill-layer',
  819. 'type': 'fill',
  820. 'source': 'vector-data',
  821. 'layout': {},
  822. 'paint': {
  823. 'fill-color': 'rgba(244,104,41,1)', // 面填充颜色
  824. 'fill-opacity': 0.3 // 面填充透明度
  825. }
  826. });
  827. window.mapboxMap.addLayer({
  828. 'id': 'data-line-layer',
  829. 'type': 'line',
  830. 'source': 'vector-data',
  831. 'layout': {},
  832. 'paint': {
  833. 'line-color': 'rgba(244,104,41,1)', // 线颜色
  834. 'line-width': 2 // 线宽度
  835. }
  836. });
  837. window.mapboxMap.addLayer({
  838. 'id': 'data-symbol-layer',
  839. 'type': 'symbol',
  840. 'source': 'vector-data',
  841. "layout": {
  842. "text-field": this.fontText, // 正确使用 text-field 属性
  843. // "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"], // 设置字体
  844. "text-size": 10, // 设置字体大小(可选)
  845. "text-anchor": "top", // 设置文本锚点(可选)
  846. "text-offset": [0, 0.6], // 设置文本偏移量(可选)
  847. "text-allow-overlap": false, // 是否允许文本重叠(可选)
  848. },
  849. "paint": {
  850. "icon-color":"#fff",
  851. "text-color":"#000"
  852. }
  853. });
  854. }
  855. },
  856. handleSelChange(){
  857. // 在每个字段后面添加换行符
  858. const withNewlines = this.selectText.reduce((acc, item, index, array) => {
  859. acc.push(["get", item]);
  860. if (index < array.length - 1) {
  861. acc.push("\n");
  862. }
  863. return acc;
  864. }, []);
  865. this.fontText = ["concat", ...withNewlines];
  866. this.changeTextField(this.fontText);
  867. },
  868. // 动态改变文本字段内容(例如,改为显示名称)
  869. changeTextField(newField) {
  870. window.mapboxMap.setLayoutProperty('data-symbol-layer', 'text-field', newField);
  871. }
  872. }
  873. };
  874. </script>
  875. <style>
  876. /*节点标签样式 */
  877. .custom-popup {
  878. z-index: 9;
  879. }
  880. .more{
  881. float:right;
  882. cursor: pointer;
  883. transition: color 0.2s;
  884. }
  885. .more:hover {
  886. color: #00A8FF;
  887. }
  888. </style>
  889. <style lang="less" scoped>
  890. /deep/ .el-select__wrapper{
  891. min-height: 30px !important;
  892. }
  893. // 隐藏地图控件(mapboxgl-ctrl-bottom-left)
  894. /deep/.mapboxgl-ctrl-bottom-left div{
  895. display:none !important;
  896. }
  897. /deep/.mapboxgl-ctrl{
  898. margin: 0 10px 50px 0 !important;
  899. }
  900. /deep/.el-divider--horizontal{
  901. margin: 0 !important;
  902. height: initial !important;
  903. }
  904. /* 新增:辖区名称样式 */
  905. /deep/.area-name {
  906. position: absolute;
  907. background: rgba(0,0,0,0.6);
  908. color: white;
  909. padding: 4px 10px;
  910. border-radius: 4px;
  911. font-size: 14px;
  912. pointer-events: none; /* 不影响鼠标悬浮 */
  913. transform: translate(-50%, -50%);
  914. white-space: nowrap;
  915. }
  916. #mapContainer {
  917. width: 100%;
  918. height: 100%;
  919. }
  920. .tips {
  921. position: absolute;
  922. z-index: 1000;
  923. color: #fff;
  924. bottom: 0;
  925. // left: 45%;
  926. width: 100%;
  927. text-align: center;
  928. padding: 10px 20px;
  929. background: #063f798a;
  930. // border-radius: 40px 40px 0px 0;
  931. -webkit-backdrop-filter: blur(10px);
  932. backdrop-filter: blur(10px);
  933. }
  934. .right-btn{
  935. position: absolute;
  936. z-index: 1000;
  937. bottom: 156px;
  938. right: 10px;
  939. text-align: center;
  940. // padding: 6px;
  941. background: #ffffff;
  942. box-shadow: 0 0 0 2px #0000001a;
  943. border-radius: 4px;
  944. display: grid;
  945. // gap: 8px;
  946. .icon {
  947. cursor: pointer;
  948. padding: 6px;
  949. &:hover{
  950. background: #e6e6e6;
  951. }
  952. }
  953. .icon:first-child {
  954. cursor: pointer;
  955. padding: 6px;
  956. &:hover{
  957. background: #e6e6e6;
  958. border-radius: 4px 4px 0px 0px;
  959. }
  960. }
  961. .icon:last-child {
  962. cursor: pointer;
  963. padding: 6px;
  964. &:hover{
  965. background: #e6e6e6;
  966. border-radius: 0px 0px 4px 4px;
  967. }
  968. }
  969. }
  970. .select-item{
  971. position: absolute;
  972. z-index: 1000;
  973. bottom: 156px;
  974. right: 50px;
  975. background: #01346f99;
  976. border-radius: 6px;
  977. }
  978. /* 十字准线样式 */
  979. .map-center-crosshair {
  980. position: absolute;
  981. top: 50%;
  982. left: 50%;
  983. width: 40px;
  984. height: 40px;
  985. // width: 100%;
  986. //height: 100%;
  987. /* 禁止点击,不影响地图交互 */
  988. pointer-events: none;
  989. /* 居中偏移 */
  990. transform: translate(-50%, -50%);
  991. z-index: 1;
  992. }
  993. /* 横线 + 竖线 */
  994. .map-center-crosshair::before,
  995. .map-center-crosshair::after {
  996. content: '';
  997. position: absolute;
  998. background: rgba(255, 0, 0, 0.7); /* 红色半透明 */
  999. }
  1000. /* 竖线 */
  1001. .map-center-crosshair::before {
  1002. width: 4px;
  1003. height: 100%;
  1004. left: 50%;
  1005. transform: translateX(-50%);
  1006. }
  1007. /* 横线 */
  1008. .map-center-crosshair::after {
  1009. width: 100%;
  1010. height: 4px;
  1011. top: 50%;
  1012. transform: translateY(-50%);
  1013. }
  1014. </style>