Skip to content
ebachta edited this page Sep 6, 2012 · 4 revisions

Adding new field type example: Geofield

This page demonstrates the front end process of mapping a third-party field to TourML that is provided by the Drupal module, Geofield. Developers can refer to the code as an example of how to do this for other third-party fields.

We are going to be adding a geolocation field to our stop type and mapping it to Drupal. Start by ensuring that the TAP Geo module is installed. Then add a field to the "Image Gallery Stop" content type we have been using in our examples. Navigate to "Admin -> Structure -> Content types -> Image Gallery Stop -> Manage fields". Under "Add new field" enter "Location" for "Label", "field_geo" for the field machine name, select "Geofield" as the field type, and finally select "OpenLayers Map" as the widget type.


In the edit screen of the field you may enter "Help text" and be sure that the "OpenLayers Map" setting is set to "Geofield Widget Map". Leave "Number of values" as "1". Once done, click "Save settings".


You should now see your new "Location" field in the list of fields on the Image Gallery Stop content type. You can reorder the fields to your liking. Your screen should now look similar to the one below.


Now we'll go ahead and configure the displays for our new field. Click on the "Manage display" tab on the top of content type edit screen. For the "Default" display set the format to "OpenLayers" and save your settings. Now revisit the options for your format of the "Location" field. Set "Data options" to "Use full geometry" and "Openlayers Map" to "Geofield Formatter Map". Click "Save" again. Your screen should now look like the one below.


While we are here we can go ahead and configure the "TourML XML" display. Drag the "Location" field out of the hidden group and set its format to "TourML Asset". Code is already provided with TAP that knows how to properly map a Geofield to TourML. Click "Save".


Let's now go to a node that is of type "Image Gallery Stop" and edit its content. You will notice that you have a zoomable and pannable map that you can use to create geolocation information. In the example below I have added a few points that would represent where my images were taken from for this gallery of images. Once done, click "Save".


If you view the node's contents you will see your map information. The map automatically sets a proper zoom and bounding box to show your geolocation information.


Clicking the "TourML XML" tab reveals that the Geofield has also been mapped to TourML properly, making it accessible to applications that use it. Notice that our mapping of the Geofield also provides some useful properties for our applications to use, the centroid and bounding box of the geolocation information. Front end applications now do not have to take on the task of calculating this on their own in order to set the initial zoom and position of a viewing map.


If a field type provided by a third-party module has been implemented in order to map to TourML, that's all it takes for front-end content authors to map add this information to TourML.

Clone this wiki locally