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
|
{# Macro that renders a bounding box element from feature list #}
{% macro render_bounded_by(features) -%}
{# first assemble all latitudes and longitudes #}
{% set longitudes = [] %}
{% set latitudes = [] %}
{% for feature in features %}
{% do longitudes.append(feature.lon) %}
{% do latitudes.append(feature.lat) %}
{% endfor %}
<!-- Rendered by macro render_bounded_by() -->
{# use the maximum and minimum Jinja2 Filters to get max/min from lists #}
<gml:boundedBy>
<gml:Box>
<gml:coord>
<gml:X>{{ longitudes|minimum }}</gml:X>
<gml:Y>{{ latitudes|minimum }}</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>{{ longitudes|maximum }}</gml:X>
<gml:Y>{{ latitudes|maximum }}</gml:Y>
</gml:coord>
</gml:Box>
</gml:boundedBy>
{%- endmacro %}
{# Macro that renders a name element #}
{% macro render_name(name) -%}
<!-- Rendered by macro render_name() -->
<gml:name>
{{ name }}
</gml:name>
{%- endmacro %}
{# Macro that renders any element with tag and content :-) #}
{% macro render_element(tag, content) -%}
<!-- Rendered by macro render_element() -->
<{{tag}}>
{{ content }}
</{{tag}}>
{%- endmacro %}
|