@@ -22,6 +22,7 @@ import { DataFlowService } from '../services'
22
22
23
23
import provincialCenterData from './webmap/config/ProvinceCenter.json' ; // eslint-disable-line import/extensions
24
24
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
25
26
26
27
import GeoJSON from 'ol/format/GeoJSON' ;
27
28
import MVT from 'ol/format/MVT' ;
@@ -1413,7 +1414,7 @@ export class WebMap extends Observable {
1413
1414
withCredentials : this . withCredentials
1414
1415
} ) . then ( function ( response ) {
1415
1416
return response . json ( )
1416
- } ) . then ( function ( data ) {
1417
+ } ) . then ( async function ( data ) {
1417
1418
if ( data . succeed === false ) {
1418
1419
//请求失败
1419
1420
that . layerAdded ++ ;
@@ -1434,7 +1435,7 @@ export class WebMap extends Observable {
1434
1435
let geojson = that . excelData2FeatureByDivision ( data . content , divisionType , divisionField ) ;
1435
1436
features = that . _parseGeoJsonData2Feature ( { allDatas :{ features :geojson . features } , fileCode :layer . projection } ) ;
1436
1437
} else {
1437
- features = that . excelData2Feature ( data . content , layer ) ;
1438
+ features = await that . excelData2Feature ( data . content , layer ) ;
1438
1439
}
1439
1440
}
1440
1441
that . addLayer ( layer , features , layerIndex ) ;
@@ -1797,7 +1798,7 @@ export class WebMap extends Observable {
1797
1798
* @param {object } layerInfo - 图层信息
1798
1799
* @returns {Array } ol.feature的数组集合
1799
1800
*/
1800
- excelData2Feature ( content , layerInfo ) {
1801
+ async excelData2Feature ( content , layerInfo ) {
1801
1802
let rows = content . rows ,
1802
1803
colTitles = content . colTitles ;
1803
1804
// 解决V2恢复的数据中含有空格
@@ -1807,10 +1808,50 @@ export class WebMap extends Observable {
1807
1808
}
1808
1809
}
1809
1810
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 ,
1812
1812
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
+
1814
1855
for ( let i = 0 , len = rows . length ; i < len ; i ++ ) {
1815
1856
let rowDatas = rows [ i ] ,
1816
1857
attributes = { } ,
@@ -1832,7 +1873,7 @@ export class WebMap extends Observable {
1832
1873
features . push ( feature ) ;
1833
1874
}
1834
1875
}
1835
- return features ;
1876
+ return Promise . resolve ( features ) ;
1836
1877
}
1837
1878
/**
1838
1879
* @private
0 commit comments