@@ -5,7 +5,7 @@ import Ajax from '../util/Ajax';
55import { isNil , hasOwn , isString } from '../../common/Util' ;
66import { PROP_OMBB } from '../../common/Constant' ;
77import { projectOMBB } from '../builder/Ombb.js' ;
8- import { calArrayBufferSize , isNumber } from '../util/index' ;
8+ import { calArrayBufferSize , isNumber , arraybufferIsGZip , decompressGzipWithBlob } from '../util/index' ;
99
1010const ALTITUDE_ERRORS = {
1111 'MISSING_ALTITUDE_ELEMENT' : 2 ,
@@ -50,33 +50,59 @@ export default class VectorTileLayerWorker extends LayerWorker {
5050 }
5151 fetchOptions . referrer = context . referrer ;
5252 fetchOptions . errorLog = context . loadTileErrorLog ;
53- const { loadTileCachMaxSize, loadTileCacheLog, } = context ;
53+ const { loadTileCachMaxSize, loadTileCacheLog } = context ;
54+
5455 return Ajax . getArrayBuffer ( url , fetchOptions , ( err , response ) => {
5556 if ( ! this . _cache ) {
5657 // removed
5758 return ;
5859 }
60+ let arrayBuffer , hasData = false ;
61+
62+ const readTile = ( ) => {
63+ this . _readTile ( url , altitudePropertyName , disableAltitudeWarning , err , arrayBuffer , cb ) ;
64+ } ;
65+
5966 if ( err ) {
6067 if ( ! err . loading ) {
6168 this . _cache . add ( url , { err, data : response && response . data , cacheIndex : context . workerCacheIndex } ) ;
6269 }
6370 } else if ( response && response . data ) {
64- let needCache = true ;
65- if ( isNumber ( loadTileCachMaxSize ) && loadTileCachMaxSize > 0 ) {
66- const bufferSize = calArrayBufferSize ( response . data ) ;
67- if ( bufferSize > loadTileCachMaxSize ) {
68- needCache = false ;
69- if ( loadTileCacheLog ) {
70- console . warn ( `url:${ url } ,loadTileCachMaxSize exceeded: ${ bufferSize } > ${ loadTileCachMaxSize } ,the tile will not be cached.` ) ;
71+ hasData = true ;
72+ arrayBuffer = response . data ;
73+ const isGZip = arraybufferIsGZip ( arrayBuffer ) ;
74+
75+ const resolveTile = ( ) => {
76+ let needCache = true ;
77+ if ( arrayBuffer && isNumber ( loadTileCachMaxSize ) && loadTileCachMaxSize > 0 ) {
78+ const bufferSize = calArrayBufferSize ( arrayBuffer ) ;
79+ if ( bufferSize > loadTileCachMaxSize ) {
80+ needCache = false ;
81+ if ( loadTileCacheLog ) {
82+ console . warn ( `url:${ url } ,loadTileCachMaxSize exceeded: ${ bufferSize } > ${ loadTileCachMaxSize } ,the tile will not be cached.` ) ;
83+ }
7184 }
7285 }
73- }
74- if ( needCache ) {
75- this . _cache . add ( url , { err : null , data : response . data , cacheIndex : context . workerCacheIndex } ) ;
86+ if ( needCache && arrayBuffer ) {
87+ this . _cache . add ( url , { err : null , data : arrayBuffer , cacheIndex : context . workerCacheIndex } ) ;
88+ }
89+ readTile ( ) ;
90+ } ;
91+
92+ if ( isGZip ) {
93+ decompressGzipWithBlob ( arrayBuffer , ( buffer => {
94+ if ( buffer ) {
95+ arrayBuffer = buffer ;
96+ }
97+ resolveTile ( ) ;
98+ } ) )
99+ } else {
100+ resolveTile ( ) ;
76101 }
77102 }
78-
79- this . _readTile ( url , altitudePropertyName , disableAltitudeWarning , err , response && response . data , cb ) ;
103+ if ( ! hasData ) {
104+ readTile ( ) ;
105+ }
80106 } ) ;
81107 }
82108
0 commit comments