html.master.html Maven / Gradle / Ivy
Geomajas WMS client plug-in guide Table of Contents
Table of Contents
This plugin provides client side TMS (TileMapService) support. It
provides a layer definition and it also defines services to interpret
TileMapService XML capabilities files.
This plugin contains multiple artifacts, that are listed below:
-
tms: The basic TMS client functionality. It
contains a TmsLayer and support for parsing TileMapService XML
capabilities files.
-
example-jar: Jar that contains showcase
examples.
-
documentation: This documentation.
Basic WMS client artifact:
<dependency>
<groupId>org.geomajas.plugin</groupId>
<artifactId>geomajas-client-gwt2-plugin-tms</artifactId>
<version>2.4.1</version>
</dependency>
Table of Contents
As most Geomajas plugins, the TMS client plugin too has a single
class that provides a starting point for most functionalities the plugin
supports. This starting point is the TmsClient
class:
org.geomajas.gwt2.plugin.tms.client.TmsClient
From here on it is possible to create new TMS layers or parse
TileMapService XML capabilities files, or ....
Before we go into the actual creating of a TMS layer, let us first
cover the required configuration objects.
The first is the
org.geomajas.gwt2.client.map.layer.tile.TileConfiguration
.
It provides the point of origin and the size of the tiles in
pixels:
-
tileOrigin: The origin for the layer
(coordinate that provides the minimum X and Y values). If you're
unsure, it's best to take a margin.
-
tileWidth: The width in pixels for an
individual tile.
-
tileHeight: The height in pixels for an
individual tile.
The other is the
org.geomajas.gwt2.plugin.tms.client.layer.TmsLayerConfiguration
object. It provides all the required parameters used in creating the
correct tile URLs. These are the following:
-
baseUrl: The base URL to the WMS server
(without any WMS params!)
-
fileExtension: The actual file extension
for the images (".png", ".jpg", ...).
Once you have your configuration objects (TileConfiguration and
TmsLayerConfiguration) it's easy to create a new layer:
// Defining a TMS configuration object:
TmsLayerConfiguration layerConfig = new TmsLayerConfiguration();
layerConfig.setFileExtension(".png");
layerConfig.setBaseUrl("http://apps.geomajas.org/geoserver/gwc/service/tms/1.0.0/demo_world%3Asimplified_country_borders@EPSG%3A4326@png");
// Then we define a Tile Configuration object:
Coordinate tileOrigin = new Coordinate(-360,-180);
TileConfiguration tileConfig = new TileConfiguration(256, 256, tileOrigin);
// Now create the layer:
TmsLayer tmsLayer = TmsClient.getInstance().createLayer("Countries", tileConfig, layerConfig);
Once you have your layer, it is possible to add it to the
map:
mapPresenter.getLayersModel().addLayer(tmsLayer);
Et voila! A newly created client-side TMS layer has been added to
the map!
As mentioned earlier, the TMS layer is build using a
TmsLayerConfiguration object, which is used internally to build the
correct URLs to the TileMap tiles. Should you change any of the
parameters in this configuration object, it's effects will take place
the next time tiles are fetched (or by refreshing the layer).
You can acquire the layer configuration objects from the layer
itself. The following example takes this configuration to change the
base URL to the layer, having it point to another TileMap:
TmsLayerConfiguration layerConfig = tmsLayer.getConfiguration();
layerConfig.setBaseUrl("something else...");
Ofcourse one does not always know beforehand which TMS layers to
add. Sometimes we need to ask a TileMapService for it's available
layers, and present the user with a choice. This can be achieved through
the TmsClient service, the result of which can than be used to create
TMS layers.
Parsing a TileMapService XML file will result in an object of the
type
org.geomajas.gwt2.plugin.tms.client.configuration.TileMapServiceInfo
.
This object contains a list of available TileMaps within the service.
Each TileMap can be used to create a TmsLayer:
String tmsBaseUrl = "/proxy?url=http://apps.geomajas.org/geoserver/gwc/service/tms/1.0.0";
TmsClient.getInstance().getTileMapService(TMS_BASE_URL, new Callback<TileMapServiceInfo, String>() {
@Override
public void onSuccess(TileMapServiceInfo result) {
for (final ListTileMapInfo listTileMapInfo : result.getTileMaps()) {
// Do something with the list of ListTileMapInfo objects...
}
}
@Override
public void onFailure(String reason) {
Window.alert("We're very sorry, but something went wrong: " + reason);
}
});
Parsing a TileMapService URL will result in a list of
org.geomajas.gwt2.plugin.tms.client.configuration.ListTileMapInfo
objects. Each of these objects in turn points to another URL that
describes the actual TileMap. In order to acquire the details regarding
such a TileMap, we must again fetch and parse the XML file at the target
URL. This time in order to acquire a
org.geomajas.gwt2.plugin.tms.client.configuration.TileMapInfo
object.
When the TileMapInfo
object is retrieved, this too
can be used to create a new TmsLayer
. The following
examples will fetch the TileMapInfo
object and immediately
create a layer from it:
String tileMapUrl = "/proxy?url=" + listTileMapInfo.getHref();
TmsClient.getInstance().getTileMap(tileMapUrl, new Callback<TileMapInfo, String>() {
@Override
public void onSuccess(TileMapInfo result) {
TmsLayer layer = TmsClient.getInstance().createLayer(result);
mapPresenter.getLayersModel().addLayer(layer);
}
@Override
public void onFailure(String reason) {
Window.alert("We're very sorry, but something went wrong: " + reason);
}
});