-
Notifications
You must be signed in to change notification settings - Fork 0
/
geojson.ftl
68 lines (62 loc) · 1.95 KB
/
geojson.ftl
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
<#ftl encoding="utf-8" />
<#import "/web/templates/modernui/funnelback_classic.ftl" as s/>
<#import "/web/templates/modernui/funnelback.ftl" as fb/>
<#compress>
<#-- geojson.ftl
Outputs Funnelback response in GeoJSON format.
Date: June 2013
Author: Gordon Grace
See also:
http://www.geojson.org/geojson-spec.html
http://geojsonlint.com/
http://docs.funnelback.com/ui_modern_form_content_type_collection_cfg.html
Pre-requisites:
- Collection has geospatial component, encoded as lat/longs only
- collection.cfg has template response type correctly set to application/json (ui.modern.form.geojson.content_type=application/json)
ToDo:
- Handle best bets?
- Handle partial matches?
- Handle complex geometry output
- Allow definitions of indexed metadata at top of template
-->
<@fb.ViewModeBanner />
<@fb.ErrorMessage />
<@s.InitialFormOnly>
</@s.InitialFormOnly>
<@s.AfterSearchOnly>
<#-- NO RESULTS -->
<#if response.resultPacket.resultsSummary.totalMatching == 0>
{
"resp":{
"code":400,
"status":"ERROR",
"errorMessage":"No matching results."
}
}
<#else>
<#-- RESULTS -->
{"type": "FeatureCollection",
"features": [
<@s.Results>
<#if s.result.class.simpleName == "TierBar">
<#if s.result.matched == s.result.outOf>
<#else></#if>
<#else>
<#-- EACH RESULT -->
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [${s.result.metaData["x"]?replace(".*\\;","","r")},${s.result.metaData["x"]?replace("\\;.*","","r")}]},
"properties": {
"title": "${s.result.title}",
"description": "${s.result.metaData["c"]}",
"kmFromOrigin": "${s.result.kmFromOrigin}",
"url": "${s.result.liveUrl?html}"
<#-- MORE METADATA FIELDS... -->
}
}<#if s.result.rank < response.resultPacket.resultsSummary.currEnd>,</#if>
</#if>
</@s.Results>
]
}
</#if>
</@s.AfterSearchOnly>
</#compress>