Problem/Motivation
Token support is currently limited to only 2 feature level variables: popup & icon. These are also trhemselves limited to entity tokens (I say "limited" but that may be a slight mis-statement, since entity tokens have to be explicitly allowed, so this is kind of an expanded access to tokens?). Token support for map global and layer configuration options would enable more dynamic layer querying options - such as requesting certain maps, or features to the Tile servers.
A simple case study for this is a Drupal system that provides the ability to generate WMS base maps from the Drupal database to lay under the vector maps in the Leaflet display - see Image 1 for an examples (WMS watershed and Leaflet Vector wells - both from Drupal). In this case, the token [current-page:url:args:value:1] is used to pass the Drupal Entity_ID of the watershed shape to the WMS server to render as an overlay (Leaflet Map Info below in 'Code 1'). This example is based on the first submitted patch.
Code 1: Leaflet map configuration with token in urlTemplate setting.
$attr_owm = 'OpenWeatherMap. ' . $attr_osm;
$wmsadd = 'my.url.com/cgi-bin/mapserv?map=/var/www/html/mapserv/dh_feature_basemap.map&hydroid=[current-page:url:args:value:1]';
$map_info['my-features-wms'] = array(
'label' => 'Feature Overview (zoom 0..18)',
'description' => t('Feature Outline'),
'settings' => $default_settings,
'layers' => array(
'base' => array(
'urlTemplate' => $prot . "{s}.tile.openstreetmap.org/$zxy",
'options' => array(
'attribution' => $attr_owm
),
'layer_type' => 'base', // Allowed values "base" or "overlay"
),
'watershed' => array(
'urlTemplate' => $prot . "$wmsadd",
'options' => array(
'attribution' => $attr_owm,
'wms' => true,
'layers' => 'dh_background',
'transparent' => true,
'maxZoom' => 15,
'minZoom' => 0,
'format' => 'image/png',
),
'layer_type' => 'overlay', // Allowed values "base" or "overlay"
),
),
);
Image 1: Image 1 shows a system with a watershed Drupal Content entity from WMS as a base layer using Contextual Argument #1 for Entity ID passed to WMS server, with Vector features showing groundwater wells (also drupal entities).
Proposed resolution
Provide generic token support for all configuration options. Current code version only supports $layer['urlTemplate']. See Code #2 for proposed modifications to leaflet_build_map().
Code 2: Example of token support for Layer urlTemplate values.
// apply tokens to URL if requested
$layer_token_support = array('urlTemplate');
foreach ($layer_token_support as $token) {
foreach ($map['layers'] as &$layer) {
if (isset($layer[$token])) {
drupal_set_message("Replacing tokens in " . $layer[$token]);
$layer[$token] = token_replace($layer[$token]);
drupal_set_message("Result " . $layer[$token]);
}
}
}
Remaining tasks
Determine concise coding solution to turn on/off supported configuration elements.
Review.
User interface changes
(New or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text.)
API changes
Add a configuration checkbox to enable Token support in different places. Off by default.
Data model changes
none.
Comment | File | Size | Author |
---|---|---|---|
#3 | leaflet-generic-token-support-2585277-03.patch | 714 bytes | robertwb |
#2 | leaflet_wms-tokens.png | 158.45 KB | robertwb |
leaflet_wms-tokens.png | 157.65 KB | robertwb |
Comments
Comment #2
robertwb CreditAttribution: robertwb commentedComment #3
robertwb CreditAttribution: robertwb commentedComment #4
robertwb CreditAttribution: robertwb commentedComment #5
RdeBoerNice work, Robert!
Rik
Comment #6
robertwb CreditAttribution: robertwb commentedThanks Rik! I am wondering if you had a thought about what config options should be exposed for token replacement, or if we should just iterate through the config array and do'em all?
Comment #7
robertwb CreditAttribution: robertwb commented