@@ -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 SampleData from './webmap/config/SampleData.json' ; // eslint-disable-line import/extensions
2526
2627import GeoJSON from 'ol/format/GeoJSON' ;
2728import 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
0 commit comments