Perforce JViews TGO Sample: Network Component - Geographic Positioning
Description
This sample shows how to place network elements on a background map. The locations of the network elements are indicated by geographic coordinates.
How to Use the Sample
You can interact with the objects through the selection interactor. For example, open the Information window attached to the "Helsinki" element. You can also navigate through the map by using the scroll bars and the zoom buttons. When you move the mouse over the map, the geographic coordinates corresponding to the mouse location are displayed in the lower right of the frame. Note that you can move the network elements on the map, but you should not move them further than the North Pole, nor further than the South Pole. The geographic position converter does not support invalid positions like these extreme cases. Note also that if you move network elements too far east or west, they will disappear and reappear on the opposite side of the map. This is a normal behavior, and reflects the topology of the earth surface.
How to Run the Sample as an Application
This sample can
be run as an application.
The installation directory contains
an executable JAR file,
network-geopositioning.jar
,
that allows you to execute the sample with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the sample application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the sample and type:
ant run
Topics Covered
- Initializing a JTGO application using a deployment descriptor
- Creating a data source
- Creating a network component with a CSS configuration file that refers to a background map
- Enabling geographic coordinates through a position converter
- Focusing on a part of the map by zooming
- Associating the data source with the network component
- Reading data from an XML file into a data source
- Converting screen coordinates back to geographic coordinates
Detailed Description
This sample shows how to place network elements on a background map. The locations of network elements are given by geographic coordinates. The code of this sample is contained in the doSample method
. The sample includes the following steps:
- Initialize the application using the method ilog.tgo.IltSystem.Init. You can pass a deployment descriptor file to this method. The file contains information about global settings for the application.
In this sample, the descriptor is called deploy and contains only a URL access specification. It is used to locate the background map. Note that the pathnames in the deployment descriptor are relative to the sample directory. This directory is always implicitly contained in the search path. Therefore, it does not need to be listed explicitly. - Create a standard data source of class ilog.tgo.datasource.IltDefaultDataSource.
- Create a network component and load its configuration from a CSS file.
The network component is of the class ilog.cpl.IlpNetwork. You pass the name of a configuration file (network) that contains the background file description and the zoom policy definition.For a list of available background file types, see the ilog.cpl.network.renderer.IlpBackgroundsRenderer class.
The configuration also installs a mixed zoom policy that guarantees that the network elements stay at the same size when you zoom in, but shrink when you zoom out. The threshold property of this zoom defines at which zoom level the network elements begin to shrink; this threshold has been empirically determined. - Adds components to display coordinates information and scale.
This step consists in creating an instance of ilog.views.maps.beans.IlvJMouseCoordinateViewer and an instance of ilog.views.maps.beans.IlvJAutomaticScaleBar and associating them with the Network Component view. - Enable geographic coordinates to be used as locations of network elements in the XML files. This step must be performed before the XML file is read into the data source, or before the data source is connected to the network component.
This step consists in setting an instance of ilog.cpl.network.IlpGeographicPositionConverter in the network component. The parameters of this converter are:- A projection that converts geographical coordinates to plane coordinates (an instance of ilog.views.maps.projection.IlvProjection or ilog.views.maps.srs.coordtrans.IlvMathTransform).
- An adjustment of the coordinates onscreen (a zoom followed by a translation). This is an instance of ilog.views.IlvTransformer.
- Focus on a part of the map. In our sample, the map spans the entire globe, but our network is located in Europe only. In order to show only Europe when the sample starts, a zoom and a translation are performed on the view. This transformation
new IlvTransformer(16,0,0,16, 181,1100)
has been empirically determined. - Connect the data source to the network component.
- Read a data file into the data source.
The data file network is read using the ilog.cpl.datasource.IlpDefaultDataSource.parse method. The file contains instances of some of the JTGO predefined classes. Since the data source is already connected to the network, the objects from the data file will immediately be displayed in the network. - Add the network to your Swing application.
ilog.cpl.IlpNetwork is a SwingJComponent
, so it can be added to your application like any other Swing component.
Installation Directory
The Network Component - Geographic Positioning sample is installed here.
Classes Involved
-
ilog.tgo.IltSystem
The class that initializes a JViews TGO application.
-
ilog.tgo.datasource.IltDefaultDataSource
The default datasource implementation.
-
ilog.cpl.IlpNetwork
The network component.
-
ilog.cpl.model.IlpObject
The business object definition.
-
ilog.cpl.network.IlpGeographicPosition
The geographic position of an object.
-
ilog.cpl.graphic.IlpPositionConverter
The converter between model and view coordinates.
-
ilog.cpl.network.IlpGeographicPositionConverter
The converter between geographic position and view coordinates.
-
ilog.views.maps.projection.IlvProjection
The map projection.
-
ilog.views.maps.beans.IlvJMouseCoordinateViewer
The map coordinate viewer.
-
ilog.views.maps.beans.IlvJAutomaticScaleBar
The map scale bar.
-
ilog.views.maps.projection.IlvCylindricalEqualAreaProjection
The projection that wraps a large, flat plane around the globe to form a cylinder.
-
ilog.views.maps.projection.IlvEquidistantCylindricalProjection
The projection that wraps a large, flat plane around the globe to form a cylinder multiplying the latitudes and longitudes by a scale factor.
-
ilog.views.maps.projection.IlvMillerCylindricalProjection
The Miller cylindrical projection.
-
ilog.views.maps.srs.coordtrans.IlvMathTransform
The math transformation definition.
-
ilog.views.IlvTransformer
The view transformer.
-
ilog.views.IlvManagerView
The manager view.
-
ilog.cpl.graphic.IlpPoint
The point position.
-
ilog.tgo.graphic.IltCompositeGrapher
The composite grapher.
-
ilog.cpl.network.renderer.IlpBackgroundsRenderer
This class gives control over the backgrounds of a network component.
Source Files
-
geopositioning.Main
The entry point of the sample.