Skip to content

Commit d5785e6

Browse files
committed
Expand FeatureInfo templates documentation
1 parent 7e93ada commit d5785e6

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

src/topics/FeatureInfo.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,26 @@ With the `qwc-feature-info-service`, you can query features directly from a data
5050
"template": "<div><h2>Demo Template</h2>Pos: {{ x }}, {{ y }}<br>Name: {{ feature.Name }}</div>"
5151
}
5252
```
53-
*Note:* `x`, `y` and `geom` are passed as parameters to the SQL query. If a `GetFeatureInfo` request is being processed with a `filter_geom` parameter, `geom` will correspond to that parameter. Otherwise `geom` will be `POINT(x y)`.
53+
54+
In a DB Query the following values are replaced in the SQL:
55+
56+
* `:x`: X coordinate of query
57+
* `:y`: Y coordinate of query
58+
* `:srid`: SRID of query coordinates
59+
* `:resolution`: Resolution in map units per pixel
60+
* `:FI_POINT_TOLERANCE`: Tolerance for picking points, in pixels (default=16)
61+
* `:FI_LINE_TOLERANCE`: Tolerance for picking lines, in pixels (default=8)
62+
* `:FI_POLYGON_TOLERANCE`: Tolerance for picking polygons, in pixels (default=4)
63+
* `:i`: X ordinate of query point on map, in pixels
64+
* `:j`: Y ordinate of query point on map, in pixels
65+
* `:height`: Height of map output, in pixels
66+
* `:width`: Width of map output, in pixels
67+
* `:bbox`: 'Bounding box for map extent as minx,miny,maxx,maxy'
68+
* `:crs`: 'CRS for map extent'
69+
* `:feature_count`: Max feature count
70+
* `:with_geometry`: Whether to return geometries in response (default=1)
71+
* `:with_maptip`: Whether to return maptip in response (default=1)
72+
* `:geom`: The `filter_geom` passed to the `GetFeatureInfo` request, if any, otherwise `POINT(x y)`
5473

5574
### Attribute values: HTML markup, hyperlinks, images
5675

@@ -154,19 +173,49 @@ Example `info_template` with template path:
154173
}
155174
```
156175

157-
*Note:*
176+
The template must only contain the body content (without `head`, `script`, `body`).
158177

159-
- `x` and `y` are the info query coordinates. `feature.<attr>` renders the `attr` attribute value of the feature.
160-
- The templates must be HTML fragments *without* `html` or `body` tags.
161-
- The templates folder needs to be mounted into the `qwc-feature-info-service` container, i.e.:
162-
```yml
163-
qwc-feature-info-service:
164-
image: sourcepole/qwc-feature-info-service:vYYYY.MM.DD
165-
volumes:
166-
...
167-
- ./volumes/info-templates:/info_templates:ro
178+
This template can contain attribute value placeholders, in the form
179+
180+
{{ feature.attr }}
181+
182+
which are replaced with the respective values when the template is rendered (using [Jinja2](http://jinja.pocoo.org/)).
183+
The following values are available in the template:
184+
185+
* `x`, `y`, `crs`: Coordinates and CRS of info query
186+
* `feature`: Feature with attributes from info result as properties, e.g. `feature.name`
187+
* `fid`: Feature ID (if present)
188+
* `bbox`: Feature bounding box as `[<minx>, <miny>, <maxx>, <maxy>]` (if present)
189+
* `geometry`: Feature geometry as WKT (if present)
190+
* `layer`: Layer name
191+
192+
To automatically detect hyperlinks in values and replace them as HTML links as well as transform image URLs to inline images the following helper can be used in the template:
193+
194+
render_value(value)
195+
196+
When using [localized themes](./Translations.md#translated-themes), if you want to make QWC translate the attribute names, enclose these in `translate()`.
197+
198+
Example:
199+
200+
```xml
201+
<div>Result at coordinates {{ x }}, {{ y }}</div>
202+
<table>
203+
<tr>
204+
<td>translate(Name):</td>
205+
<td>{{ feature.name }}</td>
206+
</tr>
207+
<tr>
208+
<td>translate(Description):</td>
209+
<td>{{ feature.description }}</td>
210+
</tr>
211+
<tr>
212+
<td>translate(Link):</td>
213+
<td>{{ render_value(feature.link) }}</td>
214+
</tr>
215+
</table>
168216
```
169217

218+
170219
### Localization
171220

172221
The `qwc-feature-info-service` supports switching the runtime locale by setting the `LOCALE` environment variable, i.e.:

src/topics/Translations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ By default, QWC will attempt to load the translation matching your browser langu
66

77
The [Settings Plugin](../references/qwc2_plugins.md#settings) furthermore allows graphically switching the language within QWC, with the list of available languages configured via the `languages` plugin configuration property.
88

9-
### Translated themes
9+
### Translated themes <a name="translated-themes"></a>
1010

1111
QWC also supports localized themes, including in particular the theme name, layer and attribute names.
1212

@@ -104,7 +104,7 @@ where `<lang>-<COUNTRY>` is a language-country code like `de-CH`.
104104
The service will then check if `myfile_<lang>-<COUNTRY>.ext` or `myfile_<lang>.ext` exist, returning the first possible match, falling back to `myfile.ext` if neither exists.
105105

106106

107-
### Adding and modifying Viewer translations
107+
### Adding and modifying viewer translations
108108

109109
When working inside a `qwc-app` source folder, the translations are located at `qwc-app/static/translations`.
110110

0 commit comments

Comments
 (0)