Geomajas Community Documentation

12.3.1. Map configuration

A map is a client side object. The Geomajas back-end works almost exclusively on layers.[1]On the client side however, these layers are combined into maps. In general, the back-end never needs to know which map the layer is displayed in when doing its work. However the back-end does need to know the coordinate reference system which is used.

<bean name="sampleFeaturesMap" class="org.geomajas.configuration.client.ClientMapInfo">
    <property name="crs" value="EPSG:4326" />
    <property name="displayUnitType" value="CRS" />
    <property name="initialBounds">
        <bean class="org.geomajas.geometry.Bbox">
            <property name="x" value="-180"/>
            <property name="y" value="-90"/>
            <property name="width" value="360"/>
            <property name="height" value="180"/>
        </bean>
    </property>
    <property name="layers">
        <list>
            <ref bean="wmsLayer" />
            <ref bean="countries110mLayer" />
        </list>
    </property>

Example 12.5. Client map configuration


The crs evidently refers to the map's coordinate reference system. The display unit type determines the unit type of the scale bar (METRIC, ENGLISH or CRS). The initial bounds determine the visible area of the map at startup time. The layers refers to the client layer info objects, not the server layer info or layer instances.

Additionally, a lot of style information can be included in the map configuration. This includes information like background colour, styles which should be used for selected points, lines and polygons and whether scale bare or pan buttons should be enabled.

<property name="backgroundColor" value="#F0F0F0" />
<property name="lineSelectStyle">
    <bean class="org.geomajas.configuration.FeatureStyleInfo">
        <property name="fillOpacity" value="0" />
        <property name="strokeColor" value="#FF6600" />
        <property name="strokeOpacity" value="1" />
    </bean>
</property>
<property name="pointSelectStyle">
    <bean class="org.geomajas.configuration.FeatureStyleInfo">
        <property name="fillColor" value="#FFFF00" />
    </bean>
</property>
<property name="polygonSelectStyle">
    <bean class="org.geomajas.configuration.FeatureStyleInfo">
        <property name="fillColor" value="#FFFF00" />
        <property name="fillOpacity" value=".5" />
    </bean>
</property>
<property name="scaleBarEnabled" value="true" />
<property name="panButtonsEnabled" value="true" />

Example 12.6. Client map configuration


An other important aspect of the map is the scale configuration. The scale configuration allows to define a maximum scale beyond which the user is not allowed to zoom in. This is not needed for zooming out as there is always a maximum bounds defined for the map (either explicitly or calculated as the union of the layer bounds). Next to that you can define a list of zoom levels. By default, the map will allow zooming to arbitrary scale levels but you may wish to enforce certain scale or zoom levels upon the user (like Google Maps does). By doing so, continuous zooming will no longer be possible and any zooming action will "snap" to the predefined scale levels.

<property name="scaleConfiguration">
    <bean class="org.geomajas.configuration.client.ScaleConfigurationInfo">
        <property name="maximumScale" value="1:1000" />
        <property name="zoomLevels">
            <list>
                <value>1:128000000</value>
                <value>1:64000000</value>
                <value>1:32000000</value>
                <value>1:16000000</value>
                <value>1:8000000</value>
                <value>1:4000000</value>
                <value>1:2000000</value>
                <value>1:1000000</value>
                <value>1:500000</value>
                <value>1:100000</value>
                <value>1:25000</value>
                <value>1:15000</value>
                <value>1:10000</value>
                <value>1:5000</value>
                <value>1:2500</value>
                <value>1:1000</value>
            </list>
        </property>
    </bean>
</property>

Example 12.7. Client map configuration - scale configuration


Scales can be defined in 2 possible notations:

  • the 1 : x notation (see the above listing) is most commonly used in geographics and expresses the ratio between 1 meter on the screen and 1 meter on the earth's sphere

  • the floating point notation (e.g. 0.0001) is used by us to express the number of pixels on the screen that correspond to 1 unit on the map (1 pixel per 10000 map units in our example)

Both scale definitions serve a different purpose. The 1 : x scale should give you an idea of what the true scale is at which the map is shown, although in practice this may depend on the DPI (actually PPI) and pixel size of your device. The floating point scale (which has units of pixel/m or pixel/deegree) is used to precisely define the resolution of raster images on the screen. If you use floating point notation, you can make sure that the scales that are being used in an application are the same as those of the raster layer(s) that lies beneath (see raster layer configuration). Otherwise the raster images may get blurry or unreadable when they need to be resized.

A map typically also contains a tool bar. If you want one, you have to specify the tools it should include.

<property name="toolbar">
    <bean name="sampleFeaturesMapToolbar" class="org.geomajas.configuration.client.ClientToolbarInfo">
        <property name="tools">
            <list>
                <ref bean="ZoomIn" />
                <ref bean="ZoomOut" />
                <ref bean="ZoomToRectangleMode" />
                <ref bean="PanMode" />
                <ref bean="ToolbarSeparator" />
                <ref bean="ZoomPrevious" />
                <ref bean="ZoomNext" />
                <ref bean="ToolbarSeparator" />
                <ref bean="EditMode" />
                <ref bean="MeasureDistanceMode" />
                <ref bean="SelectionMode" />
            </list>
        </property>
    </bean>
</property>

Example 12.8. Client map configuration


Obviously the tools themselves need to be defined as well. You can pass some parameters to the tools. An example tool definition look like this.

<bean name="ZoomIn" class="org.geomajas.configuration.client.ClientToolInfo">
    <property name="parameters">
        <list>
            <bean class="org.geomajas.configuration.Parameter">
                <property name="name" value="delta" />
                <property name="value" value="2" />
            </bean>
        </list>
    </property>
</bean>

Example 12.9. Tool configuration


Note that the tool id and the names of the parameters are interpreted by the client, so it is the client face which defines the possible values.

Last but not least, you can also configure the layer tree component which may be connected to the map.

    <property name="layerTree">
        <bean name="sampleFeaturesTree" class="org.geomajas.configuration.client.ClientLayerTreeInfo">
            <property name="tools">
                <list>
                    <ref bean="LayerVisibleTool" />
                    <ref bean="LayerLabeledTool" />
                    <ref bean="ShowTableAction" />
                    <ref bean="LayerRefreshAction" />
                </list>
            </property>
            <property name="treeNode">
                <bean class="org.geomajas.configuration.client.ClientLayerTreeNodeInfo">
                    <property name="label" value="Layers" />
                    <property name="layers">
                        <list>
                            <ref bean="wmsLayer" />
                            <ref bean="countries110mLayer" />
                        </list>
                    </property>
                    <property name="expanded" value="true" />
                </bean>
            </property>
        </bean>
    </property>
</bean>

Example 12.10. Client map configuration


This defines the tools which are available in the layer tree widget, and the tree of layers (as a node, which can contain a list of nodes etc).

Note that the layers are indicated by referring to the client configuration object.



[1] The only current exception is the printing command which converts maps to PDF document. Clearly this also uses the map configuration.