<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:entities="http://www.opendatakit.org/xforms/entities" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<h:head>
		<h:title>Reference geometry demo</h:title>
		<model entities:entities-version="2024.1.0" odk:xforms-version="1.0.0">
			<instance>
				<data id="ref_geo_demo" version="20260527162709">
					<note/>
					<from_entities>
						<entities_note/>
						<shape/>
						<shape_label/>
					</from_entities>
					<repeats_note/>
					<from_repeat jr:template="">
						<geometry/>
					</from_repeat>
					<from_repeat>
						<geometry/>
					</from_repeat>
					<meta>
						<entity create="1" dataset="places" id="">
							<label/>
						</entity>
						<instanceID/>
					</meta>
				</data>
			</instance>

			<instance id="places" src="jr://file-csv/places.csv"/>

			<bind nodeset="/data/note" readonly="true()" type="string"/>
			<bind nodeset="/data/from_entities/entities_note" readonly="true()" type="string"/>
			<bind entities:saveto="geometry" nodeset="/data/from_entities/shape" type="geoshape" required="true()"/>
			<bind nodeset="/data/from_entities/shape_label" type="string" required="true()"/>
			<bind nodeset="/data/repeats_note" readonly="true()" type="string"/>
			<bind nodeset="/data/from_repeat/geometry" type="geotrace"/>
			<bind nodeset="/data/meta/entity/@id" readonly="true()" type="string"/>
			<setvalue event="odk-instance-first-load" ref="/data/meta/entity/@id" value="uuid()"/>
			<bind calculate=" /data/from_entities/shape_label " nodeset="/data/meta/entity/label" readonly="true()" type="string"/>
			<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/>
		</model>
	</h:head>
	<h:body>
		<input ref="/data/note">
			<label>This form demonstrates using existing geometry as context for capturing new shapes or traces.</label>
		</input>
		<group appearance="field-list" ref="/data/from_entities">
			<input ref="/data/from_entities/entities_note">
				<label>The question below lets you capture a new geoshape to the places Entity List and shows previously-captured geoshapes in the Entity List as reference.</label>
			</input>
			<input ref="/data/from_entities/shape">
				<label>Capture geoshape</label>
				  <itemset nodeset="instance('places')/root/item">
    				<value ref="name" />
    				<label ref="label" />
  				  </itemset>
			</input>
			<input ref="/data/from_entities/shape_label">
				<label>Give a name to the shape you just captured.</label>
			</input>
		</group>
		<input ref="/data/repeats_note">
			<label>Next, you'll see a geotrace question in a repeat. As you add traces, they will be shown as reference for the next traces captured.</label>
		</input>
		<group ref="/data/from_repeat">
			<label>Geotrace</label>
			<repeat appearance="field-list" nodeset="/data/from_repeat">
				<input ref="/data/from_repeat/geometry">
					<label>Capture geotrace</label>
					<itemset nodeset="../../from_repeat[geometry != '']">
						<value ref="geometry"/>
						<label ref="geometry"/>
					</itemset>
				</input>
			</repeat>
		</group>
	</h:body>
</h:html>