Skip to content
Permalink
Browse files

rework visible extent rule to allow multiple extents per zoom level

  • Loading branch information
tomhel committed May 25, 2016
1 parent 62a2e07 commit 4b93fec8d8c3f188986227c56b5741e12e2aadf6
Showing with 73 additions and 43 deletions.
  1. +4 −4 include/mapcache.h
  2. +40 −26 lib/configuration_xml.c
  3. +29 −13 lib/ruleset.c
@@ -1084,13 +1084,13 @@ struct mapcache_rule {
*/
int readonly;
/**
* visible extent
* visible extents, array of mapcache_extent
*/
mapcache_extent *visible_extent;
apr_array_header_t *visible_extents;
/**
* visible limits
* visible limits, array of mapcache_extent_i
*/
mapcache_extent_i *visible_limits;
apr_array_header_t *visible_limits;
};

/**\class mapcache_ruleset
@@ -181,7 +181,7 @@ void parseRuleset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
for(cur_node = ezxml_child(node,"rule"), i = 0; cur_node; cur_node = cur_node->next, i++) {
int *zoom, nzoom, j;
char* zoom_attr = (char*)ezxml_attr(cur_node, "zoom_level");
ezxml_t visible_extent = ezxml_child(cur_node, "visible_extent");
ezxml_t visibility = ezxml_child(cur_node, "visibility");
ezxml_t readonly = ezxml_child(cur_node, "readonly");
mapcache_rule *rule = mapcache_ruleset_rule_create(ctx->pool);

@@ -203,33 +203,41 @@ void parseRuleset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
return;
}

/* parse visible_extent */
if(visible_extent && visible_extent->txt && *visible_extent->txt) {
double *values;
int nvalues;
char *hidden_color = (char*)ezxml_attr(visible_extent, "hidden_color");
char *value = apr_pstrdup(ctx->pool,visible_extent->txt);
mapcache_extent extent = {0,0,0,0};

if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) ||
nvalues != 4) {
ctx->set_error(ctx, 400, "failed to parse visible_extent array %s in ruleset %s, rule %d. "
"(expecting 4 space separated numbers, got %d (%f %f %f %f)"
"eg <visible_extent>-180 -90 180 90</visible_extent>)",
value,ruleset->name,i+1,nvalues,values[0],values[1],values[2],values[3]);
return;
}
extent.minx = values[0];
extent.miny = values[1];
extent.maxx = values[2];
extent.maxy = values[3];
rule->visible_extent = (mapcache_extent*)apr_pcalloc(ctx->pool, sizeof(mapcache_extent));
*rule->visible_extent = extent;
/* parse visibility, <visibility> */
if(visibility) {
char *hidden_color = (char*)ezxml_attr(visibility, "hidden_color");
ezxml_t extent_node;

if (hidden_color && *hidden_color) {
/* parse color, base 16 */
rule->hidden_color = (unsigned int)strtol(hidden_color, NULL, 16);
}

/* parse extents, <extent> */
for (extent_node = ezxml_child(visibility,"extent"); extent_node; extent_node = extent_node->next) {
double *values;
int nvalues;
char *value = apr_pstrdup(ctx->pool,extent_node->txt);
mapcache_extent extent = {0,0,0,0};
mapcache_extent *pextent;

if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) ||
nvalues != 4) {
ctx->set_error(ctx, 400, "failed to parse extent array %s in ruleset %s, rule %d. "
"(expecting 4 space separated numbers, got %d (%f %f %f %f)"
"eg <extent>-180 -90 180 90</extent>)",
value,ruleset->name,i+1,nvalues,values[0],values[1],values[2],values[3]);
return;
}

extent.minx = values[0];
extent.miny = values[1];
extent.maxx = values[2];
extent.maxy = values[3];
pextent = (mapcache_extent*)apr_pcalloc(ctx->pool, sizeof(mapcache_extent));
*pextent = extent;
APR_ARRAY_PUSH(rule->visible_extents, mapcache_extent*) = pextent;
}
}

/* add this rule for given zoom_levels */
@@ -803,9 +811,15 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)

if(rule) {
mapcache_rule *rule_clone = mapcache_ruleset_rule_clone(ctx->pool, rule);
if(rule->visible_extent) {
rule_clone->visible_limits = apr_pcalloc(ctx->pool, sizeof(mapcache_extent_i));
mapcache_grid_compute_limits_at_level(grid,rule_clone->visible_extent,rule_clone->visible_limits,tolerance,i);

if(rule->visible_extents) {
int j;
for(j = 0; j < rule->visible_extents->nelts; j++) {
mapcache_extent *visible_extent = APR_ARRAY_IDX(rule->visible_extents, j, mapcache_extent*);
mapcache_extent_i *visible_limit = apr_pcalloc(ctx->pool, sizeof(mapcache_extent_i));
mapcache_grid_compute_limits_at_level(grid,visible_extent,visible_limit,tolerance,i);
APR_ARRAY_PUSH(rule_clone->visible_limits, mapcache_extent_i*) = visible_limit;
}
}
APR_ARRAY_PUSH(gridlink->rules, mapcache_rule*) = rule_clone;
} else {
@@ -46,8 +46,8 @@ mapcache_rule* mapcache_ruleset_rule_create(apr_pool_t *pool)
{
mapcache_rule* rule = (mapcache_rule*)apr_pcalloc(pool, sizeof(mapcache_rule));
rule->zoom_level = -1;
rule->visible_extent = NULL;
rule->visible_limits = NULL;
rule->visible_extents = apr_array_make(pool,0,sizeof(mapcache_extent*));
rule->visible_limits = apr_array_make(pool,0,sizeof(mapcache_extent_i*));
rule->hidden_color = 0xffffff; //default = white
rule->readonly = 0;
return rule;
@@ -64,14 +64,24 @@ mapcache_rule* mapcache_ruleset_rule_clone(apr_pool_t *pool, mapcache_rule *rule
clone->hidden_color = rule->hidden_color;
clone->readonly = rule->readonly;

if(rule->visible_extent) {
clone->visible_extent = (mapcache_extent*)apr_pcalloc(pool, sizeof(mapcache_extent));
*clone->visible_extent = *rule->visible_extent;
if(rule->visible_extents) {
int i;
for(i = 0; i < rule->visible_extents->nelts; i++) {
mapcache_extent *extent_clone = (mapcache_extent*)apr_pcalloc(pool, sizeof(mapcache_extent));
mapcache_extent *extent = APR_ARRAY_IDX(rule->visible_extents, i, mapcache_extent*);
*extent_clone = *extent;
APR_ARRAY_PUSH(clone->visible_extents, mapcache_extent*) = extent_clone;
}
}

if(rule->visible_limits) {
clone->visible_limits = (mapcache_extent_i*)apr_pcalloc(pool, sizeof(mapcache_extent_i));
*clone->visible_limits = *rule->visible_limits;
int i;
for(i = 0; i < rule->visible_limits->nelts; i++) {
mapcache_extent_i *extent_clone = (mapcache_extent_i*)apr_pcalloc(pool, sizeof(mapcache_extent_i));
mapcache_extent_i *extent = APR_ARRAY_IDX(rule->visible_limits, i, mapcache_extent_i*);
*extent_clone = *extent;
APR_ARRAY_PUSH(clone->visible_limits, mapcache_extent_i*) = extent_clone;
}
}

return clone;
@@ -113,19 +123,25 @@ mapcache_rule* mapcache_ruleset_rule_get(apr_array_header_t *rules, int idx)
}

/*
* check if tile is within visible extent
* check if tile is within visible extents
*/
int mapcache_ruleset_is_visible_tile(mapcache_rule* rule, mapcache_tile *tile) {
if(!rule || !rule->visible_limits) {
int i;

if(!rule || !rule->visible_limits || apr_is_empty_array(rule->visible_limits)) {
return MAPCACHE_TRUE;
}

if(tile->x < rule->visible_limits->minx || tile->y < rule->visible_limits->miny ||
tile->x > rule->visible_limits->maxx || tile->y > rule->visible_limits->maxy) {
return MAPCACHE_FALSE;
for(i = 0; i < rule->visible_limits->nelts; i++) {
mapcache_extent_i *extent = APR_ARRAY_IDX(rule->visible_limits, i, mapcache_extent_i*);

if(tile->x >= extent->minx && tile->y >= extent->miny &&
tile->x <= extent->maxx && tile->y <= extent->maxy) {
return MAPCACHE_TRUE;
}
}

return MAPCACHE_TRUE;
return MAPCACHE_FALSE;
}

/*

0 comments on commit 4b93fec

Please sign in to comment.
You can’t perform that action at this time.