Note: the ArcGridDataSource used below is deprecated and was replaced by a GridCoverageExchange implementation (will be in the 2.1 release).
Let's review what we have seen by creating a small map. The map data is available in the CVS repository in the sample data module, but I've attached it to this page too. If you want to use the attached data, you will just need to change the URLs so that they point to your local filesystem instead of using the classpath.
In order to build a map you need to:
- Get the feature sources with the data you want to display from the feature store, or the feature collection from the data sources (if you need to use an older data source that has not yet been converted to the newer data store interface).
- Build an appropriate style for each feature source. Here we will use the StyleBuilder to ease the tedious building of a full Style object.
- Create a MapContext and add the layers: made up of the feature sources and the styles
- Create a MapPane to display the MapContext contents on the screen.
The full source code is attached to this page. Here we will examine the source code section by section.
First, let's load the FeatureSources and the FeatureCollections. Please refer to the Data access basic for more information about data sources. One small note about the DEM loading: as you can see an ArcGrid data source is used, giving us a feature collection. The feature collection will contain a single Feature that in turn wraps the GridCoverage that really has the DEM in it.
Next, let's create styles. The streams style will be a blue line, 3 pixels wide:
The roads style will be a composite style, with a yellow centerline and a black wider line under it. To avoid visual problems at crossings, we will build it with two separate feature type styles instead of using a rule with two symbolizers:
The archeological sites will be depicted as a small yellow triangle and a label with the name of the archeological site. The name is contained in the "CAT_DESC" attribute of the shapefile, and we are going to tell the text symbolizer this. Also notice the halo, that will be drawn around the text in order to make it more readable.
In this case we will create a rule with two symbolizers, since we don't have crossing problems here.
The bug sites will be depicted as small red circles. The code is very similar to that above, so it is omitted here.
The restricted areas will be depicted as gray translucent polygons by giving them an opacity of less than 1.0:
Finally, we will create a style for the DEM. Here we are going to provide a special color map that associates a certain height with a certain color, and generates a color ramp for intermediate values:
Once the styles are ready, building the map and showing it is a snap:
Here is a screenshot of the resulting map pane, where you can see:
- the map;
- the magnifier;
- the map pane commands, listed in the context menu.
In conclusion, a word of caution about using the MapPane: the MapPane in its current state is not a finished part of the API and will be changed once we complete the GUI components design. If you wish to help, please share your opinions and help us in the GUI components design page.