@@ -817,6 +817,9 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
817817
818818 // setup zoom level rules if configured
819819 if (ruleset ) {
820+ mapcache_buffer * last_hidden_tile = NULL ;
821+ unsigned int last_hidden_color ;
822+
820823 // prepare one rule per zoom level. if rule is missing it will be NULL
821824 for (i = 0 ; i < grid -> nlevels ; i ++ ) {
822825 mapcache_rule * rule = mapcache_ruleset_rule_find (ruleset -> rules , i );
@@ -827,17 +830,24 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
827830 if (rule -> visible_extents ) {
828831 int j ;
829832
830- // create empty tile in configured format to return when outside visible extent
831- if (tileset -> format ) {
832- rule_clone -> hidden_tile = tileset -> format -> create_empty_image (ctx , tileset -> format , grid -> tile_sx , grid -> tile_sy , rule -> hidden_color );
833- } else {
834- rule_clone -> hidden_tile = config -> default_image_format -> create_empty_image (ctx , config -> default_image_format , grid -> tile_sx , grid -> tile_sy , rule -> hidden_color );
835- }
833+ // create blank tile in configured format to return when outside visible extent
834+ // try to reuse last tile if possible
835+ if (last_hidden_tile == NULL || last_hidden_color != rule -> hidden_color ) {
836+ if (tileset -> format ) {
837+ last_hidden_tile = tileset -> format -> create_empty_image (ctx , tileset -> format , grid -> tile_sx , grid -> tile_sy , rule -> hidden_color );
838+ } else {
839+ last_hidden_tile = config -> default_image_format -> create_empty_image (ctx , config -> default_image_format , grid -> tile_sx , grid -> tile_sy , rule -> hidden_color );
840+ }
836841
837- if (GC_HAS_ERROR (ctx )) {
838- return ;
842+ if (GC_HAS_ERROR (ctx )) {
843+ return ;
844+ }
845+
846+ last_hidden_color = rule -> hidden_color ;
839847 }
840848
849+ rule_clone -> hidden_tile = last_hidden_tile ;
850+
841851 // compute limits for extents
842852 for (j = 0 ; j < rule -> visible_extents -> nelts ; j ++ ) {
843853 mapcache_extent * visible_extent = APR_ARRAY_IDX (rule -> visible_extents , j , mapcache_extent * );
0 commit comments