forked from qwc-services/qwc-feature-info-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo_templates.py
115 lines (110 loc) · 5.24 KB
/
info_templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from jinja2 import Template
# template for GetFeatureInfoResponse <Layer> tag
layer_template = Template("""
<Layer name="{{ layer_title|e }}" layername="{{ layer_name|e }}"
{{ 'layerinfo="%s"' | format(parent_facade if parent_facade else layer_name) }}
{{ 'featurereport="%s"' | format(feature_report) if feature_report }}
{{ 'displayfield="%s"' | format(display_field) if display_field }}>
{%- for feature in features %}
<Feature id="{{ feature['fid'] if feature['fid'] }}">
{{ feature['html_content'] }}
{% if feature['bbox'] %}
<BoundingBox CRS="{{ crs }}"
minx="{{ feature['bbox'][0] }}" miny="{{ feature['bbox'][1] }}"
maxx="{{ feature['bbox'][2] }}" maxy="{{ feature['bbox'][3] }}"
/>
{%- endif %}
{% if feature['wkt_geom'] %}
<Attribute name="geometry" value="{{ feature['wkt_geom'] }}"
type="derived" />
{%- endif %}
{% for attr in feature.attributes %}
<Attribute name="{{ attr['alias']|e }}" value="{{ attr['value']|e }}" attrname="{{ attr['name'] }}" />
{%- endfor %}
</Feature>
{% endfor -%}
</Layer>
""")
# default info template for feature info HTML
default_info_template = """
<table class="attribute-list">
<tbody>
{% for attr in feature._attributes -%}
{% if attr['type'] == 'list' -%}
{# attribute is a list #}
<tr>
<td class="identify-attr-title wrap"><i>{{ attr['alias']|e }}</i></td>
<td>
<table class="identify-attr-subtable">
<tbody>
{%- for item in attr['value'] %}
{%- if item is mapping -%}
{# item is a dict #}
{% for key in item -%}
{% if not attr['json_aliases'] %}
{% set alias = key %}
{% elif key in attr['json_aliases'] %}
{% set alias = attr['json_aliases'][key] %}
{% endif %}
{% if alias %}
<tr>
<td class="identify-attr-title wrap">
<i>{{ alias|e }}</i>
</td>
<td class="identify-attr-value wrap">
{{ render_value(item[key]) }}
</td>
</tr>
{% endif %}
{%- endfor %}
{%- else -%}
<tr>
<td class="identify-attr-value identify-attr-single-value wrap" colspan="2">
{{ render_value(item) }}
</td>
</tr>
{%- endif %}
<tr>
<td class="identify-attr-spacer" colspan="2"></td>
</tr>
{%- endfor %}
</tbody>
</table>
</td>
</tr>
{%- elif attr['type'] in ['dict', 'OrderedDict'] -%}
{# attribute is a dict #}
<tr>
<td class="identify-attr-title wrap"><i>{{ attr['alias']|e }}</i></td>
<td>
<table class="identify-attr-subtable">
<tbody>
{% for key in attr['value'] -%}
<tr>
<td class="identify-attr-title wrap">
<i>{{ key|e }}</i>
</td>
<td class="identify-attr-value wrap">
{{ render_value(attr['value'][key]) }}
</td>
</tr>
{%- endfor %}
</tbody>
</table>
</td>
</tr>
{%- else -%}
{# other attributes #}
<tr>
<td class="identify-attr-title wrap">
<i>{{ attr['alias']|e }}</i>
</td>
<td class="identify-attr-value wrap">
{{ render_value(attr['value']) }}
</td>
</tr>
{%- endif %}
{%- endfor %}
</tbody>
</table>
"""