@@ -114,9 +114,10 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
114114 this . _handleLayerInfo ( mapInfo , _taskID ) ;
115115 } else {
116116 setTimeout ( ( ) => {
117- this . _createMap ( mapInfo ) ;
118- this . map . on ( 'load' , ( ) => {
119- this . _handleLayerInfo ( mapInfo , _taskID ) ;
117+ this . _createMap ( mapInfo ) . then ( ( ) => {
118+ this . map . on ( 'load' , ( ) => {
119+ this . _handleLayerInfo ( mapInfo , _taskID ) ;
120+ } ) ;
120121 } ) ;
121122 } , 0 ) ;
122123 }
@@ -236,7 +237,78 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
236237 return true ;
237238 }
238239
239- _createMap ( mapInfo ) {
240+ async _getScales ( mapInfo ) {
241+ const baseLayerInfo = mapInfo . baseLayer ;
242+ const scales = [ ] ;
243+ let coordUnit = baseLayerInfo . coordUnit || baseLayerInfo . units || mapRepo . CRS . get ( this . baseProjection ) . unit ;
244+ if ( ! coordUnit ) {
245+ coordUnit = this . baseProjection == 'EPSG:3857' ? 'm' : 'degree' ;
246+ }
247+ let visibleScales = null ;
248+ if ( baseLayerInfo . layerType === 'TILE' ) {
249+ try {
250+ const reqOptions = {
251+ withoutFormatSuffix : true ,
252+ withCredentials : this . webMapService . handleWithCredentials ( '' , baseLayerInfo . url , false )
253+ } ;
254+ const res = await this . getBounds ( `${ baseLayerInfo . url } .json` , reqOptions )
255+ if ( res && res . visibleScales ) {
256+ visibleScales = res . visibleScales ;
257+ }
258+ } catch ( error ) {
259+ console . error ( error ) ;
260+ }
261+ }
262+ if ( visibleScales && visibleScales . length > 0 ) {
263+ //底部设置过固定比例尺,则使用设置的
264+ visibleScales . forEach ( ( scale ) => {
265+ const value = 1 / scale ;
266+ scales . push ( `1:${ value } ` ) ;
267+ } ) ;
268+ } else if ( baseLayerInfo . layerType === 'WMTS' ) {
269+ try {
270+ const result = await this . webMapService . getWmtsInfo ( baseLayerInfo , this . baseProjection ) ;
271+ result . scales . forEach ( ( scale ) => {
272+ scales . push ( `1:${ scale } ` ) ;
273+ } ) ;
274+ } catch ( error ) {
275+ console . error ( error ) ;
276+ }
277+ } else if ( baseLayerInfo . layerType === 'ZXY_TILE' ) {
278+ const { resolutions : visibleResolution } = baseLayerInfo ;
279+ visibleResolution . forEach ( ( result ) => {
280+ const currentScale = '1:' + Util . getScaleFromResolution ( result , coordUnit ) ;
281+ scales . push ( currentScale ) ;
282+ } ) ;
283+ } else {
284+ const extent = baseLayerInfo . layerType === 'MAPBOXSTYLE' ? mapRepo . CRS . get ( this . baseProjection ) . extent : mapInfo . extent ;
285+ const resolutions = this . _getResolutionsByExtent ( {
286+ extent : this . _transExtentToBounds ( extent ) ,
287+ tileSize : 512
288+ } ) ;
289+ for ( const res of resolutions ) {
290+ const scale = '1:' + Util . getScaleFromResolution ( res , coordUnit ) ;
291+ if ( scales . indexOf ( scale ) === - 1 ) {
292+ scales . push ( scale ) ;
293+ }
294+ }
295+ }
296+ return scales ;
297+ }
298+
299+ _transExtentToBounds ( extent ) {
300+ if ( extent instanceof Array ) {
301+ return extent ;
302+ }
303+ return [
304+ extent . leftBottom . x ,
305+ extent . leftBottom . y ,
306+ extent . rightTop . x ,
307+ extent . rightTop . y
308+ ] ;
309+ }
310+
311+ async _createMap ( mapInfo ) {
240312 // 获取字体样式
241313 const fontFamilys = this . _getLabelFontFamily ( mapInfo ) ;
242314 const center = this . _getMapCenter ( mapInfo ) ;
@@ -247,10 +319,6 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
247319 const interactive = this . mapOptions . interactive ;
248320 const tileSize = mapInfo . baseLayer . tileSize ;
249321
250- if ( mapInfo . baseLayer . layerType === 'ZXY_TILE' ) {
251- const { leftBottom, rightTop} = mapInfo . extent ;
252- mapInfo . visibleExtent = [ leftBottom . x , leftBottom . y , rightTop . x , rightTop . y ] ;
253- }
254322 if ( isNaN ( minZoom ) ) {
255323 minZoom = mapInfo . minScale
256324 ? this . _transformScaleToZoom ( mapInfo . minScale , mapRepo . CRS . get ( this . baseProjection ) , tileSize )
@@ -272,8 +340,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
272340 }
273341 if ( ! bounds ) {
274342 if ( mapInfo . minScale && mapInfo . maxScale ) {
343+ const scales = await this . _getScales ( mapInfo ) ;
275344 zoomBase = Math . min (
276- this . _transformScaleToZoom ( mapInfo . minScale , mapRepo . CRS . get ( this . baseProjection ) , tileSize ) ,
345+ this . _transformScaleToZoom ( scales [ 0 ] || mapInfo . minScale , mapRepo . CRS . get ( this . baseProjection ) , tileSize ) ,
277346 this . _transformScaleToZoom ( mapInfo . maxScale , mapRepo . CRS . get ( this . baseProjection ) , tileSize )
278347 ) ;
279348 } else {
@@ -294,7 +363,6 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
294363 maxZoom,
295364 bearing : this . bearing || 0 ,
296365 pitch : this . pitch || 0 ,
297- bounds,
298366 interactive : interactive === void 0 ? true : interactive ,
299367 style : {
300368 version : 8 ,
@@ -3127,7 +3195,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
31273195 }
31283196
31293197 _getVisibility ( visible ) {
3130- const visibility = visible === true || visible === 'visible ' ? 'visible ' : 'none ' ;
3198+ const visibility = visible === false || visible === 'none ' ? 'none ' : 'visible ' ;
31313199 return visibility ;
31323200 }
31333201
0 commit comments