@@ -57,9 +57,12 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
5757 updateWhenZooming : false ,
5858 keepBuffer : 25 ,
5959 resolution : 2 ** 5 ,
60- debugLevel : 0
60+ debugLevel : 0 ,
61+ caching : true
6162 } ,
6263
64+ cache : { } ,
65+
6366 initialize : function ( options : GeoRasterLayerOptions ) {
6467 try {
6568 if ( options . georasters ) {
@@ -321,7 +324,23 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
321324 // note that we aren't setting the tile height or width here
322325 // drawTile dynamically sets the width and padding based on
323326 // how much the georaster takes up the tile area
324- this . drawTile ( { tile, coords, context, done } ) ;
327+ const coordsKey = this . _tileCoordsToKey ( coords ) ;
328+ const key = `${ coordsKey } :${ this . options . resolution } ` ;
329+ const doneCb = ( error ?: Error , tile ?: HTMLElement ) : void => {
330+ done ( error , tile ) ;
331+
332+ // caching the rendered tile, to skip the calculation for the next time
333+ if ( ! error && this . options . caching ) {
334+ this . cache [ key ] = tile ;
335+ }
336+ } ;
337+
338+ if ( this . options . caching && this . cache [ key ] ) {
339+ done ( undefined , this . cache [ key ] ) ;
340+ return this . cache [ key ] ;
341+ } else {
342+ this . drawTile ( { tile, coords, context, done : doneCb } ) ;
343+ }
325344
326345 return tile ;
327346 } ,
@@ -1060,6 +1079,10 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
10601079
10611080 same ( array : GeoRaster [ ] , key : GeoRasterKeys ) {
10621081 return new Set ( array . map ( item => item [ key ] ) ) . size === 1 ;
1082+ } ,
1083+
1084+ clearCache ( ) {
1085+ this . cache = { } ;
10631086 }
10641087} ) ;
10651088
0 commit comments