Layers and Layer Manager

Table of contents

Concepts

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 and its derived classes

Layer class

The Layer class is abstract and therefore cannot be instantiated. However, it provides the basic methods for all layers.

VectorLayer class

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.

RasterLayer class

The RasterLayer class is derived from the Layer class and contains only raster data. Its methods are rarely used by JMap application developers.

Layer class events

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.

LayerManager 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.

LayerManager class events

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.

Dernière mise à jour

K2 Geospatial 2022