diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 677aafd..a05775e 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -398,6 +398,19 @@ class API(object): 'Content-type': 'application/json' } + formats = ['json', 'html'] + + format_ = args.get('f') + if format_ is not None and format_ not in formats: + exception = { + 'code': 'InvalidParameterValue', + 'description': 'Invalid format' + } + LOGGER.error(exception) + return headers_, 400, json.dumps(exception) + + LOGGER.debug('Processing query parameters') + if dataset not in self.config['datasets'].keys(): exception = { 'code': 'InvalidParameterValue', @@ -431,6 +444,12 @@ class API(object): } ] + if format_ == 'html': # render + headers_['Content-type'] = 'text/html' + content = _render_j2_template(self.config, 'item.html', + content) + return headers_, 200, content + return headers_, 200, json.dumps(content) @@ -442,7 +461,7 @@ def to_json(dict_): :returns: JSON string representation """ - import json + return json.dumps(dict_) diff --git a/pygeoapi/templates/item.html b/pygeoapi/templates/item.html new file mode 100644 index 0000000..50d2cf6 --- /dev/null +++ b/pygeoapi/templates/item.html @@ -0,0 +1,54 @@ +{% extends "base.html" %} +{% block title %}{{ super() }} {{ data['title'] }} {% endblock %} +{% block extrahead %} + + + +{% endblock %} + +{% block body %} +
+

{{ data['title'] }}

+ {{ data['description'] }} +

Feature {{ data['ID'] }} JSON

+ + + + + +

Properties

+
    + {% for k, v in data['properties'].items() %} +
  • {{ k }}: {{ v }}
  • + {% endfor %} +
+
+
+
+
+{% endblock %} + +{% block extrafoot %} + +{% endblock %} diff --git a/pygeoapi/templates/items.html b/pygeoapi/templates/items.html index b13c231..b957084 100644 --- a/pygeoapi/templates/items.html +++ b/pygeoapi/templates/items.html @@ -18,13 +18,13 @@

{{ data['title'] }}

{{ data['description'] }} -

Features JSON

+

Features JSON

@@ -48,7 +48,7 @@ var geojson_data = {{ data['features'] |to_json }}; var items = new L.GeoJSON(geojson_data, { onEachFeature: function (feature, layer) { - var html_ = '' + feature.ID + ''; + var html_ = '' + feature.ID + ''; layer.bindPopup(html_); } });