Customizing the map

This topic explains ways to customize your map (JMap instance), for example by controlling the animation, enabling layers to wrap around the dateline, or adding a grid.

Enabling wrap around

The world is round, however most flat representations of the earth only extend up to 180 degrees East and West longitude. This makes it difficult to visualize areas that span across the date line, or routes that traverse the Pacific Ocean. By enabling the wrapAround property on a map, the eastern and western hemispheres wrap around each other forming a continuous map and giving the impression that the map is endless. Panning a map becomes similar to spinning a globe.

By default the map layers added to a map (JMap instance) do not wrap around the dateline. If you would like the map's tiled layers to wrap around the dateline, you can set this on the map as follows:

map.setWrapAroundEnabled(true);
NoteNote:

Currently, wrap around will work for tiled layers whose full extent envelope covers the entire world.

Displaying 'no data' tiles

Tile caches for cached map services usually do not have a tile for every single level of detail, everywhere in the extent of the area of coverage of the service. In a Java map application, the map control allows you to zoom or pan to one of these levels of details for which no tile exists. In your application you can choose to show a standard 'no data' tile when this occurs, or you can show a tile from the nearest level of detail for this area, resampled. The default behavior is to show a resampled tile, such that if you are zooming into an area and you get to the point where no tiles are available, you will start to see the same tile you were seeing at the previous zoom level, but larger. The code snippet below shows how you would set the map to show or hide the 'no data' tiles:

// show 'no data' tiles
map.setHidingNoDataTiles(false);
 
// hide 'no data' tiles
jMap.setHidingNoDataTiles(true);

Below is an example of what a 'no data' tile looks like:

'no data' tile

Controlling the animation

Methods on the JMap component allow you to control the animation mode and duration (animation is turned on by default). The code snippet below shows how you would set the animation duration to 1 second, or turn the animation off:

// set a custom animation duration (1 second) on panning and zooming
map.setAnimationDuration(1.0f);
 
// turn the animation off
map.setAnimationMode(AnimationMode.OFF);

Displaying a grid

You can add a grid to a map by calling the getGrid() method on the JMap instance and choosing the type of grid you would like to display. By default the grid type is 'None' such that no grid displays. As an example, the code snippet below allows you to show a grid of type Military Grid Reference System (MGRS) in your map:

// adds an MGRS grid to the JMap instance
map.getGrid().setType(GridType.MGRS);

The result is an MGRS grid displaying in your map, as in the following screen capture:

MGRS grid added to a map

Methods on the Grid class allow you toggle the visibility of the grid and change the type of grid to display on-the-fly. In addition, you can further customize the grid by controlling:

Customizing these aspects of the grid may be desirable depending for example on which basemap you are using and which part of the world your application focuses on. The code snippet below sets a custom line color, label color, and line width on a grid:

// set up some custom grid colors and line widths 
int gridLevels = map.getGrid().getLevelCount();
for (int level = 0; level < gridLevels; level++) {
   map.getGrid().setLineColor(level, Color.RED);
   map.getGrid().setLabelColor(level, Color.CYAN);
   map.getGrid().setLineWidth(level, 1);
}

Toggling the Esri logo

The Esri logo displays in a map by default but you can control whether you want to show this logo or not. The code snippet below toggles off the Esri logo:

// toggle off the esri logo
map.setShowingEsriLogo(false);
2/7/2013