application.xml

The application.xml file defines all the LayerModelFactories and also references to other xml files needed for the configuration of a Geomajas application. The LayerModelFactories are factories on the server that are able to create a LayerModel. A LayerModel in turn is, as the name reveals, the model behind a layer. They must also be able to serve as a datasource, and therefore often need connection parameters in their configuration. Geomajas is packaged with different kinds of these LayerModelFactories. Examples are factories for Shape files, WKT, Hibernate, GeoTools and so on. We have divided the LayerModels into 2 kinds: vector and raster models. This is done because both operate and behave very differently.

 

Vector models

First up are the vector based layer models factories. They are defined by the 'layerModelFactory'-tag and an id attribute. The id is needed later when we refer to these factories in the definition of a FeatureType in a layer (in order for the layer to know where to get it's data).

 

Shape files

First up is the a factory for creating LayerModels, stored in memory, from a single shapefile. It only needs one connection parameter: the location of the file.

 

<layerModelFactory id="townShape">
    <factoryClass>ShapeInMemLayerModelFactory</factoryClass>
    <parameterMap>
        <parameter name="url" value="file:shapes/towns.shp"  />
    </parameterMap>
</layerModelFactory>

 

Hibernate

Next up is the HibernateLayerModelFactory. In complex applications, this one is the most important, because it allows the user to define complex mappings, easily implement business logic and so forth. It uses hibernate-spatial to accomplish this, and therefore supports PostGIS and Oracle at the time of writing (hibernate-spatial-1.0-M1). This factory does not need connection parameters because hibernate uses it's own configuration file (hibernate.cfg.xml). When using the hibernare layermodel factory, always make sure that the hibernate configuration file is correct.

<layerModelFactory id="hibernate">
    <factoryClass>HibernateLayerModelFactory</factoryClass>
    <parameterMap  />
</layerModelFactory>

 

Geotools

Another implementation of the LayerModelFactory interface creates LayerModels that actually use Geotools datastores behind the scenes. This in turn means that any type of data that can be retrieved by or through geotools can be fetched with these LayerModels as well. This also means that configuration of the factory (i.e. the connection parameters) are exactly the same as those geotools uses, because they are simply passed to the geotools datastorefinder. By using geotools, we can support shapefiles, databases, WFS and so on. Below is an example of a parametermap that will automatically determine the underlying datasource is a PostGIS database. (geotools determines this by which parameters are used)

<layerModelFactory id="postgis">
    <factoryClass>GeotoolsLayerModelFactory</factoryClass>
    <parameterMap>
        <parameter value="postgis" name="namespace"  />
        <parameter value="some_user_name" name="user"  />
        <parameter value="geomajas" name="database"  />
        <parameter value="some_password" name="passwd"  />
        <parameter value="localhost" name="host"  />
        <parameter value="5432" name="port"  />
        <parameter value="postgis" name="dbtype"  />
    </parameterMap>
</layerModelFactory>

 

Well known text

As one of the simpler examples now show the WKT layer model. As you can see in the example below, it does not need any connection parameters. This is the most simple of all.

<layerModelFactory id="wkt">
    <factoryClass>WKTLayerModelFactory</factoryClass>
    <parameterMap  />
</layerModelFactory>

 

Raster models

As a second type of LayerModelFactories we now have the rasterlayermodelfactories. Notice that main tag for a factory is now 'rasterLayerFactory', instead of 'layerModelFactory' !

Google

As a first example of rasters that Geomajas can use to create a layer, we present google. Google differs from your standard WMS server, and we therefore needed a different model and factory.

<rasterLayerFactory id="google">
    <factoryClass>GoogleLayerFactory</factoryClass>
    <parameterMap  />
</rasterLayerFactory>

 

WMS

The second option is to use a WMS server to fetch your raster-images from. This factory requires some preset connection parameters. baseWMSurl: The base url to the WMS service. From this base url, the LayerModel knows how to create the complex urls needed for fetching specific data from a WMS server. version: The version of the WMS protocol you want to use. format: The preferred image format. srs: The standard coordinate system used for fetching images from this WMS service.

<rasterLayerFactory id="someWMS">
    <factoryClass>WMSLayerFactory</factoryClass>
    <parameterMap>
        <parameter value="http://some.wms.org/wms.aspx" name="baseWMSurl"  />
        <parameter value="1.1.1" name="version"  />
        <parameter value="image/gif" name="format"  />
        <parameter value="EPSG:31300" name="srs"  />
    </parameterMap>
</rasterLayerFactory>

 

Open Street Maps

Analogous to the specific Google implementation, there is a specific RasterLayerFactory for Open Street Maps.

<rasterLayerFactory id="osm">
    <factoryClass>OSMLayerFactory</factoryClass>
    <parameterMap  />
</rasterLayerFactory>

 

Example

The application.xml contains more then just factories for vector and raster layers. Before we even get to these factories, we must first define 2 other parameters: url: This parameter contains a string with the name of the directory in which this application.xml can be found. In the example below we see as value: 'demo'. This means that this xml file can be found under /applications/demo/application.xml. Geomajas will always look for it's applications under the 'applications' directory under the webapp root. name: This is the full name of the application in question. On the server nothing is done with this parameter, be it is sent to the client along with most of the configuration. At the bottom of the application.xml there are references to other xml files. Each of these contain different parts of the Geomajas configuration. In what follows we will assume that the names of these files have not been altered.

<?xml version="1.0" encoding="UTF-8"?>
<applicationConfig xmlns="http://geomajas.org/schemas/configuration/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:ns2="http://www.w3.org/1999/xhtml"
        xmlns:ns="http://www.geomajas.org/schema/configuration/"
	xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty"
        xmlns:xi="http://www.w3.org/2001/XInclude"
	xsi:schemaLocation="http://geomajas.org/schemas/configuration/
        file://geomajas-application.xsd ">

 <url>demo</url>
 <name>demo application</name>

 <layerModelFactory id="structShape">
 	<factoryClass>ShapeInMemLayerModelFactory</factoryClass>
 	<parameterMap>
 		<parameter name="url" value="file:shapes/strucnet_p.shp"  />
 	</parameterMap>
 </layerModelFactory>

 <layerModelFactory id="hibernate">
 	<factoryClass>HibernateLayerModelFactory</factoryClass>
 	<parameterMap  />
 </layerModelFactory>
 <rasterLayerFactory id="google">
	 <factoryClass>GoogleLayerFactory</factoryClass>
	 <parameterMap  />
 </rasterLayerFactory>

 <xi:include href="layerTree.xml"  />

 <xi:include href="maps.xml"  />

 <xi:include href="toolbar.xml"  />

 <xi:include href="tools.xml"  />

</applicationConfig>