Skip to content

Commit e371635

Browse files
author
ChenGuanglin
committed
【bug】示例数据按行政区划制作迁徙图,view方式浏览,提示添加失败
review by zhaoq
1 parent 91064fa commit e371635

File tree

2 files changed

+103
-7
lines changed

2 files changed

+103
-7
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { DataFlowService } from '../services'
2222

2323
import provincialCenterData from './webmap/config/ProvinceCenter.json';// eslint-disable-line import/extensions
2424
import municipalCenterData from './webmap/config/MunicipalCenter.json';// eslint-disable-line import/extensions
25+
import SampleData from './webmap/config/SampleData.json';// eslint-disable-line import/extensions
2526

2627
import GeoJSON from 'ol/format/GeoJSON';
2728
import MVT from 'ol/format/MVT';
@@ -1413,7 +1414,7 @@ export class WebMap extends Observable {
14131414
withCredentials: this.withCredentials
14141415
}).then(function (response) {
14151416
return response.json()
1416-
}).then(function (data) {
1417+
}).then(async function (data) {
14171418
if (data.succeed === false) {
14181419
//请求失败
14191420
that.layerAdded++;
@@ -1434,7 +1435,7 @@ export class WebMap extends Observable {
14341435
let geojson = that.excelData2FeatureByDivision(data.content, divisionType, divisionField);
14351436
features = that._parseGeoJsonData2Feature({allDatas:{features:geojson.features},fileCode:layer.projection});
14361437
} else {
1437-
features = that.excelData2Feature(data.content, layer);
1438+
features = await that.excelData2Feature(data.content, layer);
14381439
}
14391440
}
14401441
that.addLayer(layer, features, layerIndex);
@@ -1797,7 +1798,7 @@ export class WebMap extends Observable {
17971798
* @param {object} layerInfo - 图层信息
17981799
* @returns {Array} ol.feature的数组集合
17991800
*/
1800-
excelData2Feature(content, layerInfo) {
1801+
async excelData2Feature(content, layerInfo) {
18011802
let rows = content.rows,
18021803
colTitles = content.colTitles;
18031804
// 解决V2恢复的数据中含有空格
@@ -1807,10 +1808,50 @@ export class WebMap extends Observable {
18071808
}
18081809
}
18091810
let fileCode = layerInfo.projection,
1810-
xIdx = colTitles.indexOf(Util.trim((layerInfo.xyField && layerInfo.xyField.xField) || (layerInfo.from && layerInfo.from.xField))),
1811-
yIdx = colTitles.indexOf(Util.trim((layerInfo.xyField && layerInfo.xyField.yField) || (layerInfo.from && layerInfo.from.yField))),
1811+
dataSource = layerInfo.dataSource,
18121812
baseLayerEpsgCode = this.baseProjection,
1813-
features = [];
1813+
features = [],
1814+
xField = Util.trim((layerInfo.xyField && layerInfo.xyField.xField) || (layerInfo.from && layerInfo.from.xField)),
1815+
yField = Util.trim((layerInfo.xyField && layerInfo.xyField.yField) || (layerInfo.from && layerInfo.from.yField)),
1816+
xIdx = colTitles.indexOf(xField),
1817+
yIdx = colTitles.indexOf(yField);
1818+
1819+
// todo 优化 暂时这样处理
1820+
if (layerInfo.layerType === 'MIGRATION') {
1821+
try {
1822+
if (dataSource.type === 'PORTAL_DATA') {
1823+
const { dataMetaInfo } = await FetchRequest.get(`${Util.getIPortalUrl()}web/datas/${dataSource.serverId}.json`, null, {
1824+
withCredentials: true
1825+
})
1826+
// eslint-disable-next-line require-atomic-updates
1827+
layerInfo.xyField = {
1828+
xField: dataMetaInfo.xField,
1829+
yField: dataMetaInfo.yField
1830+
}
1831+
if(!dataMetaInfo.xIndex) {
1832+
xIdx = colTitles.indexOf(dataMetaInfo.xField);
1833+
yIdx = colTitles.indexOf(dataMetaInfo.yField);
1834+
} else {
1835+
xIdx = dataMetaInfo.xIndex;
1836+
yIdx = dataMetaInfo.yIndex;
1837+
}
1838+
} else if (dataSource.type === 'SAMPLE_DATA') {
1839+
// 示例数据从本地拿xyField
1840+
const sampleData = SampleData.find(item => item.id === dataSource.name) || {};
1841+
xField = sampleData.xField;
1842+
yField = sampleData.yField
1843+
layerInfo.xyField = {
1844+
xField,
1845+
yField
1846+
}
1847+
xIdx = colTitles.findIndex(item => item === xField);
1848+
yIdx = colTitles.findIndex(item => item === yField);
1849+
}
1850+
} catch (error) {
1851+
console.error(error);
1852+
}
1853+
}
1854+
18141855
for (let i = 0, len = rows.length; i < len; i++) {
18151856
let rowDatas = rows[i],
18161857
attributes = {},
@@ -1832,7 +1873,7 @@ export class WebMap extends Observable {
18321873
features.push(feature);
18331874
}
18341875
}
1835-
return features;
1876+
return Promise.resolve(features);
18361877
}
18371878
/**
18381879
* @private
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
[
3+
{
4+
"id": "SalesJan2009",
5+
"fileName": "SalesJan2009",
6+
"xField": "Longitude",
7+
"yField": "Latitude",
8+
"type": "POINT"
9+
},
10+
{
11+
"id": "Sacramentorealestatetransactions",
12+
"fileName": "Ealestate transactions",
13+
"xField": "longitude",
14+
"yField": "latitude",
15+
"type": "POINT"
16+
},
17+
{
18+
"id": "BeijingResidentialDistrict",
19+
"fileName": "北京市住宅小区",
20+
"xField": "SmX",
21+
"yField": "SmY",
22+
"type": "POINT"
23+
},
24+
{
25+
"id": "GlobalRecordOfOver7Earthquakes",
26+
"fileName": "全球历史7级以上地震记录",
27+
"xField": "经度",
28+
"yField": "纬度",
29+
"type": "POINT"
30+
},
31+
{
32+
"id": "ChinaRecordOfOver6Earthquakes",
33+
"fileName": "中国历史6级以上地震记录",
34+
"xField": "经度",
35+
"yField": "纬度",
36+
"type": "POINT"
37+
},
38+
{
39+
"id": "ChinaMeteorologicalObservationStation",
40+
"fileName": "中国气象观测站",
41+
"xField": "经度",
42+
"yField": "纬度",
43+
"type": "POINT"
44+
},
45+
{
46+
"id": "BeijingSubwayLine",
47+
"fileName": "北京市地铁交通线路",
48+
"type": "LINE"
49+
},
50+
{
51+
"id": "ChinaEarthquakeIntensityZone",
52+
"fileName": "中国地震烈度区划面",
53+
"type": "POLYGON"
54+
}
55+
]

0 commit comments

Comments
 (0)