Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The purpose of this section is to guide Java developers in developing mapping applications based on JMap Pro and JMap Server 7 using JMap’s Java API.
Although the JMap Pro application can be customized, it is strongly recommended to implement all new features and customizations by developing extensions with JMap’s Java API.
JMap Pro is a Java-based client application. It can run as a Java applet in a browser, as a standalone JavaWebStart (JNLP) application or as a standalone application launched at the command line (which is especially useful for development). In all cases, the application is the same, and all extensions developed are compatible.
JMap Server is a server application developed in Java. You can develop extensions for JMap Server using JMap’s Java API.
For programming, the JMap 7 SDK uses Ant to perform various tasks using scripts. Ant can be downloaded from http://ant.apache.org.
When used from Eclipse, Ant may be unable to find the Java compiler in order to compile classes. In such a case, you must add a reference to the tools.jar library provided with the Java JDK in the Ant configuration. For more information, refer to this article: http://wiki.eclipse.org/FAQ_Why_can’t_my_Ant_build_find_javac%3F.
Eclipse is the preferred Java development environment for JMap. It can be downloaded from this address: http://www.eclipse.org. However, it is quite possible to develop JMap applications using the environment and tools of your choice. The following information applies to the Eclipse Luna (version 4.4) environment.
To simplify development, it is recommended to integrate the JMap 7 SDK as an Eclipse project. Your development should be in projects that are separate from the SDK to keep it intact as a source of reference.
In an Eclipse worskpace (existing or new), create a Java project for the JMap 7 SDK.
File -> New -> Java Project
Select the path of the JMap 7 SDK that was specified when it was installed. To do this, you must disable the Use default location option to let Eclipse browse a folder outside of the current workspace. The project name is set automatically when the folder is selected.
Press Finish.
To start new development work using the JMap 7 SDK (such as creating a new JMap extension), it is recommended to create separate projects. Each new project should point to the libraries distributed with the SDK to allow for compilation. The example below shows how to create a new JMap project.
In the same Eclipse workspace containing the project for the JMap 7 SDK, create a new Java project.
File -> New -> Java Project
Give your project a name then press Next.
Select the Projects tab and press Add.
Select the JMap SDK project. All of the SDK’s libraries will become available for your project. Press OK.
Press Finish.
The JMap 7 SDK comes with many examples located in the JDK_HOME/examples folder.
The Ant script build_examples.xml is used to compile and run the examples.
Many simple examples can be run in JMap Pro from a unique GUI using the Showcase extension.
The Hello World extension demonstrates a basic JMap Pro client extension that communicates with a JMap Server extension.
The Webextensions extension shows how to develop an action that can respond to JMap Web queries (refer to JMap Web Development).
In JMap, map elements are objects (points, lines, polygons, text, etc.) that make up the map. The classes of these elements are all derived from the abstract class K2DElement. Map elements are organized into layers that are displayed in a JMap application within a view (View class). Each map element is associated with a geometry (Geometry interface) and has a digital identifier as well as a certain number of attributes. The map element does not directly contain any geometry information. Instead, it is the associated geometry that contains all of the geometry coordinates. Element identifiers found within the same layer must be unique. The GeneratedUniqueId() utility method of the K2DElement abstract class allows you to generate a sequence of unique identifiers for the elements.
The following example demonstrates how to create map elements:
// Create a point geometry Point
pointGeometry = new Point.Double(100., 100.);
// Create the element using the geometry, null attributes and auto generated id
K2DPoint point = new K2DPoint(pointGeometry, null, K2DElement.generateUniqueId());
// Create a line geometry Point
pointGeometry1 = new Point.Double(100., 100.);
Point pointGeometry2 = new Point.Double(200., 200.);
Line lineGeometry = new Line(pointGeometry1, pointGeometry2);
// Create some attributes
String attrib1 = "some value";
Integer attrib2 = new Integer(999);
// Create the element using the geometry, 2 attributes and auto generated id
K2DPolyline line = new K2DPolyline(lineGeometry, new Object[] {attrib1, attrib2}, K2DElement.generateUniqueId());
Map elements normally have values for their attributes. These values are the descriptive data of the map elements. All elements within the same layer possess the same list of attributes (same names, same types). Note that the elements contain only the values of the attributes (table or chart of objects) and not their definition. The definition of these attributes is managed at the layer level, using the Attribute class.
The list of attributes for the elements of a layer is determined by the JMap administrator when the layer (linked attributes) is created. The types of attributes are defined using Java constants for the SQL types (java.sql.Types class).
Element attributes are used for many functions such as tooltips, labels, thematics, and filtering.
The following example demonstrates how to access the values of element attributes:
K2DElement element = ... Object[] attributeValues = element.getAttributes();
for (int i = 0; i < attributeValues.lenght; i++)
{
System.out.println(i + " : " + attributeValues[i]);
}
The following example demonstrates how to access the definition of a layer’s attributes.
VectorLayer layer= ...
Attribute[] attributes = layer.getAttributeMetaData();
for (int i = 0; i < attributes .lenght; i++)
{
System.out.println(i + " name : " + attributes[i].getName());
System.out.println(i + " title : " + attributes[i].getTitle());
System.out.println(i + " type: " + attributes[i].getType());
}
When elements are drawn on the map, a style object is used to determine the visual aspects of the elements. Instances of the Style class have properties such as line color, fill color, letter font, transparency, etc. Each layer will have one or more styles. The style used for displaying the elements is based on the scale of the map and whether or not it contains thematics. Thematics dictate the style of the displayed elements based on the attribute values of these elements.
The following example demonstrates how to obtain the style used for a layer according to a particular scale. Here the presence of thematics on the layer is not taken into account.
K2DElement element = ...
VectorLayer layer = ...
Style style = layer.getStyle(view.getScaleFactor());
The following example demonstrates how to obtain the style used to display a specific element at a given scale. The resulting style does not take into account the presence of thematics on the layer.
K2DElement element = ...
VectorLayer layer = ...
Style style = layer.getStyle(element, view.getScaleFactor());
Style properties can be modified by calling the methods of the Style class. The following example demonstrates how to modify the style parameters of a layer of polygons at the current map scale.
VectorLayer layerOfPolygons = ...
Style style = layerOfPolygons.getStyle(view.getScaleFactor());
style.setBorderColor(Color.BLACK);
style.setFillColor(Color.BLUE);
style.setTransparency(.5f); // 50% transparent
The bounding rectangle of a displayed map element is the smallest rectangle in device coordinates (DC) that completely contains the element, taking its style into account. The style of an element influences the bounding rectangle displayed. For example, a thick polygon border will increase the size of the bounding rectangle, and the size of a point symbol will determine the size of the bounding rectangle on display, and so forth.
The following code example shows how to obtain the bounding rectangle of a displayed map element:
K2DElement element = ...
View view = ...
VectorLayer layer = ...
Rectangle displayBounds = element.getDisplayBounds(view.getTransform(), layer.getStyle(element, view.getScaleFactor()));
Note that the getDisplayBounds method takes the transformation of the view (refer to Coordinate Systems) and element style as parameters.
The map elements of vector layers can be selected. A variety of tools allow the user to select elements in the vector layers of a JMap project.
The K2DElement class has a property called selected that indicates whether or not an element is selected. Selected elements are displayed using a different style, which is the selection style of the vector layer.
Vector layers manage the list of their selected elements. The API of the VectorLayer class offers several methods related to selecting elements. See Layers and Layer Manager for more information on this topic.
The following source code example shows how to select and unselect elements.
K2DElement element = ...
VectorLayer layer = ...
// add the element to the current selection
layer.addToSelection(element);
// test if element is selected, useless, just to demonstrate boolean
isSelected = element.isSelected();
// cycle through selection
Collection selection = layer.getSelection();
for (K2DElement element : selection)
System.out.println(element));
// unselect element
layer.unselectElement(element);
// clear layer selection
layer.clearSelection();
Styled elements (K2DStyledElement class) are special map elements. They have their own style and they ignore the style of the layer that contains them when they are displayed. They are useful when programmatically adding elements to the map that have their own style. Aside from this difference, styled elements behave exactly like any other map elements.
The following coding example shows how to create styled elements.
K2DElement element = ...
Style style = ...
K2DStyledElement styledElem = new K2DStyledElement(element, style);
// element will use this style to draw itself
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 current horizontal distance of the view in world coordinates (WC).
Other
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.
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.
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.
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.
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.
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
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.
The following class diagram shows a simplified version of JMap Pro’s architecture.
When JMap Pro opens, a connection to the associated JMap Server is established. This connection is used to direct the various system requests, including requests to load the project configuration and data as well as .
Communication between a JMap Pro (desktop) application and JMap Server is done by exchanging requests and responses. The requests and the responses are in fact serialized objects that must normally be programmed, and these objects will contain the properties required to execute the request and return the information to the client. For example, an application managing citizen requests might have a request and response with the following properties:
Your extension should always check the status of a response before using it. If the status is not equal to JMapSRV_STS_SUCCESS, a special treatment should be done in order to manage the error situation. In this case, the getMessage() method allows you to generate a message explaining the cause of the error.
JMapSrvConnection jmapConn = JMapApplicationContext.getInstance().getConnection();
The following code example shows how to use the executeRequest method.
MyRequest request = new MyRequest("This is a test", 555);
JMapSrvConnection jmapConn = JMapApplicationContext.getInstance().getConnection();
MyResponse response = (MyResponse)jmapConn.executeRequest(request); // Execution WILL block here
if (response.getStatus() == MyResponse.JMAPSRV_STS_SUCCESS)
{
// Do something useful with the response
}
else
{
// Handle error here
}
The following code example shows how to use the pushRequest method.
MyRequest request = new MyRequest("This is a test", 555);
request.setClient(new JMapRequestClient()
{
// Will be called when the response is received from JMapServer
@Override
public void callback(JMapRequest request, JMapResponse response)
{
if (response.getStatus() == MyResponse.JMAPSRV_STS_SUCCESS)
{
// Do something useful with the response
}
else
{
// Handle error here
}
}
});
JMapSrvConnection jmapConn = JMapApplicationContext.getInstance().getConnection(); jmapConn.pushRequest(request); // Execution WILL NOT block here
JMap Pro applications are developed on a modular basis to simplify the addition of new features. Applications can be broken down into three levels, two of which are scalable to allow for programming additional features.
The first level is the entry point of the application ( class), which covers the type of application (applet, Java Web Start or standalone Java) and instantiates the application class (instance of the class) to be used. The second level is the JMap Pro application; it is driven by its abstract class, , which provides all the services required to ensure its proper operation. Since the class does not provide the application’s graphical interface, it is necessary to instantiate a class that inherits the JMapApplication class and that will instantiate the application’s graphical components, including the layer hierarchy and button toolbars. The DockingClient class, included in this SDK, is a good example of a JMap Pro application. The third level is for JMap extensions. JMap Pro applications allow you to develop and use extension classes ( class) to add new features to applications. JMap Pro extension development is explained in the following .
When the application is initialized, a connection with JMap Server is established based on the application parameters that have been specified. Communication with the server is unidirectional and allows for exchanging messages using requests and responses. The details of this communication are explained in this .
The following tables present the keys of JMap Pro’s GUI components. These keys are used to control these components through programming, notably in the methods of the JMapGuiService class.
There are several ways to allow communication between a JMap Pro application and another client application, also called an external application.The external application is an application running locally on the same computer as JMap Pro. We are not talking here of web applications (HTML, javascript), but rather client applications. The JMap Socket extension provides this communication in a simple and effective way.
The Socket extension is a generic extension that allows a bidirectional socket communication between external applications and JMap Pro extensions. This extension does not directly process the messages. Its role is limited to providing communication. Here is a typical scenario describing the use of this extension:
An external application sends the identifier of an element to JMap and it is automatically located and selected on the map. Conversely, the user clicks on a map element, and JMap sends the ID of the element to the external application, which displays a form with the properties of the element.
To communicate, external applications and JMap extensions send messages that are in fact byte arrays. The contents of these byte arrays is interpreted on either side. The Socket extension does not interpret their content.
The external application always connects to JMap first. It does so by opening a socket to the port configured in the Socket extension. Thereafter, the external application will once again initiate communication. This first contact is a special communication called a handshake. During the handshake, the external application indicates its unique identifier (a character string identifying the application).
As for the JMap extension that wants to communicate with the external application, it must register with the Socket extension. It must provide the same identifier as the external application. This is the identifier that links the two.
Subsequently, the external application and JMap extension can send each other messages in any direction. Each party (the external application or extension) is responsible for interpreting the messages and taking the appropriate actions.
Optionally, the Socket extension can launch the external application if it does not respond. Once it is launched, the external application may initiate communication as described above.
The code examples that follow are written in Java . An external application programmed in another language should implement the same logic, in that application’s language.
Opening a socket using IP address 127.0.0.1 and port 12351):
Socket socket = new Socket(“127.0.0.1”, 12351);
Sending a handshake message
The handshake message is received and interpreted by the Socket extension only. Note that the number of bytes of the message must precede the contents of the message. The message is sent as a byte array. The character encoding (charset) of this message is defined in the configuration of the Socket (socket.properties file) extension.
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
String handshake = "handshake:MyIdentifier";
dos.writeInt(handshake.getBytes().length);
dos.write(handshake.getBytes());
dos.flush();
Sending other messages
Subsequent messages are sent the same way as the handshake message, however, they will be received and interpreted by the extensions registered with the same identifier. Extensions that receive messages must therefore be able to understand the content of messages and perform the corresponding actions. The character encoding of the message is free and must be agreed to by the extension and the external application.
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
String message = "locate :id=333";
dos.writeInt(message.getBytes().length);
dos.write(message.getBytes());
dos.flush();
Receiving messages from JMap
Receiving messages is done using the same socket as for sending. The length of the message is read first, followed by the byte array of the message. Message reception should be done asynchronously, in a separate thread.
DataInputStream dis = new DataInputStream(socket.getInputStream());
int length = dis.readInt();
if (length > 0)
{
byte[] messageBytes = new byte[length];
dis.readFully(messageBytes);
}
The following example shows how to register a JMap extension with the socket extension to be notified when a connection or disconnection occurs and when messages from the external application are received. This code could be placed in the init() method of the JMap extension.
SocketClientExtension.register(new SocketClient()
{
@Override
public void socketMessageReceived(byte[] bytes)
{
String data = new String(bytes /*, Charset.forName("ISO-8859-5")*/);
// Interpret content of data…
}
@Override
public void socketConnectionOpened()
{
}
@Override
public void socketConnectionClosed()
{
}
@Override
public String getIdentifier()
{
return "MyIdentifier";
}
@Override
public String getExecutable()
{
// Optional - return null if not needed return "c:/external_app.exe";
}
});
The following example shows how to send a message to the external application from the JMap extension.
String message = "openform: id =99";
byte[] bytes = message.getBytes();
SocketClientManager.getInstance().sendMessage("MyIdentifier" , bytes);
Java applets are executed in the environment of a web browser. Therefore, they can interact, in both directions, with the javascript code in the web page that contains the applet. This communication allows you to create HTML interfaces to control the map and perform simple integrations with other applications running in the environment of the web browser. This does not apply to JMap Pro applications deployed with the JavaWebStart method (not in a web browser) because no web page is involved in these cases.
The following sample web page is a normal startup page for a JMap Pro applet to which javascript functions have been added (pan and zoom). Hyperlinks are also used to call these functions. When triggered, the functions call the JMap API to control the map.
The JMap Pro application has a getApplicationContext() method that is used to access all the components of the application.
<%@page contentType="text/html;charset=ISO-8859-1"%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String parameters = null;
if (username != null && username.length() != 0)
{
parameters = "?username=" + username;
if (password != null)
parameters += "&password=" + password;
}
%>
<html>
<head>
<title>
aa
</title>
<script src="library/deployJava.js"></script>
<script src="library/jmap.js"></script>
</head>
<BODY BGCOLOR="#ffffff" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<script>
function zoom(factor)
{
document.jmap.getApplicationContext().getViewManager().getActiveView().zoom(factor);
document.jmap.getApplicationContext().getViewManager().getActiveView().refresh();
}
function pan(x, y)
{
document.jmap.getApplicationContext().getViewManager().getActiveView().pan(x, y);
document.jmap.getApplicationContext().getViewManager().getActiveView().refresh();
}
</script>
<a href="javascript:zoom(2.);">Zoom in</a>
<a href="javascript:zoom(0.5);">Zoom out</a>
<a href="javascript:pan(0, 200);">Pan north</a>
<a href="javascript:pan(0, -200);">Pan south</a>
<a href="javascript:pan(200, 0);">Pan west</a>
<a href="javascript:pan(-200, 0);">Pan east</a>
<script>
var attributes =
{
name: "jmap",
codebase: "http://127.0.0.1:8080/aa",
code: "com.kheops.jmap.client.application.JMapApplicationLauncher",
archive: "dockingClient.jar,jmap_application.jar,jmap_client.jar,jmap_client_images.jar,jmap_projections.jar,jmap_symbols.jar,custom_symbols.jar,jmap_metadata.jar,jmap_net.jar,jmap_spatial.jar,kheops_ui.jar,kheops_util.jar,gif4j_pro_2.0.jar,jide-action.jar,jide-common.jar,jide-components.jar,jide-dock.jar,jide-grids.jar",
width: "100%",
height: "100%",
mayscript: true,
separate_jvm: true,
parameters: "-appclassname jmap.viewers.docking.AppDocking -project "The World" -directport 7003 -httpport 8080 <%= username != null ? username : "" %> <%= password != null ? password : "" %> -proxypath /aa/servlet/jmapproxy -serverid "aa" -maxmemory 33554432 -connection direct -donotlistusers false -showconnectionmoredetails false true "
};
var parameters = {fontSize:16, jnlp_href:'dockingClient.jnlp'} ;
deployJava.runApplet(attributes, parameters, '1.6.0_10');
</script>
</body>
</html>
From a JMap Pro applet, it is possible to call javascript functions that are in the web page containing the applet. This allows for interaction between the JMap Pro application and its HTML environment. For example, it would be possible to select an item on the map and display its information in an HTML page.
To enable this java-javascript communication, the mayscript: true parameter must be specified in the attributes used to start the applet, as shown in the following example.
<script>
var attributes =
{
name: "jmap",
codebase: "http://127.0.0.1:8080/aa",
code: "com.kheops.jmap.client.application.JMapApplicationLauncher",
archive: "dockingClient.jar,jmap_application.jar,jmap_client.jar,jmap_client_images.jar,jmap_projections.jar,jmap_symbols.jar,custom_symbols.jar,jmap_metadata.jar,jmap_net.jar,jmap_spatial.jar,kheops_ui.jar,kheops_util.jar,gif4j_pro_2.0.jar,jide-action.jar,jide-common.jar,jide-components.jar,jide-dock.jar,jide-grids.jar",
width: "100%",
height: "100%",
mayscript: true,
separate_jvm: true,
parameters: "-appclassname jmap.viewers.docking.AppDocking -project "The World" -directport 7003 -httpport 8080 <%= username != null ? username : "" %> <%= password != null ? password : "" %> -proxypath /aa/servlet/jmapproxy -serverid "aa" -maxmemory 33554432 -connection direct -donotlistusers false -showconnectionmoredetails false true "
};
var parameters = {fontSize:16, jnlp_href:'dockingClient.jnlp'} ;
deployJava.runApplet(attributes, parameters, '1.6.0_10');
</script>
To call a javascript function from your Java code (possibly your JMap extension), you must use the JSObject API, as shown in the following example.
JSObject w = JSObject.getWindow((Applet)appContext.getRootPaneContainer());
w.eval("show_form(" + id + ");");
In this example, the getWindow method receives the instance of the applet as a parameter. The getRootPaneContainer method of the JMapApplicationContext class returns the top level container of the application, the latter being the instance of the Applet when the application is running inside the web browser.
The javascript function to be called and its parameters are taken as parameters by the eval method. In this example, an ID is passed to the javascript function.
JMap Server extensions are modules developed in Java that are added to JMap Server to respond to new types of queries and perform tasks on the server side. Server extensions can contain configuration interfaces that are integrated to the Extensions section of JMap Admin. Often, a server extension works with a client extension.
To develop a server extension and make it available, you must perform the two following steps:
Develop an extension by creating a Java class that implements the interface.
(Optional) Develop a JMap Admin configuration interface for your extension.
Deploy your extension in JMap Server.
See the following sections for more information.
The first step towards developing a JMap Server extension is to write a class that implements the interface. This interface includes the following 3 methods, which are called at different moments in the life cycle of the extension:
To do its job, your extension can use the services offered by JMap Server. This includes spatial data extraction, access to relational databases connected to JMap Server, access to the system log (log files), etc.
For more information on the services offered by JMap Server, see the section.
The various versions of the log method are used to store messages, depending on the type of information to be recorded.
The following table shows the most commonly used methods of the Logger class.
LEVEL_DEBUG
LEVEL_INFO
LEVEL_WARNING
LEVEL_ERROR
LEVEL_FATAL
The following code example shows how to log a message with the various methods.
// Logs a message of level INFO
Logger.getInstance().log(Logger.LEVEL_INFO, "Extension ABC recieved a request for ...");
// Logs a message of level WARNING, tagged to user etardif
Logger.getInstance().log(Logger.LEVEL_WARNING, "Something occurred in Extension ABC ...", "etardif");
// Logs a message of level ERROR, and includes the exception stack trace
Exception e = ...;
Logger.getInstance().log(Logger.LEVEL_ERROR, "An unexpected error occurred in Extension ABC ...", e);
The connections to the relational databases that JMap Server is connected are available through programming. This greatly simplifies data access because you do not need to open, close and manage the connections to these databases.
JMap Server manages database connections in connection pools. These pools function as follows: when a connection is required, it is borrowed from the pool. It is then used briefly to execute one or more queries. Lastly and most importantly, the connection is returned to the pool and is once again available for other needs. Thus, connections are never closed.
The following source code example shows how to use a pool of connections to databases.
DatabaseConnectionPool pool = JMapServer.getInstance().getDBConnPool("parcels");
Connection conn = null;
try
{
conn = pool.borrowConnection();
// use connection to do queries.....
}
catch (SQLException e)
{
e.printStackTrace();
} finally
{
// It is very important to return the connection to the pool.
// Doing it in a finally clause is a good practice
if (conn != null)
pool.returnConnection(conn);
}
To extract data, you can also use filters. Filters are objects that control what data must be extracted based on various criteria.
The following source code example shows how to extract spatial data using a spatial filter.
JMapServerProject serverProject = ...
JMapServerVectorLayer serverLayer = ...
Polygon region = ...
final JMapServerDataManager dataMgr = JMapServer.getInstance().getDataManager();
// Create a new spatial filter for all elements that intersect the polygon
final SpatialQueryFilter newFilter = new SpatialQueryFilter();
newFilter.setGeometry(region);
newFilter.setType(SpatialQueryFilter.SPATIAL_OP_INTERSECTS);
// Set the projection on the filter to indicate the coordinate system of the geometry
newFilter.setProjection(serverProject.getProject().getMapProjection());
// Do the extraction using the data manager. All attributes of the layer will be included
JMapGeoElement[] result = dataMgr.extractElements(serverProject, serverLayer,
new QueryFilter[]{newFilter},
serverLayer.getBoundAttributes() );
String to = "jo32@gmail.com;ann122@hotmail.com";
String from = "admin@123map.com";
try
{
MailService.sendMail(MailService.toAddresses(to), "Map extraction completed", "The data was extracted successfully and is available here.", new InternetAddress(from));
}
catch (AddressException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
The following code example shows how to access the user who initiated a query.
public JMapExtensionResponse processRequest(JMapExtensionRequest request)
{
int sessionId = request.getSessionId();
User user = JMapServer.getInstance().getSessionManager().getSessionUser(sessionId);
System.out.println("##### Request originating from user: " + user.getName() + " (" + user.getFullName() + ")");
...
}
The following table shows the most useful methods of the UserManager class.
In JMap, workspaces are spaces used for individual storage of user data. Each workspace is actually a separate subdirectory of JMap Server. The workspaces are used to store contexts created by users. As a programmer, you can use them to store data.
To be deployed in JMap Server, server extensions must follow certain rules. If these rules are met, the extension appears in the Extensions section of JMap Admin.
Group extension classes in an archive (JAR)
All the classes of the extension must be contained in a single JAR archive file. Use a meaningful and unique name.
Include a manifest file
The extension archive must include a manifest.mf file with the following entries:
Here is an example of the contents of a manifest file:
extension_class: jmap.extensions.tracking.server.TrackingExtension
extension_name: Tracking
extension_request: jmap.extensions.tracking.common.TrackingRequest
extension_response: jmap.extensions.tracking.common.TrackingResponse
extension_version: 5.0.0010
Place the file in the correct directory
The JAR file of the extension must be placed in the server extensions directory (JMAP_HOME/extensions).
(Optional) Place the files from the configuration interface of the extension in the appropriate directory
The files that make up the configuration interface (JSP pages) must be copied to the directory used for this purpose (JMAP_HOME/jmapadmin/extensions).
Each server extension may include a configuration interface integrated to JMap Admin. Using this interface, JMap administrators can configure the operational parameters of your extension (e.g. security, database connectivity, a layer selection, etc.). Note that this interface is completely optional.
This interface consists of one or more JSP pages. The main JSP page (which is called first) must absolutely have the same name as the extension class. For example, if the class name of the server extension is
jmap.extensions.tracking.server.TrackingServerExtension
then the main JSP page must be
jmap.extensions.tracking.server.TrackingServerExtension.jsp
For more information on programming these JSP pages, refer to the examples included in the SDK.
The JMap Pro application takes certain parameters when it is started up. These parameters specify the address of the JMap Server, the communication ports, the project to open, and many other options.
Parameters are passed to the application in various ways, depending on its starting mode. Java and JavaWebStart applet parameters are passed in the application’s JNLP file. Application parameters are passed to the command line or can be specified in an Ant script.
The following example shows the parameters passed to the command line to start a JMap Pro application that opens the project The World and loads the extension Showcase.
-appclassname jmap.viewers.docking.AppDocking -server jmap3.k2geospatial.com -directport 7003
-project "The world" -extensions jmap.examples.showcase.extension.ShowCaseClientExtension
The following table describes the various parameters:
Layers ( class and its related classes) are highly important in JMap programming. They contain and manage the map data displayed on the map ( class). There are two main types of layers: vector layers ( class), which contain vector data, and raster layers ( 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 . 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 ( and 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 ( 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 ( class), which will then be loaded in the 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 ( and 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.
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 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.
Layer layer = ...
layer.addLayerEventListener(new LayerEventListener()
{
@Override
public void layerSelChangedEventOccurred(LayerSelChangedEvent e)
{
// TODO
}
...
});
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.
Two coordinate systems are used in JMap Pro programming: the WC or World Coordinates system and the DC or Device Coordinates system. The WC system is the system used for the original data and the DC system is used for the screen that will display the map.
All the geometry coordinates in JMap are in WC. For example, if your data uses the MTM zone 8 projection, the values of the coordinates will be similar to (300 000, 5 000 000). If your data is not projected, it will be in longitude and latitude and its range will be from -180 to 180 degrees east-west and from -90 to 90 degrees north-south
The computer screen used to display the map is divided into pixels with the coordinates (0,0) showing on the top left part of the screen. This is the DC system. When you are working with mouse-clicked events (i.e., MouseClicked) in a JMap application, you are working with DC coordinates contained in the event and expressed in pixels.
In JMap programming, WC coordinates must frequently be transformed into DC and vice-versa. When the map elements of a layer are drawn on the screen, their coordinates are converted from WC to DC on the fly in order to light up the appropriate pixels on the screen. However, when a mouse click occurs on the map, the DC coordinates of the mouse cursor are transformed into WC coordinates in order to select the appropriate element on the map.
The following source code example demonstrates how to transform WC coordinates into DC.
K2DTransform transform = ...
Point pointWC;
Point pointDC;
// Transform a point from WC to DC
pointWC = new Point.Double(100., 100.);
pointDC = transform.transform(pointWC);
// Transform a point from DC to WC
pointDC = new Point.Double(100., 100.);
pointWC = transform.transformInv(pointDC);
The following source code example demonstrates how to transform DC coordinates resulting from a mouse click event to WC. The transformation is obtained from the view.
View view = ...
K2DTransform transform = view.getTransform();
MouseEvent e = ...
Point pointWC = transform.transformInv(new Point.Double(e.getX(), e.getY()));
Point pointWC = Tool.toWCPoint(e);
Rectangle transformations (normal or inverted) must be performed with caution: if a rotation is applied to a view, the rectangle that is returned could be overwritten. To prevent this problem, it is preferable to make calculations on an oriented rectangle initialized from the rectangle to be transformed.
View view = ...
final ViewState viewState = view.getViewState();
// Computes the display bounding box of the selection
final Rectangle displaySelectBounds = view.getLayerManager().getDisplaySelectedBounds(viewState, true);
if (displaySelectBounds != null)
{
// Transforms the display bounding box into a WC extent.
final OrientedRectangle selectBounds = viewState.getTransform().transformInv(
new OrientedRectangle.Double(displaySelectBounds)
);
view.zoom(selectBounds);
view.refresh()
}
JMap Pro extensions are modules developed in Java that can be added to JMap Pro to enhance its features. Extensions are specified as parameters for applications and are initialized when said applications are launched. Typically, extensions are integrated to the GUI of a JMap Pro application by inserting the buttons and menus that activate the functions provided by the extension.
To develop an extension and make it available to users, you must perform the following two steps:
Develop your extension by creating a Java class derived from the class;
Deploy your extension in JMap Server so it may be accessed by the JMap Pro applications.
See the following sections for more information.
To program JMap Pro extensions, it is important to follow a set of simple rules. This section describes these programming rules.
The first step towards developing a JMap Pro extension consists of programming a class derived from the abstract class . This class contains the following 3 methods, which are called at different moments in the life cycle of the extension:
Parameters are passed to the extension with the init() method, using a Map<String, String> collection. In JMap, there are two predefined parameters that match constants defined in the class:
EXTENSION_PARAMETER_GUI_VISIBLE: Indicates whether the extension’s GUI components (other than toolbars) must be visible when the application is launched.
EXTENSION_PARAMETER_TOOLBAR_VISIBLE: Indicates whether the extension’s toolbars must be visible when the application is launched.
These parameters contain true or false values and they are set by the JMap Administrator when a JMap Pro application is deployed. Your extension must comply with these parameters. An extension can also receive its own settings, which would be set by the JMap Administrator.
The following code example shows how to access the settings from the init() method.
public void init(JMapApplicationContext appContext, Map<String, String> mapExtensionParameters)
{
String param = mapExtensionParameters.get(JMapClientExtension.EXTENSION_PARAMETER_TOOLBAR_VISIBLE);
boolean toolbarVisible = Boolean.parseBoolean(param);
...
}
Most commonly used methods of the JMapApplication class:
As a developer of JMap Pro extensions, you will probably be developing applications that need to communicate between the client side and JMap Server. Whether you need to communicate with your own extension on the server side or to make general requests to JMap Server, the programming principle is the same.
To create your request class, you must observe the two following rules:
All of the class’s properties must be serializable.
You are free to add all the properties and methods that are useful to executing your request. These properties and methods can be used by your extension on the server side.
The following source code example demonstrates how to program a simple request.
// This request is used to save a new citizen complaint
public class SaveComplaintExtensionRequest extends JMapExtensionRequest
{
private String citizenName;
private int requestType;
public void setCitizenName(String citizenName)
{
this.citizenName = citizenName;
}
public String getCitizenName()
{
return this.citizenName;
}
public void setRequestType(int requestType)
{
this.requestType = requestType;
}
public int getRequestType()
{
return this.requestType;
}
}
To create your response class, you must observe the two following rules:
All of the class’ properties should be serializable.
You are free to add all properties and methods that are useful to returning the information regarding the request’s execution to the client. These properties and methods can operate from the client side by your extension after the request is executed on the server.
The following source code example demonstrates how to program a simple response.
// This response is returned to client after a citizen complaint save request was executed
public class SaveComplaintExtensionResponse extends JMapExtensionResponse
{
private long uniqueId;
public void setUniqueId(long uniqueId)
{
this.uniqueId = uniqueId;
}
public long getUniqueId()
{
return this.uniqueId;
}
}
Your extension should always check the status of a response before using it. If the status is not equal to JMapSRV_STS_SUCCESS, a special process must occur in order to manage the error. In this case, the getMessage() method allows you to generate a message explaining the cause of the error.
Some client extensions can be completely invisible to the user but the majority of extensions are integrated into the JMap Pro GUI. This integration can take many forms. The initGui() method must be used to initialize the graphical interface of an extension.
The main methods of the JMapGuiService class are listed below:
// This button will be in a group thus only onebutton can be pressed among this group.
AbstractButton button = guiFactory.createToggleButton(new ButtonAction(),
appContext.getApplication().getGuiService().getMainButtonGroup());
// Add the button on the Zoom and Pan toolbar.
appContext.getApplication().getGuiService().getToolBar("ZOOM_PAN").add(button);
The following code example shows how to create a toolbar using the JMapGuiFactory class. In this example, the JMapApplicationActionManager class is used to access the buttons’ actions. This class can manage single instances of actions. Afterwards, two buttons are created and added to the bar. Finally, the toolbar is added vertically, on the right side of the application. Notice the HashMap of properties that is used to place the toolbar. This principle is used with all components to specify their characteristics.
// Create the new toolbar final ToolBar
toolBar = guiFactory.createToolBar("SHOWCASE", "JMap example showcase");
// Create and add buttons on toolbar
toolBar.add( guiFactory.createToggleButton(applicationActionManager.getAction(CreatePolygonAction.class), jmapGuiService.getMainButtonGroup())
);
toolBar.add( guiFactory.createButton(applicationActionManager.getAction(ShowDockingPanelAction.class))
);
// Adds the new toolbar vectically to the right side of the application frame.
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("CONTEXT_INIT_SIDE", new Integer(SwingConstants.EAST)); // Dock to the east
jmapGuiService.addToolBar(toolBar, properties);
// Create a panel with the needed components
final JPanel panel = new JPanel();
...
// Set the properties of the dockable panel.
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("KEY", COMPONENT_KEY); // Will be used to reference the panel
properties.put("TITLE", "JMap 7 SDK showcase."); // Will be displayed on the title bar
properties.put("CONTEXT_INIT_SIDE", SwingConstants.EAST); // Tells JMap to dock the panel to the east of the frame
appContext.getApplication().getGuiService().addDockableComponent(panel, properties);
The following code example shows how to create and add a menu to the interface.
// Create menu and add items to it
JMenu menu = new JMenu("SDK");
JMenuItem item1 = new JMenuItem("Item 1");
JMenuItem item2 = new JMenuItem("Item 2");
this.menu.add(item1); this.menu.add(item2);
// Add menu to menu bar at position 4
appContext.getApplication().getGuiService().getMenuBar().add(menu, 4);
// Add 2 menu items to existing menus TOOLS and HELP
JMenuItem item3 = new JMenuItem("Item 3");
JMenuItem item4 = new JMenuItem("Item 4");
appContext.getApplication().getGuiService().addMenuItem("TOOLS", item3, false);
appContext.getApplication().getGuiService().addMenuItem("HELP", item4, false);
The following code shows how to add a section of items to the map’s pop-up menu. This menu appears when the user right-clicks on the map. In addition, the menu item is only active if the user has clicked on at least one element of a map layer. Otherwise, the menu item will be disabled.
final ViewMenuAction menuAction = new ViewMenuAction();
// Obtain the currently active view
View view = JMapApplicationContext.getInstance().getViewManager().getActiveView();
if (view != null)
{
// Add a separatr and a menu item
view.addPopupMenuSeparator();
view.addPopupMenuAction(menuAction);
}
// Register an event listener with the View Manager so that we are notified when the view popup menu is about to be displayed
JMapApplicationContext.getInstance().getViewManager().addViewEventListener(new ViewAdapter()
{
@Override
public void viewPopupMenuShowing(ViewPopupMenuShowingEvent e)
{
// Enable map menu item only if the user clicked on some element
K2DElement[] elements = e.getView().getLayerManager().getElementsAtPoint(e.getWcCoord(), e.getView().getViewState(), false);
menuAction.setEnabled(elements.length > 0);
}
});
Abstract methods of the AbstractLayerSettingsCustomPage class:
// Obtain a reference to the ShowLayerSettingsAction
instance ShowLayerSettingsAction showLayerSettingsAction = (ShowLayerSettingsAction)appContext.getApplicationActionManager()
.getAction(ShowLayerSettingsAction.class);
// Add the custom panel for the Cities layer
showLayerSettingsAction.addLayerSettingsCustomPage(SDKLayerSettingsPanel.class.getName(), layerCities.getId());
You can add buttons associated with a layer in the layer manager. These buttons can be used to trigger custom actions that are specific to a layer. The buttons are added in different ways in the hierarchical section and list section.
The following source code example shows how to add a button to the Cities layer.
// Obtain layer instance from layer manager
Layer layerCities = appContext.getViewManager().getLayerManager().getLayer("Cities");
JMapGuiService guiService = appContext.getApplication().getGuiService();
JMapGuiFactory guiFactory = guiService.getGuiFactory();
AbstractButton abstractButton = guiFactory.createButton(new ButtonAction());
// Add the button to the 'More options' of the LayerTreeBar (hierarchy) for the layer Cities
guiService.getLayerTreeBar().addCustomButton(abstractButton, layerCities.getId());
// Add the button to the LayerPanel of the LayerBar (list) for the layer Cities
LayerPanel layerPanel = guiService.getLayerBar().getLayerPanel(layerCities.getId());
Button button = new Button(new ButtonAction(), false, new Dimension(18, 18));
layerPanel.addCustomButton(button);
To be deployed within JMap Pro applications, client extensions must follow certain rules. If these rules are met, the extension appears in the deployment section of JMap Admin.
Group extension classes in an archive (JAR)
All classes and resources (images, etc.) of the extension must be contained in a single JAR archive file. Use a meaningful and unique name, as this name will be used in the following steps.
Include a manifest file
The extension archive must include a manifest.mf file with the following entries:
Here is an example of a manifest file's content:
extension_class: jmap.extensions.edition.EditionExtension
extension_name: Edition
extension_version: 1.0.0049
Provide a JNLP file
The JNLP file is required. It describes the deployed library. The file must have the same name as the extension's JAR file (except for the .jnlp extension). The following example shows the parts that must be changed in bold.
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for Extension libraries -->
<jnlp
spec="1.0+" codebase="http://$JMAPSERVER_HOST$:$JMAPSERVER_WEBPORT$$PATH$/edition_client"
href="edition_client.jnlp">
<information>
<title>Edition Extension</title>
<vendor>K2 Geospatial</vendor>
<description>Edition Extension</description>
<description kind="short">Edition Extension</description>
</information>
<security> <all-permissions/> </security>
<resources> <jar href="edition_client.jar"/> </resources>
<component-desc/>
</jnlp>
Place the files in the correct directory.
All files that make up the extension (JAR, JNLP, and other files) must be placed in a directory created specifically for the extension and located within the directory for Client Extensions (JMap_HOME/extensions/client). The name of the extension's directory must be identical to the name of the extension's JAR. The following image shows how files and directories are organized in Windows for K2 Geospatial's Edition extension.
The signature of a Java library certifies that the library comes from an identifiable source and that its content has not been altered. The user who executes the library’s code can trust the authenticity of the library. This is even more important when the library requires system access that can cause security issues such as data access, network access, etc.
The Java API documentation for JMap 7 is available online at .
Returns the instance of the class associated with this view. See below for more information on this topic.
Returns the instance associated with the view.
Returns the map projection () of the data on the map.
Returns the unit () of the data on the map.
Sends an image of the map by email to the recipients defined in the type object passed as a parameter.
For more information, refer to the section.
Every response has a status that indicates if the request was executed successfully or if a problem occurred. The getStatus() method of the class allows you to get the status of the response. For the list of possible statuses and their description, refer to the documentation of the class.
The class is responsible for all communication between JMap client and JMap Server. The connection instance can be accessed using the JMap application context, as shown in the following example.
The following methods (inherited from the class) are used to send requests to JMap Server and to receive the responses.
When initializing the application, all useful instances that define the application’s execution context are stored in a singleton of the class.
The Socket extension provides a standard means of communication allowing JMap extensions to communicate with external applications. External applications are applications running locally on the same computer as JMap Pro. These applications can be written in any programming language (Java, C + +, Windev, C #, VB.NET, etc.). Note that web applications (HTML, javascript, etc.) are not supported by this integration method. Other methods are better suited to web applications (see ).
You must implement a class derived from the class. This class provides your extension with all the information it needs to perform its work. Requests are typically initiated on the client side and passed to JMap Server for processing by your extension. In this class, you can include all the required properties, but make sure these are all serializable.
When your extension is initialized, the type of your query (full class name, including package) is associated with your extension. This way, when JMap Server receives this type of query, it is automatically directed to your extension (processRequest method). For more information on how to make the connection between your query and your extension, refer to the section.
For more information on programming requests, refer to the section.
You must also implement a class derived from the class. This class is intended to provide information resulting from the execution of your query. The processRequest method of your extension must return an instance of this class. Depending on the nature of the query, the response may either return a large amount of information or just a query execution status (success, failure, etc.). You can include all the required properties in your class, but make sure they are all serializable.
For more information on programming responses, see the section.
The class is the main class from which you can access JMap Server’s various services. This class is a singleton. You can therefore access it from anywhere using the static method JMapServer.getInstance().
JMap Server’s home path is accessed using the static method of the class. It can be useful to know this path when you wish to read or write data in JMap Server’s subdirectories.
The JMap Server logging tool can record events in log files. The tool’s class is and it is a singleton. Thus, you can access the single instance using the static Logger.getInstance() method.
The various message levels are defined by constants of the class.
The and methods allow you to get a connection pool (instance of the class) using its numeric ID or name.
The following table shows the most commonly used methods of the class.
Spatial data can be extracted using the JMap Server data manager ( class). The data manager can be accessed using the method of the class.
The following table shows the most commonly used methods of the class.
Filter classes are all derived from the abstract class . The following table shows all the types of filters that are available.
The static method of the class allows you to send emails from JMap Server. In order for the emails to be sent successfully, JMap Server must be connected to an SMTP server. This connection can be configured during the JMap installation or it can be defined in the Settings section of JMap Admin.
The JMap Server Session Manager ( class) is responsible for managing active sessions in the system. Among other things, it provides access to the user connected to a session by using the session ID. This session number is accessible from every request received by JMap Server, including queries destined to server extensions. The session manager can therefore be used to know the identity of the user who initiated a query.
The User Manager ( interface) provides access to the list of users and groups used by JMap Server for access control. It also allows you to access user information. If you develop a server extension that must manage its own list of permissions, it can be very useful to access the list of users that the system uses.
The method of the class returns the User Manager (class that implements the interface) being used.
The class contains the information on a user (full name, email address, etc.).
The method of the class allows you to access the workspaces manager ( class), which provides some useful methods related to worskpaces. By default, workspaces are located in the JMap_HOME / workspaces directory.
The following table shows the most useful methods of the class.
The 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.
The class is derived from the Layer class and contains only raster data. Its methods are rarely used by JMap application developers.
To receive the events of a layer, you must implement the interface and register it with the layer using the method, as shown in the following example:
There is also an adapter () that simplifies the development of the listener. The 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 class.
In JMap, each map ( class) has a layer manager ( 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.
To receive the layer manager’s events, you must implement the interface and register it with the layer manager using the method.
The class contains an affine transformation matrix used to convert data between the DC and WC systems. It provides methods to transform the coordinates in both directions. Each map in JMap ( class) has its own transformation instance.
The following source code example demonstrates how to transform DC coordinates using a mouse click event. This simple method is only available from a tool class derived from the class.
The class is very useful for extension development because it provides access to a set of general application resources. This class is a singleton. Therefore, the instance can easily be accessed from anywhere using the static method.
The class represents the JMap application. It offers methods that provide access to application resources (GUI, event logs, etc.). It also provides methods to perform tasks in a simple way (create a new map, close the project, etc.).
For more information on client-server communication in JMap, refer to the section.
The class should be derived from the class;
The class should be derived from the class;
Being derived from the class, your response class will inherit some useful properties, including the response status and an explanatory message in case of a problem.
Each response has a status that indicates if the request was executed successfully or if a problem occurred. The getStatus() method of the class allows you to get the status of the response. For the list of possible statuses and their description, refer to the documentation of the class.
The class is used to access the components of the graphical user interface (menus, toolbars, etc.) and to add or remove components. To simplify access to the graphical components, each component has a unique key. This key must be provided when a component is added or removed. For a complete list of available keys, see the section components. The JMapGuiFactory class described below provides methods for creating GUI components.
The class is used to create buttons, menus and toolbars that are compatible with JMap applications. Methods such as createButton (), createMenu (), createToolBar (), etc. are called to create the appropriate components.
The following code shows how to add a button to an existing toolbar. The toolbar is retrieved using its key. For a complete list of available keys, see section . Note that the action associated with the button is not shown in the example.
The method adds components such as windows to the interface. It takes a HashMap of key-value pairs as a parameter to define the display settings of the new window. All keys and possible values are defined in the method’s documentation.
The following code example shows how to add items to existing application menus. Note that a key is used to retrieve existing menus. For a complete list of available keys, see the section .
It is possible to add sections to the settings window of a layer, as shown in the image below. To do this, you must implement your own class derived from the abstract class and implement that class’s 3 abstract methods. You must provide a title and icon for your section by passing them to the constructor of the superclass; they will be displayed in the settings window.
The getLayer() method of the class lets you know to which layer the parameters apply. To save your settings section, you must use the method addLayerSettingsCustomPage of the ShowLayerSettingsAction class, as shown in the following source code example.
Signing Java libraries is done using the jarsigner tool included with the Java JDK. To do this, you must have a Java signing certificate issued for your organization. These certificates can be purchased from a reputable security company such as Thawte () or Verisign (). Once you have your certificate, you must import it in a keystore using the keytool, which is also included with the Java JDK. Note that the keytool can also produce development certificates. These certificates are not deemed to be from reliable sources and they will generate warning messages. However, they are helpful for development and in-house testing purposes. For more information on this topic, refer to the documentation on the Java JDK’s security tools ().
The libraries of JMap Pro extensions must be signed in order to be properly deployed in a JMap Pro application. If you use the provided with the JMap SDK, the Ant scripts generated handle the signing of your extension. Thus, when you run these scripts to compile and build the library for your extension, it is signed automatically. This signature is done using the development certificate provided with the SDK. If you want to use your own certificate, you must replace the JDK_HOME/tools/extensionbuilder/RES/keystore.jks file by your own keystore, in which you will have imported your certificate.
Sends the request passed as a parameter to JMap Server and returns the response generated by JMap Server or by a server extension. This is a blocking method. It is well suited to situations where one must wait for the server’s response before continuing.
Sends the request passed as a parameter to JMap Server. This method is non-blocking. When the response is received, the callback() method of the client of the request is called. This method is well suited to situations where one must quickly give back control to the user and when one can process the response in an asynchronous manner.
Toolbars
ZOOM_PAN
Toolbar containing buttons for zooming and panning.
SELECTION
Toolbar containing buttons for selection/deselection.
ROTATION
Toolbar containing buttons for rotation and cancellation of the rotation.
MEASURE_LABEL
Toolbar containing buttons for measuring, clearing measurements, labelling and clearing labels.
INFOS_SEARCH
Toolbar containing buttons for reporting and search tools.
PRINT_MAIL
Toolbar containing buttons for printing and emailing.
Menus
PROJECT
Projects menu containing items for loading projects, context management, personal layers management, etc.
VIEW
View menu containing items for controlling the display of the various components of the GUI such as the layer manager, overview, etc.
TOOLS
Tools menu containing the items of various tools and extensions.
MAP
Maps menu containing map window management items.
HELP
Help menu containing help topic items.
Windows
LAYERS
Map layer manager.
CONTEXTS
Contexts management window.
ELEMENTS_EXPLORER
Window containing the elements explorers of the layers.
SELECTION_EXPLORER
Window containing the selection explorer.
MESSAGES_VIEWER
JMap messages management window.
PERSONAL_LAYERS
Personal layers management window.
QUERIES
Spatial and attribute queries window.
GO_TO_COORDINATE
Window for entering coordinates to be reached on the map.
GEOMETRY_INFO_PANEL
Window to display geometric properties of map elements.
OVERVIEW
Map overview window.
Logs a message of the specified level.
Logs a message of the specified level associated with the specified user.
Logs a message of the specified level and the trace of the exception passed as a parameter.
Logs a message of the specified level, associated with the specified user, and the trace of the exception passed as a parameter.
Changes the level of the messages that will be recorded.
Borrows a JDBC connection from the pool. The connection is then reserved exclusively.
Returns a JDBC connection borrowed from the pool. It is very important to call this method after using a connection.
Provides the status of the connection pool. Can be called to validate that the pool is working correctly before borrowing a connection. The possible statuses are defined by constants of the ConnectionPoolInfo class (CONNECTION_NOT_TESTED, CONNECTION_ERROR or CONNECTION_OK).
Extracts the spatial data and attributes that pass the filters passed as parameters, for the specified of the specified project. Only attributes that are specified in the last parameter are included in the result.
Extracts spatial data and its attributes based on the query passed as parameters. The general syntax for queries is the following:
select element from $ $ source {$ {project} $ PROJECT_NAME layer layer_name {}} WHERE condition
Example:
select element from $ $ source {$ {project} The World Countries {$ layer}} Where COUNTRY = 'Peru'
Extracts spatial data and its attributes based on to the query passed as parameters and the list of identifiers specified. Only items whose identifier is in the list are returned.
Extracts spatial data and its attributes based on the query passed as parameters, the list of identifiers and the region specified. Only elements whose identifier is in the list and who intersect the region are returned.
Sets a condition based on a data attribute. The condition is defined by an attribute and a set of values. Only data for which the attribute has a value included in the set of values will pass the filter.
Sets a condition based on the type of data geometry. The condition is defined by one or more types of geometries. Only data with a geometry type matching the filter will pass the filter.
Sets a spatial condition. Only data meeting the condition will pass the filter. The condition is defined by a geometry and a constraint. For example: all geometries that intersect the specified polygon, all geometries that contain the specified point, etc.
Sets a condition in SQL. This is the equivalent of the where clause in an SQL query. The where clause is interpreted by the database system that contains the data.
Returns the user (instance of the User class) whose name is specified as a parameter.
Returns the group (instance of the Group class) whose name is specified as a parameter.
Returns the list of users (instances of the User class) used by JMap Server.
Returns the list of groups (instances of the Group class) used by JMap Server.
Returns the full path to the workspace directory for the user specified as a parameter.
Erases all the content of the workspace for the user specified as a parameter.
Clears the workspace directory of the user specified as a parameter.
Variable
Description
extension_class
Identifies the main class of the extension. This is the class that implements the JMapServerExtension interface.
extension_request
Identifies the class used as the query for this extension. This is the entry that will route requests to your extension. If your extension supports multiple classes of requests, they must all derive from this class.
extension_response
Identifies the class used as a response to this extension. If your extension supports several classes of responses, they must all be derived from this class.
extension_name
Specifies the name of the extension. This name appears in JMap Admin in the Extensions section.
extension_version
Specifies the version number of the extension. This information appears in JMap Admin in the Extensions section. The version number is used only to simplify the management of extensions.
Parameters (* = mandatory)
-appclassname *
Main class of the application to run. Currently, the only possible value is jmap.viewers.docking.AppDocking.
-server *
The name or IP address of the JMap server to which the application must connect.
-directport
IP communication port for direct connections with JMap Server.
-httpport
IP communication port for connections through HTTP proxy with JMap Server.
-project
The project that will open by default. Must be enclosed in quotes if the name contains spaces.
-language
Language of the application’s GUIs. Supported values are fr, en, es, pt, and default. The default value means that the language used will be the default language of the user’s operating system.
-country
The country, used with the language, to determine the display formats of dates and numbers.
-username
The username to log on to the application.
-password
The password to log on to the application.
-sessionid
Specifies the session number in order to connect to a session that is already open on the JMap server.
-autozoom
Instructs the JMap application to locate a position or element automatically upon startup. The syntax is: autozoom-REGION, x, y, width, height OR autozoom-OBJECT; <br />LayerName; <br />attribute, value OR autozoom-OBJECT; <br />LayerName; <br />attribute, value; <br />maxScale
-connection
Type of connection to use between the application and the JMap Server. Possible values are: - direct: Opens a direct connection to JMap Server using the direct port. - proxy: Opens a proxy HTTP connection to JMap Server using the HTTP port. - any: Attempts to open a direct connection. In case of failure, switches to connection through HTTP proxy.
-proxypath
If the connection type is HTTP-proxy, specifies a relative path to the HTTP proxy.
-serverid
If the connection type is HTTP-proxy, specifies on which JMap Server instance the connection must open when multiple instances of JMapServer are available. This way, the HTTP proxy can be used to direct the queries. Server IDs are configured in the jmsconnections.xml files.
-showconnectionmoredetails
Determines whether the login window should show the list of available projects on JMap Server. Possible values: true, false
-usediskcache
Determines whether the disk cache is enabled or not. Possible values: true, false
-diskcachepath
If the disk cache is enabled, determines the folder where the cached data will be saved.
-diskcachesize
If the disk cache is enabled, determines the maximum size of the total data cache. Data will automatically be deleted when the cache reaches the size limit. The value is expressed in bytes. A value of -1 indicates an unlimited size.
-usememorycache
Determines whether the memory cache is enabled or not. If the cache is enabled, the data in memory is handled in the following way: when the space becomes full, i.e. the cache reaches the size limit (-maxmemory parameter), data is automatically removed from the memory. The amount of data removed depends on the specified percentage (percentreleasememory parameter). Possible values: true, false
-maxmemory
If the in-memory cache is enabled, determines the maximum size of the data in memory.The value is expressed in bytes. The default value is 33554432 (32MB).
-percentreleasememory
Determines the percentage of memory to free when the cache becomes full. The percentage is based on the total size of the cache. The value is an integer between 1 and 100.
-logos
List of logos to show on the map as well as their position and transparency. Example -logos “? Jmaplogo.gif x = 5 & y = 5 & transparency = 30.0 & relativeTo = NE”
-northarrow
Display settings for a north arrow on the map, including the model, position, size, etc. Example -northarrow Simple3D, 0,50,5,5
-displayscalebar
Determines whether the scale bar must be displayed on the map. Possible values: true, false
-extensions
The list of extensions to initialize at application startup, separated by commas. Example -extensions jmap.extensions.googlemap.client.GoogleMapsExtension, jmap.examples.showcase.extension.ShowCaseClientExtension
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.
Main methods of the K2DTransform class
Creates a new oriented rectangle from the specified WC point and transforms it into a DC point.
Creates a new point from a WC point and transforms it into a DC point.
Creates a new rectangle from a specific WC rectangle and transforms it into DC.
Creates a new oriented rectangle from the specified DC point and transforms it into a WC point.
Creates a new point from a specific DC point and transforms it into a WC point.
Creates a new rectangle from a specific DC rectangle and transforms it into WC.
Returns the instance of the connection (JMapSrvConnection class) to JMap Server.
Returns the instance of the main application window.
Returns the instance of the View Manager (ViewManager class) of the application.
Returns the instance of the JMap application (JMapApplication class).
Returns the path to the main JMap folder on the user's computer. This is where JMap writes its data.
Creates a new map view that automatically appears in the application.
Returns the instance of the project (Project class) opened in the application.
Returns the instance of the application’s JMapGuiService class. See the GUI Integration section for more information.
Returns the instance of the application’s Logger class. Used to record messages from your extension in the JMap application’s logs.
Adds an item to an existing menu by specifying the menu key.
Retrieves a menu using its key. The returned object can then be used to modify the menu.
Adds a toolbar to a specific position in the application interface.
Retrieves a toolbar using its key. The returned object can then be used to modify the toolbar.
Adds a dockable window at a specific position in the application interface.
Allows you to remove a dockable window using its key.
Returns the JMapGuiFactory instance. This class allows you to create GUI components such as buttons and toolbars.
In this method, you must create and return the the instance of JPanel that displays the GUI of the settings in your section. This is the graphical interface that will be displayed.
This method is called when the user clicks on the OK button to confirm the changes and close the window. Your method should return true only if the parameters entered are valid. Otherwise, the window will refuse to close.
This method is called when the user clicks on the OK button to confirm the changes and close the window, and after calling the validateSetting() method. You must apply the parameter changes on the layer.
Variable
Description
extension_class
Identifies the main class of the extension, derived from the abstract class JMapClientExtension.
extension_name
Specifies the name of the extension. This name appears in JMapAdmin when deploying applications.
extension_version
Specifies the version number of the extension. This information appears in JMapAdmin when deploying applications. The version number is used only to simplify the management of extensions.
Most commonly used methods of the JMapApplication class
Adds a project listener in the application's list of listeners.
Removes a project listener from the application's list of listeners.
Creates a new view (View class) initialized with the current project in the application.
Returns the active project (Project class) in the application.
Returns the JMapGuiService instance to be used in order to access and manipulate the components of the application's GUI.
Returns an instance of java.util.Logger to perform logging in the application.
Returns the extension loaded (JMapClientExtension class) for the specified class name.
Returns the messaging controller (JMapClientMessagingController class) of the application.
Returns the edition transaction manager (EditionTransactionManager class) of the application.
Returns the user parameter controller (JMapUserParameterController class).
Returns the user parameter (UserParameter class) saved for the specified key.
Defines a user parameter to be saved.
This method is called when JMap Server is launched, when extensions are initially loaded or when the administrator requests to reset the extension from JMap Admin. It is used to initialize the extension. In this method, you can put any code used to prepare the operation of your extension. This could include loading a settings file, checking dependencies, etc.
This method is called when JMap Server receives a request destined to your extension. In this method, you must include the code needed to process the request. In addition, the method must return a response resulting from processing the request.
This method is called when JMap Server shuts down or when the administrator requests to reset the extension from JMap Admin. It is used to execute the code needed to close the extension. This could include closing files or connections to other systems.
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.
This method is called when the extension is loaded by the JMap Pro application. At this point, the graphical interfaces have not yet been initialized. In this method, you can put any code that will prepare the operation of your extension. This could include loading a settings file, verifying dependencies, etc. The method receives an instance of JMapApplicationContext as a parameter. This class provides access to all the resources of the JMap application. The method also receives a collection (map) of parameters. These parameters provide useful information for the extension. See below for more information.
This method is called by the JMap application when its graphical interface has been initialized. In this method, you should put the code that initializes the GUI of your extension. This could include adding buttons or toolbars, menus, windows, etc. See the GUI Integration section for more information. This GUI will allow users to access the functions offered by your extension.
This method is called by the JMap application just before it exits. In this method, you must put the code required to terminate your extension. This could include the code to release resources, save settings, etc.
A JMap tool provides interaction between the user and the map using the mouse. For example, when the user activates the selection tool and clicks on the map to select an item, it is the selection tool class that performs the work. This tool is programmed to make a selection at the location that is clicked on the map. Similarly, when the distance measurement tool is used, the tool class calculates and displays the distance between the 2 points clicked by the user. Thus, developing a JMap tool allows you to implement custom actions.
In general, only one tool at a time can be enabled. In order to be enabled, a tool must be the active tool in a JMap view. To do so, you must use the method setCureentTool(Tool) of the View or ViewManager class. Note that the method used to activate the tool, such as a button or a menu item, has no connection with the operation of the tool itself.
When the user changes the active the tool (e.g. by pressing a button), the code will essentially be as follows:
JMapApplicationContext.getInstance().getViewManager().setCurrentTool(new MyTool());
When a tool is active, it receives all the mouse events that are generated by the active view. The Tool class is responsible for processing these events and taking the appropriate actions.
To develop a new tool, you must program a class derived from the abstract class Tool and implement only the methods needed to perform the tool’s function. For example, if the tool must perform an action when the user clicks the mouse, you must implement the onToolClicked() method.
Tool class methods:
This method is called when the tool becomes the active tool of a view. The code for this method should be used as necessary to prepare the work of the tool. The view is passed as a parameter to this method.
This method is called by the view when the tool becomes active to allow your tool to provide its own mouse cursor. The cursor will be visible on the view as long as your tool remains the active tool.
This method is called when the user presses on one of the mouse buttons within the view.
This method is called when the user releases a mouse button within the view.
This method is called after the user has completed a mouse click within the view.
This method is called repeatedly when the user moves the mouse inside the view.
This method is called repeatedly when the user moves the mouse inside the view while keeping a button pressed.
This method is called when the tool becomes inactive, i.e. when another tool is activated on the screen. The code for this method could be used, as needed, to perform a termination action or to free up resources.
The following code example shows a simple tool that displays the properties of the first element found at the coordinates of the mouse cursor when the user presses and releases the left mouse button on the map. Only vector layers are considered and the search is performed from the highest layer to the lowest layer, in the layer display order. Other methods of the Tool class are not implemented because they are not required for the operation of this tool.
public class ElementInfoTool extends Tool
{
public void onToolReleased(MouseEvent e)
{
super.onToolReleased(e);
System.out.println("ElementInfoTool.onToolReleased");
// Obtain array of layers to cycle them in reverse order
final Layer aLayers[] = this.view.getLayerManager().getAllLayers();
// Get the layer visibility status from the layer manager (also includes the hierarchy visibility)
final LayerVisibilitySet layersVisibility = this.view.getLayerManager().getLayerTreeVisibility();
// Transform mouse x,y coordinate to WC coordinate
// Point wcCoord = view.getTransform().transformInv(new Point.Double(e.getX(), e.getY())); final Point wcCoord = toWCPoint(e); // method inherited from class Tool
final ViewState viewState = this.view.getViewState();
// Cycle through every layer in reverse order (from top position to bottom position) looking for an element under the x,y position.
for (int i = aLayers.length - 1; i >= 0; i--)
{
// Consider only vector layers
if (!(aLayers[i] instanceof VectorLayer))
continue;
final VectorLayer vectorLayer = (VectorLayer) aLayers[i];
// Layer must be visible, selectable and displayed at the current scale
if (layersVisibility.isVisible(vectorLayer.getId()) && vectorLayer.isSelectable() && vectorLayer.isDrawable(viewState.getScale()))
{
final K2DElement elem = vectorLayer.getElementAtPoint(wcCoord, viewState, true);
if (elem != null)
{
String message = "Selected element on layer " + vectorLayer.getName() + ":\n\n"
+ "Class:" + elem.getClass().getName() + '\n'
+ "Id: " + elem.getId() + '\n'
+ "Geometry: " + elem.getGeometry().getClass() + '\n'
+ "Display bounds: " + elem.getDisplayBounds(viewState, vectorLayer.getStyle(elem, viewState.getScale())) + '\n'
+ "Attributes:\n";
final Object[] attribs = elem.getAttributes();
final Attribute[] attribDefinitions = vectorLayer.getAttributeMetaData();
for (int j = 0; j < attribs.length; j++)
{
message += " " + attribDefinitions[j].getName() + " : " + attribs[j] + '\n';
}
JOptionPane.showMessageDialog(this.view, message);
break;
}
}
}
}
}
You can implement tools to draw on the map simply by deriving them from existing JMap classes for drawing tools.
By deriving from these classes, all the basic operations are inherited. The following options are available:
Persistent and volatile modes (determines whether items are created);
Select the layer that will receive the items drawn;
Style parameters of drawn elements (colors, line types, etc.);
Display dimensions on the map while drawing.
The following table lists the classes for drawing tools available in JMap. All these classes are derived from the ToolDraw class.
The following table lists the most commonly used methods of the ToolDraw class.
The following code example shows a tool derived from ToolDrawPolygon that inherits all of its drawing capabilities.
public class CreatePolygonTool extends ToolDrawPolygon
{ private final static String LAYER_NAME = "Zones";
private VectorLayer targetLayer; // The layer that will hold the polygons
public void init(View view)
{
super.init(view);
// Make sure the layer exists. If not create it and register it in the layer manager of the view.
final LayerManager layerMgr = view.getLayerManager();
this.targetLayer = (VectorLayer)layerMgr.getLayer(LAYER_NAME);
if (this.targetLayer == null)
{
// The layer does not exist, create it
this.targetLayer = new VectorLayer(Layer.getNextUserLayerId(), // avoid id conflict with other layers
LAYER_NAME,
ElementTypes.TYPE_POLYGON);
// Tell JMap that information on this layer does not come from the server
this.targetLayer.setLocal(true);
// Set the mouse-over text for the layer. It will be displayed when the user stops the mouse pointer over an element.
this.targetLayer.setMouseOverConfiguration(new MouseOverConfiguration("This is a zone."));
// Add the layer to the layer manager list. All layers need to be registered in the layer manager in order to be displayed in the view. The layer is added to the top.
layerMgr.addLayer(this.targetLayer);
}
// Tell the superclass that the resulting elements should be persisted when completed. That means that they will be placed on a layer. Otherwise, they would be deleted as soon as they are completed.
setPersistent(true);
// Tell the superclass to place the resulting elements on the target layer. Otherwise, they would be placed on the default drawing layer
// (id = LayerManager.LAYER_ID_USER_DRAWINGS).
setDrawLayer(this.targetLayer);
// Modify the style of the surface elements (polygons).
final Style surfaceStyle = getStyleContainer().getSurfaceStyle();
surfaceStyle.setFillColor(Color.GREEN);
surfaceStyle.setTransparency(.50f);
// To have the valid drawing style displayed in the layer bar, make the layer default style identical to the drawing style.
this.targetLayer.setStyle(surfaceStyle, 0.);
}
}
Request
Response
Name of requesterType of requestDescriptionx and y coordinates of the request’s location
Status of the saved request in the database Unique identifier generated upon save
It may be useful to have remote debugging for the JMap Server extensions. Once deployed, these extensions are executed directly in the JMap Server process. It is therefore only possible to debug such extensions remotely. The Java Runtime Environment allows for remote debugging by adding a special parameter in the JMap Server environment. You will then be able to perform a server connection from Eclipse and monitor the execution of your JMap extensions step by step.
To activate remote debugging in JMap Server, you must modify the file startjmapserver.vmoptions located in the JMap_HOME/bin directory. The line starting with -Xdebug should be added.
-Xmx768m
-XX:MaxPermSize=256m
-Djava.awt.headless=true
-Dfile.encoding=ISO-8859-1
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
Next, you must restart JMap Server. JMap Server will then be in debug mode and it will be awaiting commands from Eclipse. It is not recommended to activate the debug mode in a production environment, as it significantly decreases system performance.
In Eclipse, you must create a remote debugging configuration using the same parameters given in the configuration file shown above (these are the default parameters).
The JMap Extensiom Builder is a tool that allows you to quickly generate the source code for JMap client and server extensions. The generated source code is basic, and you must complete it in order to implement the functions of your extension. This tool helps you save time by allowing developers to focus on the real purpose of their development activity instead of dealing with the technical details of programming and deploying JMap extensions.
The tool has a GUI and may also be used in the command line, without a GUI. The parameters accepted by the extension builder are shown below. Note that they are all optional, and default values are used for the missing parameters.
Parameter
Description
-name extensionname
The extension name as it will appear in JMap Admin. It can contain spaces. e.g. tracking goods, network analysis, etc.
-class classname
The full name (with package) of the main class of the extension. The names of the other classes needed by the extension will be derived from that name. e.g. jmap.extensions.tracking
-dest destfolder
The target directory for the generated files. If the directory already exists, it will be deleted and recreated. The default value is output.
-target target
The type of extension to generate. Valid values are client, server or both. The default is both. Different classes and packages are created according to the selected option.
-gui true\false
Determines whether the GUI should be displayed or not. Possible values are true and false. The default value is true. If the GUI is used, its fields are initialized with the values provided as parameters.
The easiest way to run the extension builder is to use the Ant script provided with the tool. The parameters passed to the tool can be modified within the Ant script.
ant -f extensionbuilder.xml
The extension builder can also be executed using the command line (on Mac or Linux, replace “” with “” in the classpath).
java -classpath extensionbuilder.jar;../../lib/kheops_util.jar jmap.sdk.tools.extensionbuilder.ExtensionBuilder -name extensionname -class classname -dest destfolder -target target -gui true\false
After running the tool, the target directory contains the sources of the extension generated as well as some other files. If a client extension was requested (client or both options), there will be a JNLP file, a keystore.jks file (for your client extension’s signature), and a featureslist.properties file. If a server extension was requested (server or both options), there will be a JSP file (configuration interface of server extension). An Ant script (build.xml) is also created in the directory. This script can be used to compile the extension and generate the JAR archives for the client and server.
The following image shows the structure of the generated files.
To run the Ant script, simply run the ant command from the destination directory. After the script has been run, the dist directory will contain all the files to be deployed on JMap Server. The following image shows the structure of the generated files.
Returns the object that contains the styles of the various types of elements (polygons, lines, etc.) that can be drawn. This method is called to change the style of the elements that will be drawn by the tool.
Specifies the layer that will receive the items drawn by the tool, if the elements are persistent (see method below). If no layer is specified, a system layer is used by default.
Determines whether the items will be stored on a layer or not (see method above). If they are not stored, the elements disappear immediately after the drawing operation is completed.