Lets assume you have a document and you want to attach a location to that document. For the sake of an example we'll pick landmarks. The Landmark document type will have parts :
and fields :
Now instead of having to figure out the latitude and longitude of the location we just want to use a map to pin point the location on. Enter the idea of a google maps field editor.
Here is a screenshot of what will be created.
| Click to enlarge |
Download the sample files here:
The xml and xsl files should be put under <wikidata directory>/resources/fieldeditors/
The java file should be compiled, and made available via a jar file under <daisy home>/daisy/webapp/WEB-INF/lib.
The instructions in the README.txt will install Daisy and deploy everything needed to let you experiment with the Google Map Field Editor.
This field will have to contain a number of different values :
We want to store these 3 values in one field since we are talking about one concept, a location, which just happens to fall apart into a number of other primitives. Also a field editor can only handle one field. To solve this we will turn to the hierarchical fields. The position in the 'hierarchy' will thus carry a meaning : 0. latitude, 1. longitude 2. zoom. Since this will all be stored in one field we will store all three values as doubles.
To summarize GmapLocation will be a hierarchical field type of doubles.
We will start of by configuring our editor. Here we will define which class drives the editor and pass a few parameters :
The field editor configuration can be found in the sample project under daisy-main/src/main/dsy-wiki/resources/fieldeditors/GmapLocation.xml
This class extends the AbstractFieldEditor and overrides a number of methods. To compile this class you must have the following classes in your classpath (these can be found in <daisy wiki home>/webapp/WEB-INF/lib)
The field editor class can be found in the sample project under daisywiki-extensions/src/main/java/com/example/gmapdemo/GoogleMapFieldEditor.java
This is a blurb of cforms definition xml that will be inserted into the grand form of the field editor tab. Here we don't use base type 'double' but 'string' since the representation of the hierarchy is not a double but a string.
The form definition can be found in the sample project under daisy-main/src/main/dsy-wiki/resources/fieldeditors/gmaplocation_definition.xsl.
In this template the field where the actual hierarchical value goes is hidden and a google map is shown in it's stead. The map is centered on the default location when there is no value in the GmapLocation field. If there is one then the map will be centered there.
The form template can be found in the sample project under daisy-main/src/main/dsy-wiki/resources/fieldeditors/gmaplocation_template.xsl.
| Name | Value |
|---|---|
| Category | Frontend (wiki) tutorials & extensions |