@@ -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 } ,
@@ -413,11 +432,11 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
413432 // pad xmax and ymin of container to tolerate ceil() and floor() in snap()
414433 container : inSimpleCRS
415434 ? [
416- extentOfLayer . xmin ,
417- extentOfLayer . ymin - 0.25 * pixelHeight ,
418- extentOfLayer . xmax + 0.25 * pixelWidth ,
419- extentOfLayer . ymax
420- ]
435+ extentOfLayer . xmin ,
436+ extentOfLayer . ymin - 0.25 * pixelHeight ,
437+ extentOfLayer . xmax + 0.25 * pixelWidth ,
438+ extentOfLayer . ymax
439+ ]
421440 : [ xmin , ymin - 0.25 * pixelHeight , xmax + 0.25 * pixelWidth , ymax ] ,
422441 debug : debugLevel >= 2 ,
423442 origin : inSimpleCRS ? [ extentOfLayer . xmin , extentOfLayer . ymax ] : [ xmin , ymax ] ,
@@ -1040,6 +1059,10 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
10401059
10411060 same ( array : GeoRaster [ ] , key : GeoRasterKeys ) {
10421061 return new Set ( array . map ( item => item [ key ] ) ) . size === 1 ;
1062+ } ,
1063+
1064+ clearCache ( ) {
1065+ this . cache = { } ;
10431066 }
10441067} ) ;
10451068
0 commit comments