@@ -22,6 +22,7 @@ import { DataFlowService } from '../services'
2222
2323import provincialCenterData from './webmap/config/ProvinceCenter.json' ; // eslint-disable-line import/extensions
2424import 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
2627import GeoJSON from 'ol/format/GeoJSON' ;
2728import 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
0 commit comments