Skip to content

Commit

Permalink
[GEOT-7109] Swt Module review and update (#3921)
Browse files Browse the repository at this point in the history
* fix dependencies and some minor improvements

* upgrade to uptodate swt libraries + fixes in tools

* fix for crs madness on loading

* re-fix necessary swt actions class to add to the menus + resetting Utiles due to wrong formatting

* update swt modules documentation

* apply proper formatting rules

* add data loading example and mapaction example to docs

* cleanup commments in pom
  • Loading branch information
moovida committed Jun 13, 2022
1 parent 1bb28b1 commit aaa25ef
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 407 deletions.
Binary file removed docs/user/images/gtswt_rcp_01.png
Binary file not shown.
Binary file removed docs/user/images/gtswt_rcp_02.png
Binary file not shown.
Binary file modified docs/user/images/gtswt_standalone_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/user/images/gtswt_standalone_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/user/images/gtswt_standalone_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/user/unsupported/swt/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ in a future extraction of common interfaces for GUI modules.
:maxdepth: 1

swtmapframe
rcp
216 changes: 0 additions & 216 deletions docs/user/unsupported/swt/rcp.rst

This file was deleted.

118 changes: 82 additions & 36 deletions docs/user/unsupported/swt/swtmapframe.rst
Original file line number Diff line number Diff line change
@@ -1,54 +1,100 @@
SWTMapFrame
-----------

The following is a tutorial that explains how to use the ``gt-swt`` module in standalone mode and inside
an RCP environment. The tutorial assumes the user is already confident with
GeoTools development/build and already an basic RCP developer.
The following is a tutorial that explains how to use the ``gt-swt`` module in standalone mode.
The tutorial assumes the user is already confident with GeoTools development.

Example
^^^^^^^

Using the standalone ``gt-swt`` module is fairly easy.

1. It is best explained with a code snippet::
Using the standalone ``gt-swt`` module is fairly easy and is best explained with a code snippet::
public class Main {
public static void main( String[] args ) throws Exception {
// create a default mapcontext
MapContext context = new DefaultMapContext();
// set the title
context.setTitle("The SWT Map is in the game");
// add a shapefile if you like
File shapeFile = new File("/home/moovida/data/world_adm0/countries.shp");
ShapefileDataStore store = new ShapefileDataStore(shapeFile.toURI().toURL());
SimpleFeatureSource featureSource = store.getFeatureSource();
SimpleFeatureCollection shapefile = featureSource.getFeatures();
context.addLayer(shapefile, null);

// and show the map viewer
SwtMapFrame.showMap(context);
// create a default mapcontext
MapContent context = new MapContent();
// set the title
context.setTitle("The SWT Map is in the game");
// and show the map viewer
SwtMapFrame.showMap(context, null);
}
}
Which results in:
Which results in:

.. image:: /images/gtswt_standalone_01.png
.. image:: /images/gtswt_standalone_01.png

2. It is possible to tweak some of the window settings, like ``statusbar``, ``layers panel`` and
``toolbars/menus``. For this use we have to move beyond our call to ``SwtMapFrame.showMap(context)``

The result is equally easy. Again a code snippet is the best way.

In the following case we decide that we want to get rid of the layers panel::

It is possible to supply to the mapframe an actionhandler that allows to add actions to the file and
navigation menus. For example the following code snippet shows how to add an add-OSM-layer action to
the file menu (in addition to the default entries)::
boolean showMenu = true;
boolean showToolBar = true;
boolean showStatusBar = true;
boolean showLayerTable = false;
final SwtMapFrame frame = new SwtMapFrame(showMenu, showToolBar, showStatusBar, showLayerTable, context);
frame.setBlockOnOpen(true);
frame.open();
public static void main( String[] args ) throws Exception {
// create a default mapcontext
MapContent context = new MapContent();
// set the title
context.setTitle("The SWT Map is in the game");
// create an action handler with the selected MapActions
SwtActionsHandler actionsHandler = new SwtActionsHandler(){
private OpenShapefileAction openShapefileAction = new OpenShapefileAction();
private OpenGeotiffAction openGeotiffAction = new OpenGeotiffAction();
private AddOsmAction addOsmAction = new AddOsmAction();

@Override
public MapAction[] getFileMenuActions() {
return new MapAction[]{openShapefileAction, openGeotiffAction, addOsmAction};
}

@Override
public MapAction[] getFileNavigationMenuActions() {
return new MapAction[0];
}

};

// and show the map viewer
SwtMapFrame.showMap(context, actionsHandler);
}


where the MapAction itself would be a class like::


public class AddOsmAction extends MapAction implements ISelectionChangedListener {

public AddOsmAction() {
super("Add OSM", "Add an Openstreetmap layer to the viewer.", null);
}

public void run() {
MapContent mapContent = mapPane.getMapContent();
String baseURL = "https://tile.openstreetmap.org/";
TileService service = new OSMService("OpenStreetMap", baseURL);
TileLayer layer = new TileLayer(service);
layer.setTitle("OpenStreetMap");
mapContent.addLayer(layer);
mapPane.redraw();
}

public void selectionChanged( SelectionChangedEvent arg0 ) {
}
}

Which results in:
The viewer will now have a new entry in the File menu:

.. image:: /images/gtswt_standalone_01.png
.. image:: /images/gtswt_standalone_02.png


By default, the viewer supports loading of shapfiles and geotiffs. If you do not know where
to get a shapefile, you can download the dataset of the world's countries from the Naturalearth Project `at this link
<https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip>`_.

Once downloaded and unzipped, just use the **Open Shapefile** action from the file menu and load the shapefile:

.. image:: /images/gtswt_standalone_03.png

The viewer features a simple style editor for vector layers and a couple of utilities to
change the order of the layers, remove a layer and bulk select and unselect the layers visibility.

0 comments on commit aaa25ef

Please sign in to comment.