mirror of
https://github.com/openstreetmap/mod_tile.git
synced 2025-08-12 02:41:14 +00:00
Support options for tile layers in mod_tile.
If a tile layer has options enabled, the URL changes to http://localhost/style/options/z/x/y.ext
This commit is contained in:
@ -87,6 +87,7 @@ typedef struct {
|
||||
int maxzoom;
|
||||
int aspect_x;
|
||||
int aspect_y;
|
||||
int enableOptions;
|
||||
} tile_config_rec;
|
||||
|
||||
typedef struct {
|
||||
|
@ -115,8 +115,8 @@ enum protoCmd rx_request(struct protocol *req, int fd)
|
||||
return cmdNotDone;
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "DEBUG: Got command %s fd(%d) xml(%s), z(%d), x(%d), y(%d)",
|
||||
cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y);
|
||||
syslog(LOG_DEBUG, "DEBUG: Got command %s fd(%d) xml(%s), z(%d), x(%d), y(%d), mime(%s), options(%s)",
|
||||
cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y, req->mimetype, req->options);
|
||||
|
||||
if ((req->cmd != cmdRender) && (req->cmd != cmdRenderPrio) && (req->cmd != cmdRenderLow) && (req->cmd != cmdDirty) && (req->cmd != cmdRenderBulk)) {
|
||||
syslog(LOG_WARNING, "WARNING: Ignoring unknown command %s fd(%d) xml(%s), z(%d), x(%d), y(%d)",
|
||||
|
@ -203,7 +203,6 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
|
||||
}
|
||||
|
||||
// cmd has already been partial filled, fill in the rest
|
||||
cmd->ver = 2; //PROTO_VER;
|
||||
switch (renderImmediately) {
|
||||
case 0: { cmd->cmd = cmdDirty; break;}
|
||||
case 1: { cmd->cmd = cmdRenderLow; break;}
|
||||
@ -215,9 +214,16 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
|
||||
|
||||
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Requesting style(%s) z(%d) x(%d) y(%d) from renderer with priority %d", cmd->xmlname, cmd->z, cmd->x, cmd->y, cmd->cmd);
|
||||
do {
|
||||
switch (cmd->ver) {
|
||||
case 2:
|
||||
ret = send(fd, cmd, sizeof(struct protocol_v2), 0);
|
||||
break;
|
||||
case 3:
|
||||
ret = send(fd, cmd, sizeof(struct protocol), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == sizeof(struct protocol_v2))
|
||||
if ((ret == sizeof(struct protocol_v2)) || (ret == sizeof(struct protocol)))
|
||||
break;
|
||||
|
||||
if (errno != EPIPE) {
|
||||
@ -1302,11 +1308,23 @@ static int tile_translate(request_rec *r)
|
||||
return OK;
|
||||
}
|
||||
|
||||
char parameters[XMLCONFIG_MAX];
|
||||
if (tile_config->enableOptions) {
|
||||
cmd->ver = PROTO_VER;
|
||||
n = sscanf(r->uri+strlen(tile_config->baseuri),"%[^/]/%d/%d/%d.%[a-z]/%10s", parameters,&(cmd->z), &(cmd->x), &(cmd->y), extension, option);
|
||||
if (n < 5) {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s with options", tile_config->xmlname);
|
||||
return DECLINED;
|
||||
}
|
||||
} else {
|
||||
cmd->ver = 2;
|
||||
n = sscanf(r->uri+strlen(tile_config->baseuri),"%d/%d/%d.%[a-z]/%10s", &(cmd->z), &(cmd->x), &(cmd->y), extension, option);
|
||||
if (n < 4) {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s", tile_config->xmlname);
|
||||
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s without options", tile_config->xmlname);
|
||||
return DECLINED;
|
||||
}
|
||||
parameters[0] = 0;
|
||||
}
|
||||
if (strcmp(extension, tile_config->fileExtension) != 0) {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid file extension (%s) for tilelayer %s, required %s",
|
||||
extension, tile_config->xmlname, tile_config->fileExtension);
|
||||
@ -1330,6 +1348,8 @@ static int tile_translate(request_rec *r)
|
||||
}
|
||||
|
||||
strcpy(cmd->xmlname, tile_config->xmlname);
|
||||
strcpy(cmd->mimetype, tile_config->mimeType);
|
||||
strcpy(cmd->options,parameters);
|
||||
|
||||
// Store a copy for later
|
||||
rdata->cmd = cmd;
|
||||
@ -1347,7 +1367,7 @@ static int tile_translate(request_rec *r)
|
||||
|
||||
r->filename = NULL;
|
||||
|
||||
if (n == 5) {
|
||||
if ((tile_config->enableOptions && (n == 6)) || ( !tile_config->enableOptions && (n == 5))) {
|
||||
if (!strcmp(option, "status")) r->handler = "tile_status";
|
||||
else if (!strcmp(option, "dirty")) r->handler = "tile_dirty";
|
||||
else return DECLINED;
|
||||
@ -1623,7 +1643,7 @@ static void register_hooks(__attribute__((unused)) apr_pool_t *p)
|
||||
static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,
|
||||
const char *baseuri, const char *name, int minzoom, int maxzoom, int aspect_x, int aspect_y,
|
||||
const char * fileExtension, const char *mimeType, const char *description, const char * attribution,
|
||||
int noHostnames, char ** hostnames, const char * cors, const char * tile_dir)
|
||||
int noHostnames, char ** hostnames, const char * cors, const char * tile_dir, const int parameterize)
|
||||
{
|
||||
int i;
|
||||
int urilen;
|
||||
@ -1692,6 +1712,7 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,
|
||||
tilecfg->hostnames = hostnames;
|
||||
tilecfg->cors = cors;
|
||||
tilecfg->store = tile_dir;
|
||||
tilecfg->enableOptions = parameterize;
|
||||
|
||||
ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, cmd->server,
|
||||
"Loading tile config %s at %s for zooms %i - %i from tile directory %s with extension .%s and mime type %s",
|
||||
@ -1704,17 +1725,17 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,
|
||||
static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char * fileExtension)
|
||||
{
|
||||
if (strcmp(fileExtension,"png") == 0) {
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png",NULL,NULL,0,NULL,NULL,NULL);
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png",NULL,NULL,0,NULL,NULL,NULL,0);
|
||||
}
|
||||
if (strcmp(fileExtension,"js") == 0) {
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "text/javascript",NULL,NULL,0,NULL,"*", NULL);
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "text/javascript",NULL,NULL,0,NULL,"*", NULL,0);
|
||||
}
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png",NULL,NULL,0,NULL,NULL, NULL);
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png",NULL,NULL,0,NULL,NULL, NULL,0);
|
||||
}
|
||||
|
||||
static const char *add_tile_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name)
|
||||
{
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, "png", "image/png",NULL,NULL,0,NULL,NULL,NULL);
|
||||
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, "png", "image/png",NULL,NULL,0,NULL,NULL,NULL,0);
|
||||
}
|
||||
|
||||
static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *conffile)
|
||||
@ -1741,6 +1762,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
|
||||
int maxzoom = MAX_ZOOM;
|
||||
int aspect_x = 1;
|
||||
int aspect_y = 1;
|
||||
int parameterize = 0;
|
||||
|
||||
if (strlen(conffile) == 0) {
|
||||
strcpy(filename, RENDERD_CONFIG);
|
||||
@ -1761,7 +1783,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
|
||||
/*Add the previous section to the configuration */
|
||||
if (tilelayer == 1) {
|
||||
result = _add_tile_config(cmd, mconfig, url, xmlname, minzoom, maxzoom, aspect_x, aspect_y, fileExtension, mimeType,
|
||||
description,attribution,noHostnames,hostnames, cors, tile_dir);
|
||||
description,attribution,noHostnames,hostnames, cors, tile_dir, parameterize);
|
||||
if (result != NULL) {
|
||||
fclose(hini);
|
||||
return result;
|
||||
@ -1799,6 +1821,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
|
||||
maxzoom = MAX_ZOOM;
|
||||
aspect_x = 1;
|
||||
aspect_y = 1;
|
||||
parameterize = 0;
|
||||
} else if (sscanf(line, "%[^=]=%[^;#]", key, value) == 2
|
||||
|| sscanf(line, "%[^=]=\"%[^\"]\"", key, value) == 2) {
|
||||
|
||||
@ -1873,13 +1896,16 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
|
||||
if (!strcmp(key, "ASPECTY")){
|
||||
aspect_y = atoi(value);
|
||||
}
|
||||
if (!strcmp(key,"PARAMETERIZE_STYLE")) {
|
||||
parameterize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tilelayer == 1) {
|
||||
//ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->server,
|
||||
// "Committing tile config %s", xmlname);
|
||||
result = _add_tile_config(cmd, mconfig, url, xmlname, minzoom, maxzoom, aspect_x, aspect_y, fileExtension, mimeType,
|
||||
description,attribution,noHostnames,hostnames, cors, tile_dir);
|
||||
description,attribution,noHostnames,hostnames, cors, tile_dir, parameterize);
|
||||
if (result != NULL) {
|
||||
fclose(hini);
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user