mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
parameterize_style.cpp File Reference
#include <algorithm>
#include <cctype>
#include <cstring>
#include <glib.h>
#include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/params.hpp>
#include <mapnik/version.hpp>
#include <sstream>
#include <string>
#include <unordered_map>
#include <boost/optional.hpp>
#include "g_logger.h"
#include "parameterize_style.hpp"

Functions

static bool is_valid_osm_lang_tag (const std::string &tok)
 Validate that a language token is a safe OpenStreetMap name:* tag suffix.
static void parameterize_map_language (mapnik::Map &m, char *parameter)
 Rewrite Mapnik layer SQL queries to localize name columns using a fallback chain of language tags.
static void parameterize_map_toggle_layer (mapnik::Map &m, char *parameter)
 Enable or disable individual Mapnik layers by name based on a comma-separated directive list.
parameterize_function_ptr init_parameterization_function (const char *function_name)
 Look up the Mapnik style parameterization callback corresponding to a configuration name.

Function Documentation

◆ init_parameterization_function()

parameterize_function_ptr init_parameterization_function ( const char * function_name)

Look up the Mapnik style parameterization callback corresponding to a configuration name.

Currently supports "language" (parameterize_map_language) and "toggle_layer" (parameterize_map_toggle_layer).

Parameters
function_nameName of the parameterization function from renderd.conf (may be NULL or empty).
Returns
Matching parameterize_function_ptr callback, or NULL if unset or unrecognized.

◆ is_valid_osm_lang_tag()

bool is_valid_osm_lang_tag ( const std::string & tok)
static

Validate that a language token is a safe OpenStreetMap name:* tag suffix.

Accepts the "_" default fallback as well as non-empty alphanumeric, underscore, or hyphen strings up to 32 characters (covering ISO 639 codes and IETF BCP 47 subtags) to prevent SQL injection into PostGIS tags->'name:...' expressions.

Parameters
tokCandidate language token extracted from the comma-separated parameter string.
Returns
true if tok contains only allowed characters and satisfies length bounds; false otherwise.

◆ parameterize_map_language()

void parameterize_map_language ( mapnik::Map & m,
char * parameter )
static

Rewrite Mapnik layer SQL queries to localize name columns using a fallback chain of language tags.

Parses a comma-separated list of language codes (capped at 256 bytes, e.g., "de,en,_"), validates each token via is_valid_osm_lang_tag(), builds a SQL , coalesce(tags->'name:de',tags->'name:en',name) as name projection, and replaces the first ,name occurrence in each datasource's "table" parameter.

Parameters
mMapnik Map instance whose layer datasources are updated in place.
parameterNull-terminated comma-separated language fallback list (no-op if NULL, empty, over 256 bytes, or containing no valid tokens).

◆ parameterize_map_toggle_layer()

void parameterize_map_toggle_layer ( mapnik::Map & m,
char * parameter )
static

Enable or disable individual Mapnik layers by name based on a comma-separated directive list.

Parses comma-separated layer tokens (capped at 1024 bytes): a leading '+' enables the named layer, a leading '-' disables it, and an unprefixed name defaults to disabling it. Later tokens for the same layer name override earlier ones.

Parameters
mMapnik Map instance whose layers are toggled in place.
parameterNull-terminated comma-separated list of layer directives (e.g., "+roads,-buildings,labels").