Geomajas OpenStreetMap layer plug-in

Geomajas Developers and Geosparc


Table of Contents

1. Introduction
2. Configuration
1. Dependencies
2. OpenStreetMap raster layer
2.1. Base configuration
2.2. Image source configuration
2.3. Zoom level configuration

List of Figures

1.1. OpenStreetMap example

List of Examples

2.1. OpenStreetMap layer dependency, using geomajas-project-server in dependency management
2.2. OpenStreetMap layer dependency, explicit version
2.3. Simple OpenStreetMap layer configuration
2.4. OpenStreetMap layer configuration example
2.5. Using custom URLs
2.6. Using a custom URL selection strategy
2.7. OpenStreetMap layer max zoom level configuration

Chapter 1. Introduction

The OpenStreetMap layer allows you to display OpenStreetMap imagery as raster layer in Geomajas.

Figure 1.1. OpenStreetMap example

OpenStreetMap example

This allows you to easily use the default rendering of the OpenStreetMap data. You can further configure it to choose different renderings.

Chapter 2. Configuration

1. Dependencies

Make sure your include the plug-in in your project. If you are using Maven and the geomajas-project-server dependency to manage version, include following dependency to your pom:

Example 2.1. OpenStreetMap layer dependency, using geomajas-project-server in dependency management


If you are not using geomajas-project-server in dependency management, then you need to mention the version explicitly.

Example 2.2. OpenStreetMap layer dependency, explicit version


2. OpenStreetMap raster layer

2.1. Base configuration

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="layerOsm" class="org.geomajas.layer.osm.OsmLayer" >
        <property name="layerInfo" ref="layerOsmInfo" />

    <bean name="layerOsmInfo" 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"/>
        <property name="tileWidth" value="256"/>
        <property name="tileHeight" value="256"/>

Note that these older versions did not allow any of the other configurations either.

2.2. Image source configuration

The default configuration for the OpenStreetMap layer will use the Mapnik rendering of OpenStreetMap by round robin iteration over the following base URLs:




This is configurable at two levels.

You can configure the URLs which are used for the tiles. You 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">

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 name="urlSelectionStrategy">
        <bean class="org.geomajas.layer.osm.LastUrlSelectionStrategy" />

2.3. Zoom level configuration

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"/>