All the necessary parameters will be automatically generated by the Map Author. To create a sample
application and generate the initial parameters follow these steps:
1) Start the Map Author;
2) Open a map (File->Open Map) or create a new one (File->New Map);
3) Create a JSP based web application (Tools->Make Web Page->Without Applet->Template: JSP Template->Save (to <APPLICATION_DIRECTORY>)).
All the initial parameters are stored in the <APPLICATION_DIRECTORY>\WEB-INF\web.xml file.
Also required is the set of RouteMAP IMS Java classes that are included in the <APPLICATION_DIRECTORY>\WEB-INF\rmims.jar library.
The basic structrute of the custom application is:
<APPLICATION_DIRECTORY>\WEB-INF\web.xml
<APPLICATION_DIRECTORY>\WEB-INF\rmims.jar
<APPLICATION_DIRECTORY>\index.jsp (entry point of the application)
<APPLICATION_DIRECTORY>\*.jsp (other JSP scripts)
Usually the Tomcat applications directory is the <INSTALLATION_DIRECTORY>\webapps\ directory and the port is 8080, so you can place your application in <INSTALLATION_DIRECTORY>\webapps\ and then access it via a URL such as: http://your_host:8080/<APPLICATION_DIRECTORY>/index.jsp.
A typical JSP script that allows executing all the examples has the following structure:
<%@ page import = "com.esri.rmims.*" %> <%@ page import = "java.io.*" %> <%@ page import = "java.awt.Color" %> <%@ page buffer="32kb" autoFlush="false" %> <% // Main code here %> <% // Auxiliary classes and methods here %>
There are several implicit objects that can be accessed directly from the JSP script. We will use several of them: application (javax.servlet.ServletContext), request (javax.servlet.ServletRequest), and out (javax.servlet.jsp.JspWriter).
The Map interface is the primary mapping interface in the system. It gives full control over the map conditions and the map image.
The Map object must be initialized before using any of the other objects or methods.
The basic steps to initialize the Map object are:
1) Create the IMSConnection object;
2) Set the server URL, group, and user name;
3) Load the map;
4) Set the map image size;
5) Set the initial extent.
See the example below:
<% Map map = openMap( application); %> <% public Map openMap(ServletContext init) throws RMException { Map map = null; IMSConnection conn = new IMSConnection(); conn.setConnectionURL(init.getInitParameter("ServerURL")); conn.setGroup(init.getInitParameter("GroupID")); conn.setUserName(init.getInitParameter("UserID")); conn.setLocale(init.getInitParameter("Lang"), init.getInitParameter("Country")); map = conn.loadMap(init.getInitParameter("MapName")); map.setImageSize(Integer.parseInt( init.getInitParameter("MapImgWidth")), Integer.parseInt( init.getInitParameter("MapImgHeight"))); map.setMeasureUnits(Integer.parseInt( init.getInitParameter("Units"))); map.setLocation(new Location(init.getInitParameter("Location"))); return map; } %>
A key method of the Map interface is the getMapImageURL() method. After performing any desired
function to the map image (set label or route, draw ellipses, rectangles, or polygons),
call this method to get the resulting map image and display it in the browser:
<img src="<%= map.getMapImageURL(map.getImageWidth(), map.getImageHeight(), ImageFormat.DEFAULT)%>" width="<%=map.getImageWidth()%>" height="<%=map.getImageHeight()%>">
Other necessary functions are included in the examples code.
There is a separate step that is used to retrieve locations represented in map units. Most of the examples require locations represented by the coordinates that are in map units, however there are several projections of the US maps in RouteMAP IMS which require their own projection dependent coordinates. Therefore to make projection independent locations represented by their coordinates we use the following code:
<% Map map = openMap( application); // pass map, label, latitude, and longitude to the constructor GeoLocation loc = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531); // now we have the location object with the x and y coordinates in map units out.println( loc.x + ", " + loc.y); // output for the Cylindrical projection: // -1160.8126558920917, 2355.452143609115 %> <% public class GeoLocation { public String label; public double x; public double y; GeoLocation (Map map, String clabel, double clat, double clon) throws RMException { Projection proj = map.getProjection(); GeoPoint pt = proj.project( clat, clon); label = clabel; x = pt.x; y = pt.y; } } %>
Most of the methods of the API require the GeoPoint object as a parameter. You can use the following methods to get the GeoPoint object.
If x, y is in pixels:
GeoPoint pt = map.toMapUnits(x, y);If x, y is in map units:
GeoPoint pt = new GeoPoint(x, y);