Layers (Layer class and its related classes) are highly important in JMap programming. They contain and manage the map data displayed on the map (View class). There are two main types of layers: vector layers (VectorLayer class), which contain vector data, and raster layers (RasterLayer class), which contain raster data (images).
When a project is loaded, the client application gets the layer configuration from the server and creates the related instances in the LayerManager. Initially, a layer does not contain any data. Its data will only be loaded, in full or in part, after the view has been refreshed, based on the loading mode and display restrictions (visibility state and display thresholds).
In JMap, there are two different modes to load layers: by tile and by region. Vector layers support both modes, but raster layers can only be loaded by region.
Tiled layers divide the region of the layer into rows and columns; each cell is a data tile (TileSet and Tile classes). Since the layers are initially empty at application startup, data tiles will be loaded by the application when they are initially displayed in a view. Once it is loaded in a layer, a tile will be kept in memory for the duration of the session, unless the session expires prematurely or the memory manager decides to delete the tile.
When a data tile request is sent to JMap Server, all geometries (Geometry interface) intersecting the region of the tile will be transferred to the client. Once the tile is received, the geometries will be transformed into elements (K2DElement class), which will then be loaded in the TileSet of the layer. To avoid duplicating an element in several data tiles, elements that are not completely included in a tile will eventually be moved to the layer’s universe tile.
Layers loaded by region are based on the same structure (TileSet and Tile classes), but they only have a single tile with a variable region. When a change is applied to the transformation matrix of the view and the view is refreshed, layers loaded by region will reload their single tile with the data intersecting the extent of the view.
The Layer class is abstract and therefore cannot be instantiated. However, it provides the basic methods for all layers.
The VectorLayer class is derived from the Layer class and contains only vector data. It has several specialized methods for vector data to generate element selections, perform spatial analysis, etc.
Vector layers have a set of attributes that are common to all elements of the layer. These attributes provide the descriptive data of the layer’s elements.
The RasterLayer class is derived from the Layer class and contains only raster data. Its methods are rarely used by JMap application developers.
The layers in JMap generate events in several situations. To get the events generated by a layer, you must register a listener on the layer. To get the events generated by all the layers of the project, it is recommended to register a listener on the layer manager. See below for more information on this subject.
To receive the events of a layer, you must implement the LayerEventListener interface and register it with the layer using the addLayerEventListener() method, as shown in the following example:
Layer layer = ...
layer.addLayerEventListener(new LayerEventListener()
{
@Override
public void layerSelChangedEventOccurred(LayerSelChangedEvent e)
{
// TODO
}
...
});
There is also an adapter (LayerAdapter) that simplifies the development of the listener. The LayerEvent superclass has a getLayer() method and a getLayerManager() method allowing you to access the layer or layer manager that generated the event
The following table shows the events triggered by the Layer class.
In JMap, each map (View class) has a layer manager (LayerManager class). The latter is responsible for managing all of the layers to be shown on the map, as well as their order and hierarchical organization. In addition, the layer manager can listen for events on all layers and perform certain operations on them.
The layer manager in JMap generates events. To receive the events generated by a layer manager, you must register a listener on the appropriate layer manager. Note that a listener registered on the layer manager will get the events generated by all the layers handled by the layer manager.
To receive the layer manager’s events, you must implement the LayerEventListener interface and register it with the layer manager using the addLayerEventListener() method.
Most commonly used methods of the Layer class
Adds a listener to the events generated by the layer.
Returns the type of elements contained in the layer. Types are defined by the constants of the ElementTypes class.
Returns the unique numerical ID of the layer.
Returns the layer name.
Returns the instance of the Style Manager (StyleManager class) used by the layer. It manages all of the layer styles, which define the graphical appearance of elements on the map.
Static method that generates a new unique identifier for a user layer.
Invalidates the cache of a layer loaded by region. This allows the layer to be refreshed when no changes have been made to the view transformation matrix.
Indicates if the layer is displayed at the specified scale according to the defined display thresholds.
Indicates whether or not the layer objects are selectable.
Indicates whether or not the layer is visible.
Returns a serializable data structure containing all of the layer’s information.
Most commonly used methods of the VectorLayer class
Adds the specified element on the layer.
Adds all specified elements on the layer.
Adds the specified element to the list of selected elements.
Adds a collection of elements to the list of selected elements.
Clears the list of selected objects on this layer.
Returns the list of attributes (Attribute class) of the layer.
Adds a new display filter (DisplayFilter interface) to the layer. This filter allows you to define what will be displayed and what won't.
Provides the first element of the layer detected at the specified coordinates in WC in the specified map (ViewState class). The last parameter determines if the elements that are invisible (due to a display filter, for example) should be considered or not.
Returns a collection containing all of the layer's elements.
Returns all of the layer's elements identified at the specified WC coordinates in the specified map (ViewState class). The last parameter determines if the elements that are invisible (due to a display filter, for example) should be considered or not.
Returns all of the layer's elements that intersect the surface specified in WC coordinates in the specified map (ViewState class). The last parameter determines if the elements that are invisible (due to a display filter, for example) should be considered or not.
Returns the total extent of the layer data as a rectangle.
Returns an array containing all the elements selected on the layer.
Most commonly used methods of the RasterLayer class
Returns the total extent of layer data as a rectangle.
Returns the raster parameters (RasterParameters class) used by the raster layer (e.g. the size of the image, transparency, etc.).
Returns an array of attributes for the various bands (RasterBand class) contained in the image.
Most commonly used events of the Layer class
Launched after new elements are added to the layer. The added elements are accessible in the instance of the event.
Launched after changing elements on the layer. Changed items are available in the instance of the event.
Launched after removing elements from the layer. The removed elements are available in the instance of the event.
Launched after changing the selection on the layer; this can include selected or unselected events. The elements in question are available in the instance of the event.
Launched after changing the style of the layer.
Most commonly used methods of the LayerManager class
Adds the specified layer to the highest position.
Adds a listener to events generated by the layer manager. The layer manager also relays all the events generated by the layers it manages.
Clears the list of selected elements on each layer.
Returns the ordered set of layers (user layers and normal layers). The layer at the zero position is the bottom layer.
Returns the layer having the specified unique identifier.
Returns the layer having the specified unique name.
Returns the position of the specified layer.
Returns a data structure (LayerVisibilitySet class) containing the visibility state of a layer. This state considers the state of the selection of groups in the layer hierarchy as well as the configuration of their visibility.
Returns all the selected elements on all layers.
Returns the extent of all selected elements on all layers.
Removes the layer located at the specified position.
Events of the layer manager
Launched after changing the position of a layer in the list of layers handled by the layer manager.
Launched after removing a layer from the list of layers handled by the layer manager.
Launched after adding a layer to the list of layers handled by the layer manager.