Skip to content

Commit a346728

Browse files
authored
Allow key=value parameters for AddTileConfig (#346)
AddTileConfig is a shorthand way of adding tile configs without a renderd.conf; if you use mod_tile with tirex, then you will typically not have a renderd.conf and hence rely on AddTileConfig. AddTileConfig lacks the richness of renderd.conf configuration; you cannot, for example, configure differing max_zooms or file extensions or mime types. To partly fix this problem, AddTileMimeConfig was introduced which takes one extra argument - misleadingly, not the MIME type, but the file extension, as a third parameter. This approach is not scalable and difficult to use because of the positional parameters. This pull request introduces optional key-value pairs for the AddTileConfig directive. You can now write AddTileConfig /tile tile mimetype=image/jpeg extension=jpg maxzoom=22 to configure your tile layer. Currently, "mimetype", "maxzoom", "minzoom", and "extension" are supported. This is totally backwards compatible, as old-style AddTileConfig directives will still work like they did before. The AddTileMimeConfig directive still works but it could be deprecated in favour of this new AddTileConfig syntax. Co-authored-by: Frederik Ramm <ramm@geofabrik.de>
1 parent c7ffa83 commit a346728

1 file changed

Lines changed: 43 additions & 5 deletions

File tree

src/mod_tile.c

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,9 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,
20922092

20932093
static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char * fileExtension)
20942094
{
2095+
// this configuration option should be deprecated and be replaced by
2096+
// a version of AddTileConfig with "extension=xxx"
2097+
// how to log a warning here?
20952098
if (strcmp(fileExtension, "png") == 0) {
20962099
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png", NULL, NULL, 0, NULL, NULL, NULL, 0);
20972100
}
@@ -2103,11 +2106,46 @@ static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const cha
21032106
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png", NULL, NULL, 0, NULL, NULL, NULL, 0);
21042107
}
21052108

2106-
static const char *add_tile_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name)
2109+
static const char *add_tile_config(cmd_parms *cmd, void *mconfig, const char *args)
21072110
{
2108-
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, "png", "image/png", NULL, NULL, 0, NULL, NULL, NULL, 0);
2109-
}
2111+
const char *baseuri = ap_getword_conf(cmd->pool, &args);
2112+
if (!baseuri) return("AddTileConfig error");
2113+
const char *name = ap_getword_conf(cmd->pool, &args);
2114+
if (!name) return("AddTileConfig error");
2115+
int maxzoom = MAX_ZOOM;
2116+
int minzoom = 0;
2117+
const char *extension = "png";
2118+
const char *mimeType = "image/png";
2119+
char *token = ap_getword_conf(cmd->pool, &args);
2120+
while(token)
2121+
{
2122+
char *eq = strchr(token, '=');
2123+
if (eq)
2124+
{
2125+
*eq++=0;
2126+
if (!strcmp(token, "maxzoom"))
2127+
{
2128+
maxzoom = atoi(eq);
2129+
}
2130+
else if (!strcmp(token, "minzoom"))
2131+
{
2132+
minzoom = atoi(eq);
2133+
}
2134+
else if (!strcmp(token, "extension"))
2135+
{
2136+
extension = eq;
2137+
}
2138+
else if (!strcmp(token, "mimetype"))
2139+
{
2140+
mimeType = eq;
2141+
}
2142+
}
2143+
if (!*args) break;
2144+
token = ap_getword_conf(cmd->pool, &args);
2145+
}
21102146

2147+
return _add_tile_config(cmd, mconfig, baseuri, name, minzoom, maxzoom, 1, 1, extension, mimeType, NULL,NULL,0,NULL,NULL,NULL,0);
2148+
}
21112149
static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *conffile)
21122150
{
21132151
FILE * hini ;
@@ -2851,12 +2889,12 @@ static const command_rec tile_cmds[] = {
28512889
OR_OPTIONS, /* where available */
28522890
"load an entire renderd config file" /* directive description */
28532891
),
2854-
AP_INIT_TAKE2(
2892+
AP_INIT_RAW_ARGS(
28552893
"AddTileConfig", /* directive name */
28562894
add_tile_config, /* config action routine */
28572895
NULL, /* argument to include in call */
28582896
OR_OPTIONS, /* where available */
2859-
"path and name of renderd config to use" /* directive description */
2897+
"path, name, and optional key-value pairs for renderd config to use" /* directive description */
28602898
),
28612899
AP_INIT_TAKE3(
28622900
"AddTileMimeConfig", /* directive name */

0 commit comments

Comments
 (0)