import { nextTick } from 'vue'; import { getJsonData, getArcgisServerData, getArcgisServerSixteenData, openApi_user_get } from '../../api/api.js'; import store from './../../store/store.js'; import mapLayer from './mapLayer.js'; import mapMenu from './mapMenu.js'; import mapView from './mapView.js'; import qyeryData from './queryData.js'; import { showToast } from 'vant'; import mapBaseLayer from './mapBaseLayer.js'; const mapData = { // 详细数据列表 searchData: null, // 地图列表数据 baseLayer: null, // 图层管理列表 manageLayer: null, num: 0, listData: [], listFileds: [], dlList: { td: 0, wxzc: 0, fc: 0 }, init() { var that = this; this.getBaseLayerData(); nextTick(() => { this.setMqpJump(config.location); this.setLayerStart(); }); }, setLayerStart() { openApi_user_get().then(res => { if (res.code == 0) { nextTick(() => { this.setDataStart(); }); } else { store.state.setLoadFlag = false; const obj = config.token + ' ' + res.message; showToast({ message: obj, wordBreak: 'break-all' }); // return; nextTick(() => { this.setDataStart(); }); } }); }, setMqpJump(item) { earthCtrl.camera.jumpTo({ //跳转视角 destination: new SmartEarth.Cesium.Cartesian3.fromDegrees(item.x, item.y, item.z ? item.z : config.posHeight) }); }, setSearchFliter(res) { var obj = this.searchData.filter(item => { var name = ''; if (item.attributes.MC) { name = item.attributes.MC; } else if (item.attributes.SWLYMC) { name = item.attributes.SWLYMC; } else if (item.attributes.XMMC) { name = item.attributes.XMMC; } if (name.indexOf(res) > -1) { return item; } }); return obj; }, getManageData() { var that = this; // if (that.manageLayer) { // that.getSixteenDataList(); // } else { getJsonData('entity.json').then(res => { var val_data = res[0].type; const obj = val_data.filter(item => { item.icon = config.imgUrl + item.icon; return item; }); that.manageLayer = obj; that.getSixteenDataList(); }); // } }, getBaseLayerData() { var that = this; getJsonData('baseLayer.json').then(data => { const obj = data.filter(item => { item.img = config.imgUrl + item.img; return item; }); that.baseLayer = obj; mapBaseLayer.init(obj); store.state.setBaseLayerFlag = that.baseLayer[0].name; }); }, setAddSearchData() { var obj = this.manageLayer; for (var i in obj) { if (obj[i].checked && !obj[i].disable) { mapLayer.setLayerChange(obj[i]); } } store.state.setLoadFlag = false; }, getSixteenDataList() { var that = this; const paramData = JSON.stringify(qyeryData.sixTeenData); getArcgisServerSixteenData(paramData).then(res => { const layers = res.layers; for (var i in layers) { const fileds = that.listFileds.concat(layers[i].fields); const feature = layers[i].features; for (var j in feature) { const dlType = feature[j].attributes; if (dlType.DL == '房产') { this.dlList.fc++; } else if (dlType.DL == '无形类资产') { this.dlList.wxzc++; } else if (dlType.DL == '土地') { this.dlList.td++; } that.manageLayer.filter(item => { if (item.name == dlType.XL) { item.count++; } }); const id = that.generateID(); feature[j].attributes['FID'] = id; that.listData.push(feature[j]); } that.listFileds = fileds; } that.searchData = that.listData; store.state.setSearchData = true; this.setAddSearchData(); }); // } }, getDataList() { // 接口循环次数 var count = config.apiLength; var that = this; // 循环遍历接口 if (that.searchData) { setTimeout(() => { store.state.setRefreshFlag = true; this.setAddSearchData(); }, 100); } else { var val_obj = this.manageLayer[this.num]; getArcgisServerData({ num: val_obj.mapServer, type: val_obj.name }).then(res => { if (res && res.features) { const fileds = that.listFileds.concat(res.fieldAliases); for (var i in res.features) { const id = that.generateID(); const attribute = res.features[i].attributes; const fid = attribute.DL + '_' + attribute.XL + '_' + attribute.objectid; res.features[i].attributes['FID'] = id; that.listData.push(res.features[i]); } that.listFileds = fileds; } this.num++; if (this.num < count) { this.getDataList(); } else { that.searchData = that.listData; store.state.setSearchData = true; mapMenu.setMenuChange(); store.state.setRefreshFlag = true; this.setAddSearchData(); } }); } }, setJudgmentData(res) { if (res && res.coordinates) { if (parseFloat(res.coordinates[0]).toFixed(3) != 117.205 && parseFloat(res.coordinates[1]).toFixed(3) != 39.132) { return true; } else { return false; } } else { return false; } }, generateID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); }, setDataStart() { store.state.setRefreshData = true; store.state.setRefreshFlag = false; nextTick(() => { store.state.setRefreshFlag = true; }); this.dlList = { td: 0, wxzc: 0, fc: 0 }; this.searchData = null; this.listData = []; this.listFileds = []; this.manageLayer = null; this.setRefreshData(); }, setRefreshData() { mapLayer.setLayerRemoveAll(); mapLayer.setRemovelocationEntity(); this.getManageData(); }, setBaseLayerChange(res) { if (!this.manageLayer) return; mapLayer.setLayerChange(res); for (var i in this.manageLayer) { if (this.manageLayer[i].id == res.id) { this.manageLayer[i].checked = res.checked; } } } }; export default mapData;