Views and View Manager

View class

In JMap, the View class is the main GUI component responsible for displaying the map. The methods of this class allow you to control the map (zoom, pan, etc.), to refresh it, to get information on the scale, etc.

The table below shows the main methods of the View class.

Navigation

Performs a zoom at the map centre using the specified magnifying factor. For example, a factor of 2 will display a map that is two times closer. A value of 0.5 will produce a map that is two times farther. The map must be refreshed afterwards.

Pans and zooms the map around the specified rectangle. The map must be refreshed afterwards.

Pans and zooms the map to show the entire area covered by the data. The map must be refreshed afterwards.

Makes the specified coordinates the new centre of the map view. The scale is not affected.The map must be refreshed afterwards.

Makes the specified coordinates the new centre of the map view. The scale is not affected. The map must be refreshed afterwards.

Moves the map based on the x and y values specified in screen coordinates (DC). The map must be refreshed afterwards.

Modifies the map scale based on the specified value. The map must be refreshed afterwards.

Display

Refreshes the map. After any method modifying the state of the map is called, the map must be refreshed in order to display the changes.

Adds a marker (symbol indicating a location) at the specified coordinates with the specified message and style.

Removes the specified marker from the map.

Removes all markers from the map.

Returns the view bounds to screen coordinates (DC).

Returns the view bounds to world coordinates (WC).

Returns the view transformation. This is the transformation used to convert Screen Cooordinates (DC) to World Coordinates (WC) and vice-versa.

Returns the view overlay. The overlay is a special layer designed to display volatile data. It is often used to create smooth animations (moving objects, drawing, etc.).

Returns the current scale factor of the view as the denominator (1: denominator).

Returns the instance of the ViewState class associated with this view. See below for more information on this topic.

Returns the current horizontal distance of the view in world coordinates (WC).

Other

Returns the LayerManager instance associated with the view.

Returns the map projection (Projection) of the data on the map.

Returns the unit (JMapUnit) of the data on the map.

Removes an action from the view’s pop-up menu.

Removes an item from the view’s pop-up menu.

Adds an action to the view’s pop-up menu.

Adds an item to the view’s pop-up menu.

Registers a listener to the events generated by the view.

Removes a listener from the events generated by the view.

Replaces the active tool of the view with the tool specified as a parameter.

Events of the View class

In JMap, a view generates events in several situations. To get these events, you must register a listener to the view. To get events generated by all open views, it is recommended to register a listener on the View Manager. Read below for more information on this subject.

To receive a view’s events, you must implement the ViewEventListener interface and register it with the view using the addViewEventListener() method, as shown in the example below.

View view = ...

view.addViewEventListener(new ViewEventListener()

{

@Override

public void viewToolChangedOccurred(ViewToolChangedEvent e)

{

}

...

});

Note that the ViewAdapter adapter can also be used to simplify the development of a listener.

The table below shows the events triggered by the View class.

View events

Launched after the view's state changes following a navigation operation (zoom, pan, etc.).

Launched when the active tool of the view is replaced by another tool.

Launched when the view is redrawn, in whole or in part. The elements of the layers are redrawn.

Launched when the view is repainted, in whole or in part. The image of the map is simply refreshed; the elements of the layers are not redrawn.

Launched when static elements (north arrow, scale bar, etc.) are added to or removed from the view.

Launched just before the pop-up menu of the view is displayed. Allows you to change the contents of the menu before it is presented to the user.

Launched when the view becomes ready for use, i.e. after the first time it is displayed.

For more information on events in Java, see the Java Tutorial.

ViewState class

The ViewState class contains some view properties that define its state at a given time (scale, scope, transformation, etc.). Several methods in the JMap API take an instance of ViewState as a parameter. It is possible to get the state of a view by calling the getViewState() method of the View class.

ViewManager class

The view manager (ViewManager class) is responsible for managing one or more views that are present in the application. This class has methods that allow you to perform operations on all the views of the application and to know at any time which view is active (i.e. in focus).

The table below shows the main methods of the ViewManager class.

Most commonly used methods of the ViewManager class

Registers a listener to the events triggered by the active view.

Registers a listener to the events triggered by the view manager (see below).

Returns the active view (i.e. the view that is in focus).

Return the layer manager of the active view.

Returns the view with the name specified as a parameter.

Returns a list of all existing views in the view manager.

Performs a refresh action on all existing views in the view manager.

Removes a listener from the events triggered by the active view of the view manager.

Removes a listener from the events triggered by the view manager.

Replaces the active tool of the active view with the tool specified as a parameter.

Events of the ViewManager class

The View Manager triggers events associated with the state of its views. To get these events, you must implement the ViewManagerEventListener interface and register it with the view manager using the addViewManagerEventListener() method, as shown in the following example.

View view = ...

ViewManager viewManager = view.getLayerManager();

viewManager.addViewManagerEventListener(new ViewManagerEventListener()

{

@Override

public void viewAdded(ViewAddedEvent e)

{

}

...

});

Note that the ViewManagerAdapter adapter can also be used to simplify the development of a listener.

The table below shows the events triggered by the ViewManager class.

View manager events

Launched when a view is added to the View Manager.

Launched when a view is activated (i.e. comes into focus).

Launched when a view has been deactivated (i.e. it has lost focus in favour of another view).

Launched when a view is removed from the View Manager.

It is also possible to register a listener to the View Manager to get the events generated by all the views associated with the layer manager. This may be more convenient than registering a listener on each view separately. To do so, use the addViewEventListener method of the ViewManager class.

ViewUtil class

The ViewUtil class provides useful methods to work with the view.

The table below shows the mains methods of the ViewUtil class.

Most commonly used methods of the ViewUtil class

Sends an image of the map by email to the recipients defined in the MailMessage type object passed as a parameter.

Produces and returns an image of the map as displayed in the view. The width (in pixels) of the image to be created is passed as a parameter.

Saves an image of the map on the hard drive. A window displays, allowing the user to select the location of the file.

Dernière mise à jour

K2 Geospatial 2022