Table of Contents
List of Figures
List of Examples
Table of Contents
Documentation for developer who want to use and extend the Geomajas GIS framework.
Geomajas is a free and open source GIS application framework for building rich internet applications. It has sophisticated capabilities for displaying and managing geospatial information. The modular design makes it easily extendable. The stateless client-server architecture guarantees endless scalability. The focus of Geomajas is to provide a platform for server-side integration of geospatial data, allowing multiple users to control and manage the data from within their own browsers. In essence, Geomajas provides a set of powerful building blocks, from which the most complex GIS applications can easily be built. Key features include:
Modular architecture
Clearly defined API
Integrated client-server architecture
Built-in security
Advanced geometry and attribute editing with validation
Custom attribute definitions including object relations
Advanced querying capabilities (searching, filters, style, ...)
Copyright © 2009-2010 Geosparc nv.
Licensed under the GNU Affero General Public License. You may obtain a copy of the License at http://www.gnu.org/licenses/
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU Affero General Public License for more details.
The project also depends on various other open source projects which have their respective licenses.
From the Geomajas source (possibly specific module), the
dependencies can be displayed using the "mvn dependency:tree
"
command.
For the dependencies of the Geomajas back-end, we only allow dependencies which are freely distributable for commercial purposes (this for example excludes GPL and AGPL licensed dependencies).
This framework and documentation was written by the Geomajas Developers. If you have questions, found a bug or have enhancements, please contact us through the user fora at http://www.geomajas.org/.
List of contributors for this manual:
Pieter De Graef
Jan De Moerloose
Joachim Van der Auwera
Frank Wynants
Table of Contents
Geomajas uses the Apache Maven project management tool for its build and documentation process. Thanks to Maven , the easiest way to start using Geomajas is by creating a new project using the Maven archetype. This will create a simple working project that you can use as starting point.
As the simple project is created using the Maven archetype, you will need to install Maven on your system, which can be downloaded from http://maven.apache.org/. We recommend using the latest stable version (2.2.1 at the time of writing). Installing Maven is quite simple: just unzip the distribution file in the directory of your choice and make some environment changes so you can access the executable. More information for your specific OS can be found at the bottom of http://maven.apache.org/download.html.
At this point it is assumed that Maven has been successfully installed. Using Maven, you can now create a template project, called the Geomajas GWT Application Archetype.
Step1: Go to the folder you want to create this application in, and execute the following command:
Example 2.1. Create project using GWT Maven archetype
mvn archetype:generate -DarchetypeCatalog=http://files.geomajas.org/archetype-catalog.xml
This will create the template project, using the latest stable release. If you want to use the latest snapshot, use the following command instead:
Example 2.2. Create project using GWT Maven archetype
mvn archetype:generate -DarchetypeCatalog=http://files.geomajas.org/archetype-latest.xml
Maven will now prompt the user for input.
If anything fails with these maven commands, you need to check the output to check the problem. One typical problem is the need to define a proxy to allow maven to access sites in the outside world. See the http://maven.apache.org/guides/mini/guide-proxies.html for details.
Step2: Maven will display the full list of available archetypes. Make sure you select the correct one: geomajas-gwt-archetype. In the image below, the correct number would be 36:
Step3: Next maven asks for the groupId. Often the package name is used. (foo.bar)
Step4: Next maven asks for the artifactId. This represents the name for your application. (i.e. my-app)
Step5: Next maven asks for the first version for your application. 1.0-SNAPSHOT is a good first version.
Step6: Next maven asks for the base package wherein to place Java files. By default this is the same as the groupId. Just hit "enter" to continue.
You have now create a Geomajas template project! It is best to continue by testing if everything went well.
From the project root, you can immediately compile, test (using jetty as servlet container), or run the application in development mode using the following commands.
You now have several options to actually test your application. First of all, you could compile it, and create a build. This can be done using the following command:
The "install" target will create a .war file for the project in
the target
directory. This web archive can simply be
dropped into a Java application container such as Tomcat.
Secondly, if you don't have a Java application container ready or simply want a quick test, then you can use mvn to run the application for you, using the following commands:
The "jetty:run" variant will immediately start a jetty server and start the application. This way, you can test your application at full speed (as when deployed). The application can be accessed at http://localhost:8080/.
Another option is to start up the application in GWT development mode, using the following command lines:
The "gwt:run" option allows you to start the application in GWT
development mode. A console will appear which allows starting your
application (from the browser). Amongst other things, this allows you
to see the messages GWT generates and see the output of the
"GWT.log
" commands.
The combination of Eclipse, maven and GWT is not quite trivial, especially for complex multi-module projects like Geomajas. There are 2 approaches possible for integrating eclipse with maven:
Eclipse plug-in for maven, avoiding the use of the maven command-line interface: m2eclipse (http://m2eclipse.sonatype.org/) is the most mature project here
Maven plug-in to generate eclipse project configurations: maven-eclipse-plugin (http://maven.apache.org/plugins/maven-eclipse-plugin/)
It is clear that an IDE integrated solution like m2eclipse offers considerable advantages over manually generating Eclipse project configurations:
direct import of maven projects
support for maven properties and filtering
In-place editing of poms
full dependency support
For a functional Geomajas setup, the following Eclipse plug-ins should be installed on a fresh Galileo download (http://www.eclipse.org/downloads/):
m2eclipse: update site http://m2eclipse.sonatype.org/sites/m2e
m2eclipse extras (especially WTP extension): http://m2eclipse.sonatype.org/sites/m2e-extras
checkstyle: update site http://eclipse-cs.sf.net/update/
SVN team provider: update site http://download.eclipse.org/releases/helios, choose Collaboration ->Subversive SVN Team Provider (Incubation)
Google's GWT Eclipse plug-in: http://dl.google.com/eclipse/plugin/3.6 (Plugin and SDK)
There is a classpath issue with the Google Plug-in for Eclipse (GPE) that prevents us from using it in a reliable way when there are multiple versions of artifacts in the maven dependency tree: http://code.google.com/p/google-web-toolkit/issues/detail?id=5033
On top of that, GPE forces the use of the built-in jetty launcher, which has problems with loading libraries from the maven repository. Recent development by Google points in the direction of better maven support, but a as far as we know a stable solution which does not require explicit user interaction is not available. (see http://googlewebtoolkit.blogspot.com/2010/08/how-to-use-google-plugin-for-eclipse.html).
In view of these problems, the following workaround seems to be the most reliable way of using the GWT plugin for us:
Run the GWT plugin with the no-server option (this can be done straight from the project since GWT 2.1
Run an embedded Jetty server to replace the GWT server
The following series of steps have to be performed to achieve a working project.
Import the project as a maven project
After the project has been imported and the workspace has been built, you should now manually mark the project as a GWT project in the project properties dialog. Open the Google -> Web Toolkit section and mark the checkbox. If the eclipse GWT version differs from the project version, the "Use specific SDK" checkbox will be enabled:
In the Google -> Web Application section, the WAR directory should be changed to the default maven war sources directory (src/main/webapp)
Open the debug configurations dialog and create a new Java application:
Search for JettyRunner as the main class. JettyRunner is a specially prepared main class that starts up Jetty with the correct parameters (port 8888 and src/main/webapp as webapp directory)
Run the new Jetty server configuration (in debug mode):
Now, run the GWT plugin in no-server mode by by right-clicking on the project and selecting Debug As -> Web Application (running on an external server):
Click ok on the dialog screen
You can now add breakpoints and debug your application as if it was a normal Java application.
If you have multiple versions of GWT in your project workspace, make sure that the gwt-dev jar is in front of the default classpath (reported GWT issue):
If you want to run your application directly with GPE, some extra actions are needed to avoid classpath problems. You will have to change your web.xml by adding a special context listener that allows Spring component scanning and circumvents a GeoTools problem with the builtin Jetty classloader:
<listener> <listener-class>org.geomajas.servlet.PrepareScanningContextListener</listener-class> </listener>
This solves most of the classpath problems but does not cure the problem of having multiple artifact versions in the classpath! This is usually only a problem when you have several Geomajas projects opened in your workspace. If this is the case, run the GWT plugin with an embedded Jetty server as explained in the previous chapter and you should be fine. Note that this should be the first listener in your web.xm files, before the spring listeners.
The following steps are needed to run GPE directly:
Follow the configuration steps of the indirect mode, right up to the Jetty part
Run the project as a GWT Web application by right-clicking
on the project and selecting Run as -> Web
Application
.
For debugging, debug the project as a GWT Web application by
right-clicking on the project and selecting Debug as ->
Web Application
.
The setup in IntelliJ IDEA is quite straightforward and does not require running a separate Maven command. Just open the project from IDEA by selecting the pom in the root directory.
IDEA will recognize this as a GWT project and assign the correct facet but as always you will have to make your own run configuration (which is fortunately trivial). You will need version 9.0 or later for the GWT 2.0 support.
Before being able to use this configuration, you need to invoke the gwt:i18n Maven target to assure the files which are used for internationalisation are available (otherwise, you will get compilation errors). You can do this from the "Maven projects" tab.
Some additional settings have to be done in the "project structure" dialog. Apart from specifying the GWT installation directory, there is a specific project setting which has to be done manually, which is setting the target Web facet to "Web". The project structure for the simple GWT project should look as follows:
After this, you should be able to run the project. Any changes in the source code will be automatically detected, and debugging is possible.
You can both create the project from the archetype or open directly the Maven project in NetBeans. See http://wiki.netbeans.org/MavenBestPractices for more details.
The archetype generates a dependency on the geomajas-dep project to manage the version of the Geomajas dependencies. This project exists for the sole purpose of keeping track of the latest released versions. It is quite likely that a new version of geomajas-dep has been released since the latest release of the archetype. Therefore, we recommend you update this dependency to the latest version. You can check the latest version using this URL: http://apps.geomajas.org/nexus/index.html#nexus-search;quick~geomajas-dep.
The most important configuration files in the project are the following:
main configuration :
src/main/webapp/WEB-INF/applicationContext.xml
map configuration :
src/main/webapp/WEB-INF/mapMain.xml
overview map configuration:
src/main/webapp/WEB-INF/mapOverview.xml
countries layer configuration :
src/main/webapp/WEB-INF/clientLayerCountries.xml
and
src/main/webapp/WEB-INF/layerCountries.xml
OpenStreetMap layer configuration :
src/main/webapp/WEB-INF/clientLayerOsm.xml
and
src/main/webapp/WEB-INF/layerOsm.xml
GWT configuration file :
src/main/java/Application.gwt.xml
web.xml:
src/main/webapp/WEB-INF/WEB-INF/web.xml
More details about the Geomajas configuration are found in the developer's guide.
Reference which may be interesting to read:
GWT project page: http://code.google.com/webtoolkit/.
SmartGWT showcase: http://www.smartclient.com/smartgwt/showcase/.
DZone's GWT refcardz: http://refcardz.dzone.com/refcardz/gwt-style-configuration-and-js.
spring documentation: http://www.springsource.org/documentation.
DZone's spring configuration refcardz: http://refcardz.dzone.com/refcardz/spring-configuration.
maven project: http://maven.apache.org/.
Maven by example book: http://www.sonatype.com/books/mvnex-book/reference/public-book.html.
maven reference book: http://www.sonatype.com/books/mvnref-book/reference/public-book.html.
DZone's maven 2 refcardz: http://refcardz.dzone.com/refcardz/apache-maven-2.
Table of Contents
This chapter is out of date and uses an older, no longer supported version of Geomajas. Paths have been modified to comply with current conventions.
In this chapter a step-by-step guide is given of how to create a web-application based on Geomajas from scratch. The application is based on marine information and has the following features :
Maps
The following maps will be used in the web-application
OpenStreetMaps as a background
Shape files
ECDIS map. The source of these maps are simple feature data files. These will be converted using OGR2OGR to a postGIS database.
AGIV maps. This is a WMS server (http://gditestbed.agiv.be/blog/2010/01/default.aspx)
SOAP
Using SOAP we will request the current positions of vessels in Belgium and Holland. Each vessel will be shown on a the map with a marker. When such a marker is clicked extra information about the selected vessel is shown.
Facility XML
The facility XML contains information about locks. When a lock is clicked (in one of the shape file layers) the corresponding XML is requested from the server and translated to HTML using XSL. After this the resulting HTML will be displayed to the user.
User management
Two different users will be available. One user has complete access to everything. The second user only can view some layers.
When using Eclipse and the GWT plug-in we removed the "generateAsync" feature from the pom.xml. Our code already contained manually generated async files, and this caused weird problems/conflicts.
Note that when you are in need of help you can always post questions on the Geomajas mailing list (check this page for instructions on how to join the mailing list) or on the Geomajas forum.
To create a new project based on Geomajas you must execute the following steps:
Example 3.1. Create project using GWT Maven archetype
mvn archetype:generate -DarchetypeCatalog=http://files.geomajas.org/archetype-catalog.xml
Once this is executed you can , among others, use the following commands :
mvn install
mvn jetty:run
mvn gwt:run
mvn eclipse:eclipse
If you are using eclipse you want to start by using the mvn
eclipse:eclipse
command. This will make your project eclipse
compliant. Once this command is finished go to eclipse, right-click on the
project, properties, google and check that the project is using GWT. Note
that every time you do an mvn eclipse:eclipse
you will have
to retake the steps. Most times you have to switch off/switch on the GWT
marker in eclipse.
Now you can already try and run the project. Either from within
eclipse or from the command line using maven: mvn gwt:run
.
You will see that you now have a basic Geomajas project already showing an
OpenStreetMaps layer and a vector layer based on shape files.
In this section we are going to explain how to add a layer to your
Geomajas showing some of your own shape files. The layer we will be
creating has the name VhaLayer
.
To show your own shape files in Geomajas follow these steps :
Place your shape files in
src/main/resources/be/fks/shapes
(note that you can
configure the exact location of these).
Now modify
src/main/webapps/WEB-INF/applicationContext.xml
Note that
you can use the existing road shape file layer as a reference to help
you out.
Modify src/main/webapp/WEB-INF/web.xml (please remove the
"be/fks/shapeinmem/" from the displayed text).
Create src/main/webapp/WEB-INF/layerVha.xml
. Note
that you can use the existing layerRoads.xml as a reference to help
you out.
Use a tool like uDig to help you. With uDig you can view shape files, PostGIS data,... and you can view the available fields.
If you get really stuck you can download an example layerVha.xml right here.
Note that if your layer is a MULTIPOINT or a POINT layer you must define a symbol.
In this section we are going to explain how to add a layer to your
Geomajas showing some of your own shape files. The layer we will be
creating has the name EcdisLayer
.
Ecdis files are provided as simple feature files. The first step we are going to do is convert these files to PostGIS. After this we will configure Geomajas to display our created PostGIS data using hibernate.
Download Ecdis files (not available here).
Be sure you have a PostgGIS database available.
Install the ogr2ogr tool (this is included in FWTools). You can find this tool using Google.
Use ogr2ogr in the following manner. Note that the csv files included in the zip must be visible to ogr2ogr.
Example 3.2. Use ogr2ogr to convert Ecdis files to PostGIS
ogr2ogr.exe -f "PostgreSQL" "PG:dbname=ecdis user=postgres password=postgres host=localhost port=5432" Y:\1R5EK012.000 -append
Check your PostGIS database (remember that you can use a tool like uDig for this).
Now modify
src/main/webapp/WEB-INF/applicationContext.xml
Add appDataSource
Add appSessionFactory
Add layer
Add treeNode
Add org.geomajas.configuration.client.ClientVectorLayerInfo bean
Modify src/main/webapp/WEB-INF/web.xml (please remove the
"be/fks/shapeinmem/" from the displayed text)
Create src/main/webapp/WEB-INF/layerEcdis.xml
. Base
yourself on an example layer file using Hibernate.
Use a tool like uDig to help you. With uDig you can view shape files, PostGIS data,... and you can view all available fields.
If you get really stuck you can download an example layerEcdis.xml right here.
Note that the WMS used in this example is a password protected WMS. Due to privacy reasons the login details are excluded from this example. Please use your own or a public WMS server to test out this part of the guide.
Modify
src/main/webapp/WEB-INF/applicationContext.xml
Modify src/main/webapp/WEB-INF/web.xml.
Add a reference to layerWmsAgiv.xml in your web.xml just like you did in the previous 2 examples.
Create
src/main/resources/be/fks/shapeinmem/
layerWmsAgiv.xml
baseWmsUrl : The link to the capabilities file but without all the extra parameters
dataSourceName : This must contain a name of the layer (names of the layers can be found in the capabilities file of the WMS server)
org.geomajas.geometry.Bbox : This can be derived from the capabilities file of the WMS server
Now you can also add extra parameters. In our example we set transparent to true and do some other things. Note that the WMS must understand the parameters you try to use (possible parameters can be derived from the capabilities file).
You can download an example layerWmsAgiv.xml file right here. Note that as said before the login details are excluded from this example due to privacy reasons. This renders this example file useless. Please use your own, or a public WMS server to test out this part of the guide.
Geomajas doesn't have any native SOAP support implemented. So what you need to is create a normal GWT servlet which does the SOAP handling and sends information back to the client about the locations of the vessels. Finally at the Geomajas client side you can display these vessels.
The following steps should be taken :
Create a servlet requesting the needed information using SOAP. Note that if you are using any special external jars you need to add those to the class path in eclipse, and to the maven class path.
At the client side display the location of the vessels using an image.
First we load the positions of the vessels and put all the requested information inside a List imgVesselPos. Initially we give the images a size of 0,0. This is because in Geomajas images resize when the user zooms. In the next step we will create size the images depending on the zoom level
In OnMapModelChange()
(called every time a user
zooms) we resize the images to the correct size depending on the
current zoom level.
Finally we create a controller. This controller shows some extra information to the user when the user clicks on a vessel.
In reality the controller is on the map (because you can't add a controller to an image). When clicked a check is performed to see if a vessel is at the location of the click.
FacilityXML documents are XML documents containing information about locks in Belgium. The goal was that when the user clicked on a lock in a certain layer the correct FacilityXML document was requested from the server and shown to the user in a nicely formatted way. The formatting is done using an XSL transformation.
Since the requesting of the XML and the XSL transformations isn't part of Geomajas this will not be discussed here. What will be show however is how you can add a listener to a layer and use data from the selected feature.
Create src\main\resources\be\fks\shapeinmem\security.xml (download an example right here). This is the file inside which you configure the users and what they are allowed to access.
Add a reference to security.xml to the web.xml just like you would do for a normal layer.
Add dependencies in pom.xml
Inherit security in the gwt.xml of the project.
In your Java code you can now create a login window using the
class org.geomajas.plugin.staticsecurity.client.LoginWindow. Use the
LoginHandler
to check if the login succeeded or
not.