$webwork.htmlEncode($page.space.name) : Google Web Toolkit (GWT), OpenLayers and GeoServer
This page last changed on Sep 13, 2007 by egunay.
This tutorial will introduce you to the GWT - OpenLayers - GeoServer integration plugin by demonstrating how to setup the development environment and how to create a map project. GWT - OpenLayers plugin aims to wrap OpenLayers JavaScript objects as GWT ui widgets so that GWT users can easily include OpenLayers ui widgets on their web pages for rendering geographical maps produced by GeoServer and/or other map servers like Google Maps, etc. GWT - OpenLayers plugin is an open source project implemented by Erdem Gunay. Although it does not support all the OpenLayers classes yet, it is in a good shape to use main features including
Here are some screenshots produced by using this plugin & GWT & OpenLayers & GeoServer
HOWTO setup development environmentPrerequisites
Installing GWTIt should be quite straightforward to install GWT, simply download the release pack and unpack it to somewhere. Verify that the sample applications under samples directory are running properly. Add the GWT folder to path environment variable so that the following GWT executable files are in path
Installing GeoServerFollow the installation instructions on GeoServer link above to install GeoServer. Make sure that the geoserver is installed and running properly by clicking following url (Note that depending on the installation, the port number may be different). Installing OpenLayersAfter downloading the OpenLayers package, unpack the package file. Following folders and JavaScript file will be used later in the tutorial
HOWTO use GWT-OpenLayers plugin to show GeoServer mapCreate a GWT projectCreating a GWT project is explained in detail by following article For this tutorial we will create a new eclipse project called 'gwt-openlayers-tutorial' Add GeoServer map to your GWT applicationNow it's time to add GeoServer map to GWT application by using GWT-OpenLayers plugin Add OpenLayers files to projectCopy following file and folders from OpenLayers unpacked folder to 'src/tutorial/public'
Add openlayers_gwt-0.1.jar to your projectModify Tutorial1.html file
Modify Tutorial1.java classimport section import com.eg.gwt.openLayers.client.Bounds; import com.eg.gwt.openLayers.client.Icon; import com.eg.gwt.openLayers.client.JObjectArray; import com.eg.gwt.openLayers.client.JSObject; import com.eg.gwt.openLayers.client.LonLat; import com.eg.gwt.openLayers.client.Map; import com.eg.gwt.openLayers.client.MapOptions; import com.eg.gwt.openLayers.client.MapWidget; import com.eg.gwt.openLayers.client.Marker; import com.eg.gwt.openLayers.client.Pixel; import com.eg.gwt.openLayers.client.Size; import com.eg.gwt.openLayers.client.control.LayerSwitcher; import com.eg.gwt.openLayers.client.control.MousePosition; import com.eg.gwt.openLayers.client.control.MouseToolbar; import com.eg.gwt.openLayers.client.control.PanZoomBar; import com.eg.gwt.openLayers.client.control.Scale; import com.eg.gwt.openLayers.client.event.EventHandler; import com.eg.gwt.openLayers.client.layer.Layer; import com.eg.gwt.openLayers.client.layer.Markers; import com.eg.gwt.openLayers.client.layer.WMS; import com.eg.gwt.openLayers.client.layer.WMSParams; import com.eg.gwt.openLayers.client.popup.AnchoredBubble; import com.eg.gwt.openLayers.client.popup.Popup; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.DockPanel; import com.google.gwt.user.client.ui.RootPanel; define class attributes public class Tutorial1 implements EntryPoint { private MapWidget mapWidget; private Map map; private WMS wmsLayer; private Markers markers; private Popup popup; modify onModuleLoad(), create map widgets public void onModuleLoad() { // let's create map options MapOptions mapOptions = new MapOptions(); mapOptions.setControls(new JObjectArray(new JSObject[] {})); mapOptions.setNumZoomLevels(16); mapOptions.setProjection("EPSG:4326"); // let's create map widget and map objects mapWidget = new MapWidget("350px", "350px", mapOptions); map = mapWidget.getMap(); markers = new Markers("marker layer"); create wms layer and map controls // let's create WMS map layer WMSParams wmsParams = new WMSParams(); wmsParams.setFormat("image/png"); wmsParams.setLayers("tiger-ny"); wmsParams.setStyles(""); wmsParams.setMaxExtent(new Bounds(-74.047185, 40.679648, -73.907005, 40.882078)); wmsLayer = new WMS("WMS Layer", "http://localhost:8080/geoserver/wms", wmsParams); // let's add layers and controls to map map.addLayers(new Layer[] {wmsLayer, markers}); map.addControl(new PanZoomBar(RootPanel.get("nav").getElement())); map.addControl(new MousePosition(RootPanel.get("position").getElement())); map.addControl(new Scale(RootPanel.get("scale").getElement())); map.addControl(new MouseToolbar()); map.addControl(new LayerSwitcher()); center the map and add a marker on the center // let's center the map to somewhere and set zoom level to 13 LonLat center = new LonLat(-73.99, 40.73); map.setCenter(center, 13); // add marker Size size = new Size(10,17); Pixel offset = new Pixel(-5, -17); Icon icon = new Icon("img/marker.png", size, offset); Marker marker = new Marker(center, icon); markers.addMarker(marker); register a mouse over event to the marker // register mouse over event marker.getEvents().register("mouseover", marker, new EventHandler() { public void onHandle(JSObject source, JSObject[] param) { Marker marker = Marker.narrowToMarker(source); if (popup != null) { map.removePopup(popup); } popup = new AnchoredBubble("marker-info", marker.getLonLat(), new Size(120,80), "<p>You moved near " + marker.getLonLat().lon() + " : " + marker.getLonLat().lat() + "</p>" , new Icon("", new Size(0,0), new Pixel(0,0)), true); map.addPopup(popup); } }); // register mouse out event marker.getEvents().register("mouseout", marker, new EventHandler() { public void onHandle(JSObject source, JSObject[] param) { Marker marker = Marker.narrowToMarker(source); if (popup != null) { map.removePopup(popup); } } }); put map widget on the page // eventually add the map widget to div:map DockPanel dockPanel = new DockPanel(); dockPanel.add(mapWidget, DockPanel.CENTER); dockPanel.setBorderWidth(1); RootPanel.get("map").add(dockPanel); } } Run Tutorial1 applicationWhen you run the Tutorial1 application again, you should see the map and a marker on the center. If you drag the mouse over the marker icon, a popup displaying the coordinates will appear. If you drag the mouse out the marker icon, the popup will disappear.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
Document generated by Confluence on Jan 16, 2008 23:27 |