Skip to content

Commit

Permalink
GetFeatureInfo Template suport for media formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Jun 10, 2020
1 parent c75efc0 commit f3d87b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
37 changes: 33 additions & 4 deletions mapstore2_adapter/plugins/geonode.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,49 @@ def get_overlays(self, viewer, request=None):
overlay['bbox']['crs'] = layer['srs'] if 'srs' in layer else \
viewer_obj['map']['projection']

if 'getFeatureInfo' in layer and layer['getFeatureInfo']:
if 'ftInfoTemplate' in layer and layer['ftInfoTemplate']:
featureInfo = {'format': 'TEMPLATE'}
featureInfo['template'] = layer['ftInfoTemplate']
overlay['featureInfo'] = featureInfo
elif 'getFeatureInfo' in layer and layer['getFeatureInfo']:
if 'fields' in layer['getFeatureInfo'] and layer['getFeatureInfo']['fields'] and \
'propertyNames' in layer['getFeatureInfo'] and \
layer['getFeatureInfo']['propertyNames']:
fields = layer['getFeatureInfo']['fields']
propertyNames = layer['getFeatureInfo']['propertyNames']
displayTypes = layer['getFeatureInfo']['displayTypes']
featureInfo = {'format': 'TEMPLATE'}

_template = '<div>'
for _field in fields:
_label = propertyNames[_field] if propertyNames[_field] else _field
_template += '<div class="row">'
_template += '<div class="col-xs-4" style="font-weight: bold; word-wrap: break-word;">%s</div> \
<div class="col-xs-8" style="word-wrap: break-word;">${properties.%s}</div>' % \
(propertyNames[_field] if propertyNames[_field] else _field, _field)

if displayTypes[_field] == 'type_href':
_template += '<div class="col-xs-6" style="font-weight: bold; word-wrap: break-word;">%s:</div> \
<div class="col-xs-6" style="word-wrap: break-word;"><a href="${properties.%s}" target="_new">${properties.%s}</a></div>' % \
(_label, _field, _field)
elif displayTypes[_field] == 'type_image':
_template += '<div class="col-xs-12" align="center" style="font-weight: bold; word-wrap: break-word;"> \
<img width="100%%" height="auto" src="${properties.%s}" title="%s" alt="%s"/></div>' % \
(_field, _label, _label)
elif displayTypes[_field] == 'type_video':
_template += '<div class="col-xs-12" align="center" style="font-weight: bold; word-wrap: break-word;"> \
<video width="100%%" height="360" controls><source src="${properties.%s}" type="video/mp4">Your browser does not support the video tag.</video></div>' % \
(_field)
elif displayTypes[_field] == 'type_audio':
_template += '<div class="col-xs-12" align="center" style="font-weight: bold; word-wrap: break-word;"> \
<audio controls><source src="${properties.%s}" type="audio/mpeg">Your browser does not support the audio element.</audio></div>' % \
(_field)
elif displayTypes[_field] == 'type_iframe':
_template += '<div class="col-xs-12" align="center" style="font-weight: bold; word-wrap: break-word;"> \
<iframe src="${properties.%s}" width="100%%" height="360" frameborder="0" allowfullscreen></iframe></div>' % \
(_field)
else:
_template += '<div class="col-xs-6" style="font-weight: bold; word-wrap: break-word;">%s:</div> \
<div class="col-xs-6" style="word-wrap: break-word;">${properties.%s}</div>' % \
(propertyNames[_field] if propertyNames[_field] else _field, _field)

_template += '</div>'
_template += '</div>'

Expand Down
2 changes: 2 additions & 0 deletions mapstore2_adapter/plugins/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def decode_base64(data):

# Store the Capabilities Document into the Layer Params of GeoNode
if _lyr_context:
if 'ftInfoTemplate' in _lyr_context:
_lyr['ftInfoTemplate'] = _lyr_context['ftInfoTemplate']
if 'getFeatureInfo' in _lyr_context:
_lyr['getFeatureInfo'] = _lyr_context['getFeatureInfo']
if 'capability' in _lyr_context:
Expand Down

0 comments on commit f3d87b9

Please sign in to comment.