Skip to content

Commit f1b3e83

Browse files
committed
2 parents 6388720 + 5b3506b commit f1b3e83

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 SampleDataInfo from './webmap/config/SampleDataInfo.json';// eslint-disable-line import/extensions
2526

2627
import GeoJSON from 'ol/format/GeoJSON';
2728
import MVT from 'ol/format/MVT';
@@ -1415,7 +1416,7 @@ export class WebMap extends Observable {
14151416
withCredentials: this.withCredentials
14161417
}).then(function (response) {
14171418
return response.json()
1418-
}).then(function (data) {
1419+
}).then(async function (data) {
14191420
if (data.succeed === false) {
14201421
//请求失败
14211422
that.layerAdded++;
@@ -1436,7 +1437,7 @@ export class WebMap extends Observable {
14361437
let geojson = that.excelData2FeatureByDivision(data.content, divisionType, divisionField);
14371438
features = that._parseGeoJsonData2Feature({allDatas:{features:geojson.features},fileCode:layer.projection});
14381439
} else {
1439-
features = that.excelData2Feature(data.content, layer);
1440+
features = await that.excelData2Feature(data.content, layer);
14401441
}
14411442
}
14421443
that.addLayer(layer, features, layerIndex);
@@ -1799,7 +1800,7 @@ export class WebMap extends Observable {
17991800
* @param {object} layerInfo - 图层信息
18001801
* @returns {Array} ol.feature的数组集合
18011802
*/
1802-
excelData2Feature(content, layerInfo) {
1803+
async excelData2Feature(content, layerInfo) {
18031804
let rows = content.rows,
18041805
colTitles = content.colTitles;
18051806
// 解决V2恢复的数据中含有空格
@@ -1809,10 +1810,50 @@ export class WebMap extends Observable {
18091810
}
18101811
}
18111812
let fileCode = layerInfo.projection,
1812-
xIdx = colTitles.indexOf(Util.trim((layerInfo.xyField && layerInfo.xyField.xField) || (layerInfo.from && layerInfo.from.xField))),
1813-
yIdx = colTitles.indexOf(Util.trim((layerInfo.xyField && layerInfo.xyField.yField) || (layerInfo.from && layerInfo.from.yField))),
1813+
dataSource = layerInfo.dataSource,
18141814
baseLayerEpsgCode = this.baseProjection,
1815-
features = [];
1815+
features = [],
1816+
xField = Util.trim((layerInfo.xyField && layerInfo.xyField.xField) || (layerInfo.from && layerInfo.from.xField)),
1817+
yField = Util.trim((layerInfo.xyField && layerInfo.xyField.yField) || (layerInfo.from && layerInfo.from.yField)),
1818+
xIdx = colTitles.indexOf(xField),
1819+
yIdx = colTitles.indexOf(yField);
1820+
1821+
// todo 优化 暂时这样处理
1822+
if (layerInfo.layerType === 'MIGRATION') {
1823+
try {
1824+
if (dataSource.type === 'PORTAL_DATA') {
1825+
const { dataMetaInfo } = await FetchRequest.get(`${Util.getIPortalUrl()}web/datas/${dataSource.serverId}.json`, null, {
1826+
withCredentials: true
1827+
})
1828+
// eslint-disable-next-line require-atomic-updates
1829+
layerInfo.xyField = {
1830+
xField: dataMetaInfo.xField,
1831+
yField: dataMetaInfo.yField
1832+
}
1833+
if(!dataMetaInfo.xIndex) {
1834+
xIdx = colTitles.indexOf(dataMetaInfo.xField);
1835+
yIdx = colTitles.indexOf(dataMetaInfo.yField);
1836+
} else {
1837+
xIdx = dataMetaInfo.xIndex;
1838+
yIdx = dataMetaInfo.yIndex;
1839+
}
1840+
} else if (dataSource.type === 'SAMPLE_DATA') {
1841+
// 示例数据从本地拿xyField
1842+
const sampleData = SampleDataInfo.find(item => item.id === dataSource.name) || {};
1843+
xField = sampleData.xField;
1844+
yField = sampleData.yField
1845+
layerInfo.xyField = {
1846+
xField,
1847+
yField
1848+
}
1849+
xIdx = colTitles.findIndex(item => item === xField);
1850+
yIdx = colTitles.findIndex(item => item === yField);
1851+
}
1852+
} catch (error) {
1853+
console.error(error);
1854+
}
1855+
}
1856+
18161857
for (let i = 0, len = rows.length; i < len; i++) {
18171858
let rowDatas = rows[i],
18181859
attributes = {},
@@ -1834,7 +1875,7 @@ export class WebMap extends Observable {
18341875
features.push(feature);
18351876
}
18361877
}
1837-
return features;
1878+
return Promise.resolve(features);
18381879
}
18391880
/**
18401881
* @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)