@@ -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' ;
@@ -38,6 +39,7 @@ import WMTSTileGrid from 'ol/tilegrid/WMTS';
3839import * as olGeometry from 'ol/geom' ;
3940import * as olSource from 'ol/source' ;
4041import Feature from 'ol/Feature' ;
42+ import olRenderFeature from 'ol/render/Feature' ;
4143import Style from 'ol/style/Style' ;
4244import FillStyle from 'ol/style/Fill' ;
4345import StrokeStyle from 'ol/style/Stroke' ;
@@ -198,6 +200,7 @@ export class WebMap extends Observable {
198200 }
199201 that . baseProjection = mapInfo . projection ;
200202 that . webMapVersion = mapInfo . version ;
203+ that . baseLayer = mapInfo . baseLayer ;
201204 that . mapParams = {
202205 title : mapInfo . title ,
203206 description : mapInfo . description
@@ -1413,7 +1416,7 @@ export class WebMap extends Observable {
14131416 withCredentials : this . withCredentials
14141417 } ) . then ( function ( response ) {
14151418 return response . json ( )
1416- } ) . then ( function ( data ) {
1419+ } ) . then ( async function ( data ) {
14171420 if ( data . succeed === false ) {
14181421 //请求失败
14191422 that . layerAdded ++ ;
@@ -1434,7 +1437,7 @@ export class WebMap extends Observable {
14341437 let geojson = that . excelData2FeatureByDivision ( data . content , divisionType , divisionField ) ;
14351438 features = that . _parseGeoJsonData2Feature ( { allDatas :{ features :geojson . features } , fileCode :layer . projection } ) ;
14361439 } else {
1437- features = that . excelData2Feature ( data . content , layer ) ;
1440+ features = await that . excelData2Feature ( data . content , layer ) ;
14381441 }
14391442 }
14401443 that . addLayer ( layer , features , layerIndex ) ;
@@ -1785,7 +1788,7 @@ export class WebMap extends Observable {
17851788 */
17861789 sendMapToUser ( layersLen ) {
17871790 if ( this . layerAdded === layersLen && this . successCallback ) {
1788- this . successCallback ( this . map , this . mapParams , this . layers ) ;
1791+ this . successCallback ( this . map , this . mapParams , this . layers , this . baseLayer ) ;
17891792 }
17901793 }
17911794
@@ -1797,7 +1800,7 @@ export class WebMap extends Observable {
17971800 * @param {object } layerInfo - 图层信息
17981801 * @returns {Array } ol.feature的数组集合
17991802 */
1800- excelData2Feature ( content , layerInfo ) {
1803+ async excelData2Feature ( content , layerInfo ) {
18011804 let rows = content . rows ,
18021805 colTitles = content . colTitles ;
18031806 // 解决V2恢复的数据中含有空格
@@ -1807,10 +1810,50 @@ export class WebMap extends Observable {
18071810 }
18081811 }
18091812 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 ) ) ) ,
1813+ dataSource = layerInfo . dataSource ,
18121814 baseLayerEpsgCode = this . baseProjection ,
1813- 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 ( `${ this . server } web/datas/${ dataSource . serverId } .json` , null , {
1826+ withCredentials : true
1827+ } ) . then ( res => res . json ( ) ) ;
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+
18141857 for ( let i = 0 , len = rows . length ; i < len ; i ++ ) {
18151858 let rowDatas = rows [ i ] ,
18161859 attributes = { } ,
@@ -1832,7 +1875,7 @@ export class WebMap extends Observable {
18321875 features . push ( feature ) ;
18331876 }
18341877 }
1835- return features ;
1878+ return Promise . resolve ( features ) ;
18361879 }
18371880 /**
18381881 * @private
@@ -4050,22 +4093,18 @@ export class WebMap extends Observable {
40504093 } ) ;
40514094 return new Promise ( ( resolve ) => {
40524095 mapboxStyles . on ( 'styleloaded' , function ( ) {
4053- let styleUrl = layerInfo . url ;
4054- if ( styleUrl . indexOf ( '/restjsr/' ) > - 1 ) {
4055- styleUrl = styleUrl + '/style.json'
4056- }
40574096 let visibleScale = layerInfo . visibleScale ;
40584097 let minResolution = visibleScale && that . resolutions [ visibleScale . maxScale ] ;
40594098 let maxResolution = visibleScale && that . resolutions [ visibleScale . minScale ] ;
40604099 let layer = new olLayer . VectorTile ( {
40614100 //设置避让参数
40624101 declutter : true ,
40634102 source : new olSource . VectorTileSuperMapRest ( {
4064- style : styleUrl ,
4103+ style : styles ,
40654104 withCredentials,
40664105 projection : layerInfo . projection ,
40674106 format : new MVT ( {
4068- featureClass : Feature
4107+ featureClass : olRenderFeature
40694108 } ) ,
40704109 wrapX : false
40714110 } ) ,
0 commit comments