Table of Contents
List of Figures
List of Examples
The OpenStreetMap layer allows you to display OpenStreetMap imagery as raster layer in Geomajas.
This allows you to easily use the default rendering of the OpenStreetMap data. You can further configure it to choose different renderings.
Table of Contents
Make sure your include the plug-in in your project. If you are using Maven and the geomajas-dep dependency to manage versions, include following dependency to your pom:
Example 2.1. OpenStreetMap layer dependency, using geomajas-dep
<dependency> <groupId>org.geomajas.plugin</groupId> <artifactId>geomajas-layer-openstreetmap</artifactId> </dependency>
If you are not using geomajas-dep to manage versions, then you need to mention the version explicitly.
Example 2.2. OpenStreetMap layer dependency, explicit version
<dependency> <groupId>org.geomajas.plugin</groupId> <artifactId>geomajas-layer-openstreetmap</artifactId> <version>1.8.0</version </dependency>
A base OpenStreetMap layer configuration looks as follows:
Example 2.3. Simple OpenStreetMap layer configuration
<bean name="osm" class="org.geomajas.layer.osm.OsmLayer"/>
If you are using 1.7.1 or earlier of the OpenStreetMap plug-in then this configuration will not work. In that version we simplified configuration by not forcing you to configure values you are not allowed to change anyway. For the old version, the configuration would look like this:
Example 2.4. OpenStreetMap layer configuration example
<bean name="osmInfo" class="org.geomajas.configuration.RasterLayerInfo"> <property name="crs" value="EPSG:900913"/> <property name="maxExtent"> <bean class="org.geomajas.geometry.Bbox"> <property name="x" value="-20026376.393709917"/> <property name="y" value="-20026376.393709917"/> <property name="width" value="40052752.787419834"/> <property name="height" value="40052752.787419834"/> </bean> </property> <!--property name="resolutions"> <list> <value>156543.03</value> <value>78271.52</value> <value>39135.76</value> <value>19567.88</value> <value>9783.94</value> <value>4891.97</value> <value>2445.98</value> <value>1222.99</value> <value>611.49</value> <value>305.75</value> <value>152.874057</value> <value>76.4370283</value> <value>38.2185141</value> <value>19.1092571</value> <value>9.55462853</value> <value>4.77731427</value> <value>2.38865713</value> <value>1.19432857</value> </list> </property--> <property name="tileWidth" value="256"/> <property name="tileHeight" value="256"/> </bean> <bean name="osm" class="org.geomajas.layer.osm.OsmLayer" > <property name="layerInfo" ref="osmInfo" /> </bean>
Note that these older versions did not allow any of the other configurations either.
The default configuration for the OpenStreetMap layer will use the Mapnik rendering of OpenStreetMap by round robin iteration over the following base URLs:
http://a.tile.openstreetmap.org
http://b.tile.openstreetmap.org
http://c.tile.openstreetmap.org
This is configurable at two levels.
You can configure the URLs which are used for the tiles. You simply define the different options using ${level}, ${x} and ${y} for the zoom level and tile coordinate. A simple configuration looks like this:
Example 2.5. Using custom URLs
<bean name="osmSingle" class="org.geomajas.layer.osm.OsmLayer"> <property name="tileUrls"> <list> <value>http://a.tile.openstreetmap.org/${level}/${x}/${y}.png</value> </list> </property> </bean>
You can also define the strategy to choose between the different URLs which have been configured. By default, the URLs will be chosen using a round robin strategy.
For example, the sample below uses the cycle map tiles and selects the class to use for the URL selection strategy (this needs to implement UrlSelectionStrategy).
Example 2.6. Using a custom URL selection strategy
<bean name="osmCycleMap" class="org.geomajas.layer.osm.OsmLayer"> <property name="tileUrls"> <util:constant static-field="org.geomajas.layer.osm.OsmLayer.OPEN_CYCLE_MAP_URLS"/> </property> <property name="urlSelectionStrategy"> <bean class="org.geomajas.layer.osm.LastUrlSelectionStrategy" /> </property> </bean>
By default the maximum zoom level is 19, but this can be modified using the maxZoomLevel property if your data source supports a different level.
Example 2.7. OpenStreetMap layer max zoom level configuration
<bean name="osmMaxLevel" class="org.geomajas.layer.osm.OsmLayer"> <property name="maxZoomLevel" value="12"/> </bean>