Geomajas Google layer plug-in

Geomajas Developers and Geosparc


Table of Contents

1. Introduction
2. Configuration
1. Dependencies
2. Google raster layer
2.1. Base configuration
2.2. Image source configuration
2.3. Zoom level configuration
3. Using the Google map add-on

List of Figures

1.1. Google layer formats, normal, satellite and hybrid

List of Tables

2.1. GoogleLayer image type configuration

List of Examples

2.1. Google layer dependency, using geomajas-project-server in dependency management
2.2. Google layer dependency, explicit version
2.3. Simple Google layer configuration
2.4. Google layer configuration
2.5. Configure to use satellite images and
2.6. Configure to use satellite images
2.7. Using custom URLs
2.8. Using a custom URL selection
2.9. Google layer max zoom level
2.10. Using the GoogleAddon

Chapter 1. Introduction

The Google layer allows you to use Google maps imagery as a raster layer in Geomajas. There are three possible types of images which can be displayed: the normal view displays street data, satellite view displays satellite images and physical view displays a hybrid of street and elevation information.

Figure 1.1. Google layer formats, normal, satellite and hybrid

Google layer formats, normal, satellite and hybrid


Use of the Google Maps images is subject to Googles terms of use. For details, check with Google, though the following URLs may help you and

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 versions, include following dependency to your pom:

Example 2.1. Google 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. Google layer dependency, explicit version


For using these functionalities in GWT client, see the specific client documentation.

2. Google raster layer

2.1. Base configuration


When using the Google layer, it is your responsibility to comply with the Google's terms of use. Some sources of information about these terms include, and Some of the things you need to do include adding the Google API code in your application (using a Google API key when not running on localhost), and (from the GWT face), using the GoogleAddon class to assure the copyright notices are displayed on the map.

A base Google layer configuration looks as follows:

Example 2.3. Simple Google layer configuration

<bean name="google" class="">
    <property name="tilesEnabled" value="true" />
    <property name="apiKey" value="" />


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. Google layer configuration

    <bean name="layerGoogle" class="">
        <property name="tilesEnabled" value="true" />
        <property name="layerInfo" ref="layerGoogleInfo" />
        <property name="satellite" value="false" />
        <property name="maxZoomLevel" value="21" />

    <bean name="layerGoogleInfo" class="org.geomajas.configuration.RasterLayerInfo">
        <property name="crs" value="EPSG:900913" />
        <property name="maxExtent">
            <bean class="org.geomajas.geometry.Bbox">
                <!-- see 
                    -20037508.342789, -20037508.342789 to 20037508.342789, 20037508.342789 -->
                <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="tileHeight" value="640" />
        <property name="tileWidth" value="640" />

Note that these older versions do not allow all of the other configurations.

You can add some properties to define the kind of images which are produced. By default, the layer displays road information, but this can be changed to either satellite or physical (roads+elevation) imagery. The view style modes are exclusive, last set will be valid

Table 2.1. GoogleLayer image type configuration

GoogleLayer configuration 
satelliteSet to true to use satellite view from Google. When this and physical are false (the default), the normal view (showing streets) will be used. Setting to true will reset physical to false.
physicalSet to true to use physical view from Google. When this and satellite are false, the normal view (showing streets) will be used. Setting to true will reset satellite to false.
maxZoomLevelSet to a number for which maps are available in the region of interest, defaults to 19. The first zoom level has one tile for the entire world, the second has four tiles etc.

These are used in the following configuration.

Example 2.5. Configure to use satellite images and

    increase max zoom level -->
<bean name="satellite" class="">
    <property name="tilesEnabled" value="true" />
    <property name="satellite" value="true" />
    <property name="maxZoomLevel" value="21" />
    <property name="apiKey" value="" />

Alternatively, you can also configure the display style using the dataSourceName property in the layer info. This is shown in the example below. However, it is preferred to use the properties on the layer itself. This can be useful for the dojo face, which uses this property to detect Google layers. Note that the suffix "@GoogleLayer" will automatically be added. Possible values are "G_NORMAL_MAP", "G_SATELLITE_MAP" and "G_PHYSICAL_MAP".

Example 2.6. Configure to use satellite images

    and increase max zoom level -->
<bean name="satelliteDs" class="">
    <property name="tilesEnabled" value="true" />
    <property name="layerInfo">
        <bean class="org.geomajas.configuration.RasterLayerInfo">
            <property name="dataSourceName" value="G_SATELLITE_MAP" />
            <property name="crs" value="EPSG:900913" /> <!-- required property -->
            <property name="tileHeight" value="640" />
            <property name="tileWidth" value="640" />
    <property name="apiKey" value="" />

2.2. Image source configuration

You can also force the set of URLs to choose from, as in the following example. Note that this may fail when setting the image type. You can define the different options using ${level}, ${x} and ${y} for the zoom level and tile coordinate. A simple configuration looks like this:

Example 2.7. Using custom URLs

<bean name="googleSingle" class="">
    <property name="tilesEnabled" value="true" />
    <property name="tileUrl"
        value="${center}&amp;zoom=${level}" />
    <property name="apiKey" value="" />

The Google layer allows configuration of the strategy to choose the server to provide the tiles. Each of the image types can be served from four servers. The default behaviour is to select the server using a round robin strategy.

The strategy can also be configured. For example, the sample below selects the class to use for the URL selection strategy (this needs to implement UrlSelectionStrategy).

Example 2.8. Using a custom URL selection

    strategy -->
<bean name="googleStrategy" class="">
    <property name="apiKey" value="" />

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.9. Google layer max zoom level

    configuration -->
<bean name="googleMaxLevel" class="">
    <property name="tilesEnabled" value="true" />
    <property name="maxZoomLevel" value="12" />
    <property name="apiKey" value="" />

3. Using the Google map add-on

To enable the display of copyright information on the map (to comply with Google's terms of use), you should use the GoogleAddon. This can be done using a line of code like:

Example 2.10. Using the GoogleAddon

    new GoogleAddon("google", map, GoogleAddon.MapType.SATELLITE, false));

This needs to be called on the MapWidget object. The first parameter is the DOM id for the object, the second the map widget itself, the third the type of imagery which needs to be used and the last indicates whether the Google map should be made visible.

Note that you will need to add the Google API key in your html source file to assure this can work (otherwise you will probably get an exception from Google when not accessing the page on localhost.