Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions include/mapcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ typedef struct mapcache_image mapcache_image;
typedef struct mapcache_grid mapcache_grid;
typedef struct mapcache_grid_level mapcache_grid_level;
typedef struct mapcache_grid_link mapcache_grid_link;
typedef struct mapcache_rule mapcache_rule;
typedef struct mapcache_ruleset mapcache_ruleset;
typedef struct mapcache_context mapcache_context;
typedef struct mapcache_dimension mapcache_dimension;
typedef struct mapcache_requested_dimension mapcache_requested_dimension;
Expand Down Expand Up @@ -834,6 +836,11 @@ struct mapcache_cfg {
*/
apr_hash_t *grids;

/**
* hashtable containing (pre)defined rulesets
*/
apr_hash_t *rulesets;

/**
* the format to use for some miscelaneaous operations:
* - creating an empty image
Expand Down Expand Up @@ -888,9 +895,11 @@ MS_DLL_EXPORT mapcache_cache* mapcache_configuration_get_cache(mapcache_cfg *con
mapcache_grid *mapcache_configuration_get_grid(mapcache_cfg *config, const char *key);
MS_DLL_EXPORT mapcache_tileset* mapcache_configuration_get_tileset(mapcache_cfg *config, const char *key);
mapcache_image_format *mapcache_configuration_get_image_format(mapcache_cfg *config, const char *key);
mapcache_ruleset *mapcache_configuration_get_ruleset(mapcache_cfg *config, const char *key);
void mapcache_configuration_add_image_format(mapcache_cfg *config, mapcache_image_format *format, const char * key);
void mapcache_configuration_add_source(mapcache_cfg *config, mapcache_source *source, const char * key);
void mapcache_configuration_add_grid(mapcache_cfg *config, mapcache_grid *grid, const char * key);
void mapcache_configuration_add_ruleset(mapcache_cfg *config, mapcache_ruleset *ruleset, const char * key);
void mapcache_configuration_add_tileset(mapcache_cfg *config, mapcache_tileset *tileset, const char * key);
void mapcache_configuration_add_cache(mapcache_cfg *config, mapcache_cache *cache, const char * key);

Expand Down Expand Up @@ -1040,6 +1049,12 @@ struct mapcache_grid_link {
mapcache_extent_i *grid_limits;
int minz,maxz;

/**
* rules (mapcache_rule) for each zoom level
* index in array = zoom level
*/
apr_array_header_t *rules;

/**
* tiles above this zoom level will not be stored to the cache, but will be
* dynamically generated (either by reconstructing from lower level tiles, or
Expand All @@ -1052,6 +1067,46 @@ struct mapcache_grid_link {
apr_array_header_t *intermediate_grids;
};

/**\class mapcache_rule
* \brief a zoom level rule
*/
struct mapcache_rule {
/**
* rule for zoom level
*/
int zoom_level;
/**
* color of tiles when outside visible extent, ARGB
*/
unsigned int hidden_color;
/**
* tile to return when outside visible extent
*/
mapcache_buffer *hidden_tile;
/**
* visible extents, array of mapcache_extent
*/
apr_array_header_t *visible_extents;
/**
* visible limits, array of mapcache_extent_i
*/
apr_array_header_t *visible_limits;
};

/**\class mapcache_ruleset
* \brief a set of rules
*/
struct mapcache_ruleset {
/**
* the name of this ruleset
*/
char *name;
/**
* rules (mapcache_rule)
*/
apr_array_header_t *rules;
};

/**\class mapcache_tileset
* \brief a set of tiles that can be requested by a client, created from a mapcache_source
* stored by a mapcache_cache in a mapcache_format
Expand Down Expand Up @@ -1258,6 +1313,49 @@ MS_DLL_EXPORT mapcache_http_response* mapcache_core_proxy_request(mapcache_conte
MS_DLL_EXPORT mapcache_http_response* mapcache_core_respond_to_error(mapcache_context *ctx);


/* in ruleset.c */

/**
* \brief allocate and initialize a new ruleset
* @param pool
*/
mapcache_ruleset* mapcache_ruleset_create(apr_pool_t *pool);

/**
* \brief allocate and initialize a new rule
* @param pool
*/
mapcache_rule* mapcache_ruleset_rule_create(apr_pool_t *pool);

/**
* \brief clone a rule
* @param pool
* @param rule
*/
mapcache_rule* mapcache_ruleset_rule_clone(apr_pool_t *pool, mapcache_rule *rule);

/**
* \brief get rule for zoom level, or NULL if none exist
* @param ruleset
* @param zoom_level
*/
mapcache_rule* mapcache_ruleset_rule_find(apr_array_header_t *rules, int zoom_level);

/**
* \brief get rule at index, or NULL if none exist
* @param rules
* @param idx
*/
mapcache_rule* mapcache_ruleset_rule_get(apr_array_header_t *rules, int idx);

/**
* \brief check if tile is within visible extent
* @param rule
* @param tile
*/
int mapcache_ruleset_is_visible_tile(mapcache_rule* rule, mapcache_tile *tile);


/* in grid.c */
mapcache_grid* mapcache_grid_create(apr_pool_t *pool);

Expand Down Expand Up @@ -1300,6 +1398,7 @@ int mapcache_grid_get_level(mapcache_context *ctx, mapcache_grid *grid, double *
* \param tolerance the number of tiles around the given extent that can be requested without returning an error.
*/
MS_DLL_EXPORT void mapcache_grid_compute_limits(const mapcache_grid *grid, const mapcache_extent *extent, mapcache_extent_i *limits, int tolerance);
void mapcache_grid_compute_limits_at_level(const mapcache_grid *grid, const mapcache_extent *extent, mapcache_extent_i *limits_ptr, int tolerance, int zoom_level);

/* in util.c */
MS_DLL_EXPORT int mapcache_util_extract_int_list(mapcache_context *ctx, const char* args, const char *sep, int **numbers,
Expand Down
17 changes: 17 additions & 0 deletions lib/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@

int mapcache_cache_tile_get(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile) {
int i,rv;
mapcache_rule *rule = mapcache_ruleset_rule_get(tile->grid_link->rules, tile->z);
#ifdef DEBUG
ctx->log(ctx,MAPCACHE_DEBUG,"calling tile_get on cache (%s): (tileset=%s, grid=%s, z=%d, x=%d, y=%d",cache->name,tile->tileset->name,tile->grid_link->grid->name,tile->z,tile->x, tile->y);
#endif

/* if tile is outside visible limits, return a blank tile */
if (mapcache_ruleset_is_visible_tile(rule, tile) == MAPCACHE_FALSE) {
tile->encoded_data = mapcache_buffer_create(0, ctx->pool);
mapcache_buffer_append(tile->encoded_data, rule->hidden_tile->size, rule->hidden_tile->buf);
return MAPCACHE_SUCCESS;
}

for(i=0;i<=cache->retry_count;i++) {
if(i) {
ctx->log(ctx,MAPCACHE_INFO,"cache (%s) get retry %d of %d. previous try returned error: %s",cache->name,i,cache->retry_count,ctx->get_error_message(ctx));
Expand Down Expand Up @@ -79,9 +88,17 @@ void mapcache_cache_tile_delete(mapcache_context *ctx, mapcache_cache *cache, ma

int mapcache_cache_tile_exists(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile) {
int i,rv;
mapcache_rule *rule = mapcache_ruleset_rule_get(tile->grid_link->rules, tile->z);
#ifdef DEBUG
ctx->log(ctx,MAPCACHE_DEBUG,"calling tile_exists on cache (%s): (tileset=%s, grid=%s, z=%d, x=%d, y=%d",cache->name,tile->tileset->name,tile->grid_link->grid->name,tile->z,tile->x, tile->y);
#endif

/* if tile is outside visible limits return TRUE
a blank tile will be returned on subsequent get call on cache */
if (mapcache_ruleset_is_visible_tile(rule, tile) == MAPCACHE_FALSE) {
return MAPCACHE_TRUE;
}

for(i=0;i<=cache->retry_count;i++) {
if(i) {
ctx->log(ctx,MAPCACHE_INFO,"cache (%s) exists retry %d of %d. previous try returned error: %s",cache->name,i,cache->retry_count,ctx->get_error_message(ctx));
Expand Down
11 changes: 11 additions & 0 deletions lib/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ mapcache_cfg* mapcache_configuration_create(apr_pool_t *pool)
cfg->grids = apr_hash_make(pool);
cfg->image_formats = apr_hash_make(pool);
cfg->metadata = apr_table_make(pool,3);
cfg->rulesets = apr_hash_make(pool);

mapcache_configuration_add_image_format(cfg,
mapcache_imageio_create_png_format(pool,"PNG",MAPCACHE_COMPRESSION_FAST),
Expand Down Expand Up @@ -241,6 +242,11 @@ mapcache_grid *mapcache_configuration_get_grid(mapcache_cfg *config, const char
return (mapcache_grid*)apr_hash_get(config->grids, (void*)key, APR_HASH_KEY_STRING);
}

mapcache_ruleset *mapcache_configuration_get_ruleset(mapcache_cfg *config, const char *key)
{
return (mapcache_ruleset*)apr_hash_get(config->rulesets, (void*)key, APR_HASH_KEY_STRING);
}

mapcache_tileset *mapcache_configuration_get_tileset(mapcache_cfg *config, const char *key)
{
if(config->mode == MAPCACHE_MODE_NORMAL) {
Expand All @@ -265,6 +271,11 @@ void mapcache_configuration_add_grid(mapcache_cfg *config, mapcache_grid *grid,
apr_hash_set(config->grids, key, APR_HASH_KEY_STRING, (void*)grid);
}

void mapcache_configuration_add_ruleset(mapcache_cfg *config, mapcache_ruleset *ruleset, const char * key)
{
apr_hash_set(config->rulesets, key, APR_HASH_KEY_STRING, (void*)ruleset);
}

void mapcache_configuration_add_tileset(mapcache_cfg *config, mapcache_tileset *tileset, const char * key)
{
tileset->config = config;
Expand Down
Loading