Skip to content

Commit 36b977f

Browse files
authored
feat(#305): support select one from map (#491)
- Engine support: Exposes geometry and other properties as one array of [string, string] to preserve order when displayed. - Rank and select share the same interface for their options, since they use the same XML element. - The support is only for ItemSets; regular Items don't have additional properties. - Front-end support: Using OpenLayers, loading async since it's a big bundle. - Front-end handles the options and builds a structure that works with OpenLayers. - It's structured with smaller components for possible reusability with geo shape / trace in the future.
1 parent 60241c7 commit 36b977f

File tree

28 files changed

+1822
-222
lines changed

28 files changed

+1822
-222
lines changed

.changeset/four-steaks-try.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@getodk/xforms-engine': minor
3+
'@getodk/web-forms': minor
4+
'@getodk/scenario': patch
5+
'@getodk/common': patch
6+
---
7+
8+
Support select one from map
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name,label,geometry,population_size,num_hospitals
2+
1,Lisbon,38.7 -9.15,500000,120
3+
2,Dublin,53.33 -6.25,1200000,200
4+
3,Edinburgh,55.953251 -3.188267,500000,150
5+
4,Amsterdam-Brussels-Luxembourg,52.37 4.9; 50.85 4.35; 49.6 6.13,3000000,450
6+
5,Zurich-Geneva-Basel,47.3667 8.55; 46.2022 6.1457; 47.55839 7.57327,1500000,300
7+
6,Barcelona-Madrid,41.390205 2.154007; 40.38 -3.7,5000000,600
8+
7,London-Paris-Amsterdam-London,51.5 -0.12; 48.85 2.35; 52.37 4.9; 51.5 -0.12,20000000,1000
9+
8,Berlin-Frankfurt-Munich-Berlin,52.52 13.4; 50.11552 8.68417; 48.13743 11.57549; 52.52 13.4,7000000,800
10+
9,Vienna-Salzburg-Innsbruck-Vienna,48.2 16.37; 47.79941 13.04399; 47.26266 11.39454; 48.2 16.37,3000000,400
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"geometry": {
7+
"type": "Point",
8+
"coordinates": [
9+
-73.56,
10+
45.52
11+
]
12+
},
13+
"properties": {
14+
"nurses": 19,
15+
"doctors": 10,
16+
"patients": 390,
17+
"id": "fea-07",
18+
"title": "Chinatown Medical Center"
19+
}
20+
},
21+
{
22+
"type": "Feature",
23+
"geometry": {
24+
"type": "Point",
25+
"coordinates": [
26+
-73.585,
27+
45.5
28+
]
29+
},
30+
"properties": {
31+
"nurses": 23,
32+
"doctors": 13,
33+
"patients": 550,
34+
"id": "fea-08",
35+
"title": "West End Health Clinic"
36+
}
37+
},
38+
{
39+
"type": "Feature",
40+
"geometry": {
41+
"type": "Point",
42+
"coordinates": [
43+
-73.555,
44+
45.485
45+
]
46+
},
47+
"properties": {
48+
"nurses": 16,
49+
"doctors": 6,
50+
"patients": 300,
51+
"id": "fea-09",
52+
"title": "Verdun Community Clinic"
53+
}
54+
},
55+
{
56+
"type": "Feature",
57+
"geometry": {
58+
"type": "LineString",
59+
"coordinates": [
60+
[
61+
-73.59,
62+
45.53
63+
],
64+
[
65+
-73.58,
66+
45.53
67+
],
68+
[
69+
-73.57,
70+
45.53
71+
]
72+
]
73+
},
74+
"properties": {
75+
"id": "fea-018",
76+
"title": "Canada Goose",
77+
"quantities": 4000,
78+
"migration_days": 12,
79+
"start_date": "2024-09-10",
80+
"end_date": "2024-09-22"
81+
}
82+
},
83+
{
84+
"type": "Feature",
85+
"geometry": {
86+
"type": "LineString",
87+
"coordinates": [
88+
[
89+
-73.59,
90+
45.47
91+
],
92+
[
93+
-73.58,
94+
45.47
95+
],
96+
[
97+
-73.57,
98+
45.47
99+
]
100+
]
101+
},
102+
"properties": {
103+
"id": "fea-019",
104+
"title": "Snowy Owl",
105+
"quantities": 150,
106+
"migration_days": 8,
107+
"start_date": "2024-11-15",
108+
"end_date": "2024-11-23"
109+
}
110+
},
111+
{
112+
"type": "Feature",
113+
"geometry": {
114+
"type": "LineString",
115+
"coordinates": [
116+
[
117+
-73.6,
118+
45.5
119+
],
120+
[
121+
-73.6,
122+
45.51
123+
],
124+
[
125+
-73.6,
126+
45.52
127+
]
128+
]
129+
},
130+
"properties": {
131+
"id": "fea-020",
132+
"title": "Peregrine Falcon",
133+
"quantities": 300,
134+
"migration_days": 5,
135+
"start_date": "2024-10-01",
136+
"end_date": "2024-10-06"
137+
}
138+
},
139+
{
140+
"type": "Feature",
141+
"geometry": {
142+
"type": "Polygon",
143+
"coordinates": [
144+
[
145+
[
146+
-73.59,
147+
45.54
148+
],
149+
[
150+
-73.58,
151+
45.54
152+
],
153+
[
154+
-73.58,
155+
45.55
156+
],
157+
[
158+
-73.59,
159+
45.55
160+
],
161+
[
162+
-73.59,
163+
45.54
164+
]
165+
]
166+
]
167+
},
168+
"properties": {
169+
"id": "fea-021",
170+
"title": "Montreal Urban Farm 1",
171+
"size": "200 hectares",
172+
"harvest_quantity": "400 tons",
173+
"harvest_date": "2024-09-05"
174+
}
175+
},
176+
{
177+
"type": "Feature",
178+
"geometry": {
179+
"type": "Polygon",
180+
"coordinates": [
181+
[
182+
[
183+
-73.61,
184+
45.46
185+
],
186+
[
187+
-73.6,
188+
45.46
189+
],
190+
[
191+
-73.6,
192+
45.47
193+
],
194+
[
195+
-73.61,
196+
45.47
197+
],
198+
[
199+
-73.61,
200+
45.46
201+
]
202+
]
203+
]
204+
},
205+
"properties": {
206+
"id": "fea-022",
207+
"title": "Montreal Urban Farm 2",
208+
"size": "150 hectares",
209+
"harvest_quantity": "300 tons",
210+
"harvest_date": "2024-10-10"
211+
}
212+
},
213+
{
214+
"type": "Feature",
215+
"geometry": {
216+
"type": "Polygon",
217+
"coordinates": [
218+
[
219+
[
220+
-73.54,
221+
45.53
222+
],
223+
[
224+
-73.53,
225+
45.53
226+
],
227+
[
228+
-73.53,
229+
45.54
230+
],
231+
[
232+
-73.54,
233+
45.54
234+
],
235+
[
236+
-73.54,
237+
45.53
238+
]
239+
]
240+
]
241+
},
242+
"properties": {
243+
"id": "fea-023",
244+
"title": "Montreal Urban Farm 3",
245+
"size": "250 hectares",
246+
"harvest_quantity": "500 tons",
247+
"harvest_date": "2024-08-15"
248+
}
249+
}
250+
]
251+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0"?>
2+
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml"
3+
xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4+
xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms"
5+
xmlns:odk="http://www.opendatakit.org/xforms">
6+
<h:head>
7+
<h:title>select-one-from-map-external-files</h:title>
8+
<model odk:xforms-version="1.0.0">
9+
<instance>
10+
<data id="select-one-from-map-external-files">
11+
<show_q1/>
12+
<q1/>
13+
<disable_q2/>
14+
<q2/>
15+
<q3/>
16+
<meta>
17+
<instanceID/>
18+
</meta>
19+
</data>
20+
</instance>
21+
<instance id="geodataGeoJson" src="jr://file/geodataGeoJson.geojson"/>
22+
<instance id="geodataCsv" src="jr://file-csv/geodataCsv.csv"/>
23+
<instance id="geodataXml">
24+
<root>
25+
<item>
26+
<name>1</name>
27+
<label>Madrid</label>
28+
<geometry>40.446254412914385 -3.7445467750577563</geometry>
29+
</item>
30+
<item>
31+
<name>2</name>
32+
<label>Warsaw</label>
33+
<geometry>52.18544754541023 21.1006145352125</geometry>
34+
</item>
35+
<item>
36+
<name>3</name>
37+
<label>Stockholm-Copenhagen-Berlin</label>
38+
<geometry>59.31284185390564 18.04203801493341; 55.7237702447557 12.59922155107742; 52.48574101841746
39+
13.337427033540052
40+
</geometry>
41+
</item>
42+
<item>
43+
<name>4</name>
44+
<label>Prague-Vienna-Budapest</label>
45+
<geometry>47.485570717616696 19.04921763281365; 48.19954394662233 16.42105774490628; 50.139932923435055
46+
14.417694964430638
47+
</geometry>
48+
</item>
49+
<item>
50+
<name>5</name>
51+
<label>London-Leeds-Liverpool-London</label>
52+
<geometry>53.40903732686215 -2.991905620523312; 51.505094241512666 -0.1321803079139272; 53.8052722823615
53+
-1.5363611594108022; 53.40903732686215 -2.991905620523312
54+
</geometry>
55+
</item>
56+
<item>
57+
<name>6</name>
58+
<label>Paris-Basel-Frankfurt-Paris</label>
59+
<geometry>48.840915452897946 2.3146557958955327; 47.54579786412256 7.63542665300713; 50.10149750150822
60+
8.703168961933983; 48.840915452897946 2.3146557958955327
61+
</geometry>
62+
</item>
63+
</root>
64+
</instance>
65+
<bind nodeset="/data/show_q1" type="string"/>
66+
<bind nodeset="/data/q1" type="string" relevant="selected(/data/show_q1, 'yes')"/>
67+
<bind nodeset="/data/disable_q2" type="string"/>
68+
<bind nodeset="/data/q2" type="string" readonly="selected(/data/disable_q2, 'yes')"/>
69+
<bind nodeset="/data/q3" type="string"/>
70+
<bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid"/>
71+
</model>
72+
</h:head>
73+
74+
<h:body>
75+
<select1 ref="/data/show_q1">
76+
<label>Do you want to show the select with geojson file?</label>
77+
<item>
78+
<value>yes</value>
79+
<label>Yes</label>
80+
</item>
81+
<item>
82+
<value>no</value>
83+
<label>No</label>
84+
</item>
85+
</select1>
86+
87+
<select1 ref="/data/q1" appearance="map">
88+
<label>Select one from geojson file</label>
89+
<itemset nodeset="instance('geodataGeoJson')/root/item">
90+
<value ref="id"/>
91+
<label ref="title"/>
92+
</itemset>
93+
</select1>
94+
95+
96+
<select1 ref="/data/disable_q2">
97+
<label>Do you want to disable the select with csv file?</label>
98+
<item>
99+
<value>yes</value>
100+
<label>Yes</label>
101+
</item>
102+
<item>
103+
<value>no</value>
104+
<label>No</label>
105+
</item>
106+
</select1>
107+
108+
<select1 ref="/data/q2" appearance="map">
109+
<label>Select one from csv file</label>
110+
<itemset nodeset="instance('geodataCsv')/root/item">
111+
<value ref="name"/>
112+
<label ref="label"/>
113+
</itemset>
114+
</select1>
115+
116+
<select1 ref="/data/q3" appearance="map">
117+
<label>Select one from xml file</label>
118+
<itemset nodeset="instance('geodataXml')/root/item[true()]">
119+
<value ref="name"/>
120+
<label ref="label"/>
121+
</itemset>
122+
</select1>
123+
</h:body>
124+
</h:html>

0 commit comments

Comments
 (0)