PTV xMap Server Code Samples

Using PTV xMap Server with Jsp/Java and C#

Overview

If you have accessed this page through the xServer's management console, you can immediately view and execute the Jsp code samples, just click the links below. Refer to the troubleshooting section if the samples do not work. This page is best viewed with Mozilla Firefox.

In order to install the C# samples which are not displayed here by default, refer to the C# installation section.

These samples are designed to be executed with the default data of Luxemburg. If you changed the data path in xmap.properties these samples may not work properly.

Use case samples

Please choose an xMap sample use case

Sample 1: Simple map request using bounding box

This sample shows how to request a map by using the map's bounding box.

Jsp Sample

View the source by clicking 'show/hide source' below, or execute it by clicking execute.
<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java"  
	import="java.io.*" 
	import="java.util.*" 
	import="com.ptvag.jabba.service.baseservices.*" 
	import="com.ptvag.xserver.common.*" 
	import="com.ptvag.xserver.xmap.*" 
	import="com.ptvgroup.xserver.framework.*" 
%>

<%
{
	//
	// This page is a sample for PTV xMap Server and is intended to
	// show client developers how to request information from the server.
	// See the code comments for documentation.
	//
	// Please note that the default url is http://localhost:<port>/<service>.
	//


	// The xServer's port
	String port = System.getProperty("port.http", "50010");
	String path = this.getServletContext().getRealPath("/").replace('\\', '/');

	// Build up the xServer's service url
	String url = request.getRequestURL().toString().split(":")[0] + "://localhost:" + port + "/" + path.substring(path.lastIndexOf("webapps") + 8) + "ws/XMap";

	//
	// When using this sample in a different context, i.e. not within the xServer, 
	// please uncomment and modify the following line and comment the line following that line.
	//
	//String serviceUrl = "http://localhost:50010/xmap/ws/XMap";
	String serviceUrl = url;


	//
	// The request parameters are defined here
	//
	
	// The map's bounding box in geodecimal co-ordinates
	int left = 603915;
	int top = 4965442;
	int right = 621217;
	int bottom = 4954227;
	
	// The image width and height
	int width = 400;
	int height = 300;

	// The image format
	ImageFileFormat imageFormat = ImageFileFormat.GIF;
	
	// The profile to be used
	String profile = "default";
	
	// The coordinate-format to be used
	String coordFormat = CoordFormat.PTV_GEODECIMAL.getValue();


	//
	// Building the request
	//

	// MapSection element
	BoundingBox mapSection = new BoundingBox();
	mapSection.setLeftTop(new Point());
	mapSection.getLeftTop().setPoint(new PlainPoint());
	mapSection.getLeftTop().getPoint().setX(left);
	mapSection.getLeftTop().getPoint().setY(top);
	mapSection.setRightBottom(new Point());
	mapSection.getRightBottom().setPoint(new PlainPoint());
	mapSection.getRightBottom().getPoint().setX(right);
	mapSection.getRightBottom().getPoint().setY(bottom);

	// MapParams element
	MapParams mapParams = new MapParams();
	mapParams.setShowScale(true);
	mapParams.setUseMiles(false);

	// ImageInfo element
	ImageInfo imageInfo = new ImageInfo();
	imageInfo.setFormat(imageFormat);
	imageInfo.setWidth(width);
	imageInfo.setHeight(height);

	// CallerContext element to set co-ordinate format and profile name
	CallerContext callerContext = new CallerContext(); 
	callerContext.setLog1("xMap sample 1"); 
	callerContext.setLog2(""); 
	callerContext.setLog3(""); 
	CallerContextProperty p1 = new CallerContextProperty("CoordFormat", coordFormat); 
	CallerContextProperty p2 = new CallerContextProperty("ResponseGeometry", GeometryEncoding.PLAIN.getValue()); 
	CallerContextProperty p3 = new CallerContextProperty("Profile", profile); 
	CallerContextProperty[] callerContextProperties = {p1, p2, p3}; 
	callerContext.setProperties(callerContextProperties); 

	
	//
	// Creating the service instance
	//
	
    // Use JWSDP or CXF? => Check what's available...
    RemoteType remoteType = null;
    try {
        Class.forName("com.ptvag.xserver.xmap.XMapCXFClient");
        // => CXF available
        remoteType = RemoteType.DOCSTYLE_CXF;
    } catch(Exception e) {  
        // => JWSDP
        remoteType = RemoteType.DOCSTYLE_JWSDP;
    }

    XMapRemoteInterface client = (XMapRemoteInterface)ClientFactory.createClient(XMapRemoteInterface.class, remoteType, "", "", serviceUrl);
	client.setCallerContext(callerContext);
	
	// Set user and password
	client.setUsername("sample");
	client.setPassword("sample");

	//
	// Sending the request
	//

	String message = "";
	boolean success = true;
	com.ptvag.xserver.xmap.Map resultMap = null;

	try 
	{
		resultMap = client.renderMapBoundingBox(mapSection, mapParams, imageInfo, null, false);
	}
	catch (Exception e) 
	{
		success = false;
		message = e.toString();
	}

	if (success == true && (resultMap == null || resultMap.getImage() == null || resultMap.getImage().getUrl() == null))
	{
		success = false;
		message = "Error parsing the response, unable to obtain the image url.";
	}
%>
<html> 
    <head>
		<meta http-equiv="Content-Language" content="en-us">
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
		<title>PTV xMap - Code Samples</title>
		<link rel="shortcut icon" href="../images/favicon.ico"/>
		<link type="text/css" rel="stylesheet" href="../css/xserver.css">
	</head> 
<body>

<%
	// If the request has been executed successfully, the response
	// image is displayed, otherwise the error message is displayed.
%>

<% if (success == true) { 
	// The resulting map url is obtained like this
	String mapUrl = request.getRequestURL().toString().split(":")[0] + "://" + resultMap.getImage().getUrl();
%>

<h2>The request has been executed successfully.</h2>
<p>The map image url is <a href=<%=mapUrl%>><%=mapUrl%></a></p>
<p>If the map image is not displayed below, please check the imageMapServer configuration in the 
file xmap.properties in the xServer's conf folder.</p>
<img src="<%=mapUrl%>"/>

<% } else { %>

<h2>An error occurred while executing the reuqest.</h2>
<p><b>Message: </b><%=message%></p>

<% } %>

<% 
} 
%>

</body> 
</html> 


Back to Top

Sample 2: Simple map request using map center and scale

This sample shows how to request a map by using the map's center co-ordinates and the scale.

Jsp Sample

View the source by clicking 'show/hide source' below, or execute it by clicking execute.
<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java"  
	import="java.io.*" 
	import="java.util.*" 
	import="com.ptvag.jabba.service.baseservices.*" 
	import="com.ptvag.xserver.common.*" 
	import="com.ptvag.xserver.xmap.*" 
	import="com.ptvgroup.xserver.framework.*" 
%>

<%
{
	//
	// This page is a sample for PTV xMap Server and is intended to
	// show client developers how to request information from the server.
	// See the code comments for documentation.
	//
	// Please note that the default url is http://localhost:<port>/<service>.
	//


	// The xServer's port
	String port = System.getProperty("port.http", "50010");
	String path = this.getServletContext().getRealPath("/").replace('\\', '/');

	// Build up the xServer's service url
	String url = request.getRequestURL().toString().split(":")[0] + "://localhost:" + port + "/" + path.substring(path.lastIndexOf("webapps") + 8) + "ws/XMap";

	//
	// When using this sample in a different context, i.e. not within the xServer, 
	// please uncomment and modify the following line and comment the line following that line.
	//
	//String serviceUrl = "http://localhost:50010/xmap/ws/XMap";
	String serviceUrl = url;


	//
	// The request parameters are defined here
	//
	
	// The map center in geodecimal co-ordinates
	int x = 612566;
	int y = 4959837;
	
	// The scale
	int scale = 1000;
	
	// The image width and height
	int width = 400;
	int height = 300;

	// The image format
	ImageFileFormat imageFormat = ImageFileFormat.GIF;
	
	// The profile to be used
	String profile = "default";
	
	// The coordinate-format to be used
	String coordFormat = CoordFormat.PTV_GEODECIMAL.getValue();


	//
	// Building the request
	//

	// MapSection element
	MapSection mapSection = new MapSection();
	mapSection.setCenter(new Point());
	mapSection.getCenter().setPoint(new PlainPoint());
	mapSection.getCenter().getPoint().setX(x);
	mapSection.getCenter().getPoint().setY(y);
	mapSection.setScale(scale);
	mapSection.setScrollHorizontal(0);
	mapSection.setScrollVertical(0);
	mapSection.setZoom(0);

	// MapParams element
	MapParams mapParams = new MapParams();
	mapParams.setShowScale(true);
	mapParams.setUseMiles(false);

	// ImageInfo element
	ImageInfo imageInfo = new ImageInfo();
	imageInfo.setFormat(imageFormat);
	imageInfo.setWidth(width);
	imageInfo.setHeight(height);

	// CallerContext element to set co-ordinate format and profile name
	CallerContext callerContext = new CallerContext(); 
	callerContext.setLog1("xMap sample 2"); 
	callerContext.setLog2(""); 
	callerContext.setLog3(""); 
	CallerContextProperty p1 = new CallerContextProperty("CoordFormat", coordFormat); 
	CallerContextProperty p2 = new CallerContextProperty("ResponseGeometry", GeometryEncoding.PLAIN.getValue()); 
	CallerContextProperty p3 = new CallerContextProperty("Profile", profile); 
	CallerContextProperty[] callerContextProperties = {p1, p2, p3}; 
	callerContext.setProperties(callerContextProperties); 

	
	//
	// Creating the service instance
	//
	
    // Use JWSDP or CXF? => Check what's available...
    RemoteType remoteType = null;
    try {
        Class.forName("com.ptvag.xserver.xmap.XMapCXFClient");
        // => CXF available
        remoteType = RemoteType.DOCSTYLE_CXF;
    } catch(Exception e) {  
        // => JWSDP
        remoteType = RemoteType.DOCSTYLE_JWSDP;
    }

    XMapRemoteInterface client = (XMapRemoteInterface)ClientFactory.createClient(XMapRemoteInterface.class, remoteType, "", "", serviceUrl);
	client.setCallerContext(callerContext);
	
	// Set user and password
	client.setUsername("sample");
	client.setPassword("sample");

	//
	// Sending the request
	//

	String message = "";
	boolean success = true;
	com.ptvag.xserver.xmap.Map resultMap = null;

	try 
	{
		resultMap = client.renderMap(mapSection, mapParams, imageInfo, null, false);
	}
	catch (Exception e) 
	{
		success = false;
		message = e.toString();
	}

	if (success == true && (resultMap == null || resultMap.getImage() == null || resultMap.getImage().getUrl() == null))
	{
		success = false;
		message = "Error parsing the response, unable to obtain the image url.";
	}
%>
<html> 
    <head>
		<meta http-equiv="Content-Language" content="en-us">
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
		<title>PTV xServer - Code Samples</title>
		<link rel="shortcut icon" href="../images/favicon.ico"/>
		<link type="text/css" rel="stylesheet" href="../css/xserver.css">
	</head> 
<body>

<%
	// If the request has been executed successfully, the response
	// image is displayed, otherwise the error message is displayed.
%>

<% if (success == true) { 
	// The resulting map url is obtained like this
	String mapUrl = request.getRequestURL().toString().split(":")[0] + "://" + resultMap.getImage().getUrl();
%>

<h2>The request has been executed successfully.</h2>
<p>The map image url is <a href=<%=mapUrl%>><%=mapUrl%></a></p>
<p>If the map image is not displayed below, please check the imageMapServer configuration in the 
file xmap.properties in the xServer's conf folder.</p>
<img src="<%=mapUrl%>"/>

<% } else { %>

<h2>An error occurred while executing the reuqest.</h2>
<p><b>Message: </b><%=message%></p>

<% } %>

<% 
} 
%>

</body> 
</html> 


Back to Top

Troubleshooting

If the Jsp samples cannot be executed, please view the source code and check the serviceUrl variable.


Back to Top

C# installation

The C# samples can be found in the xServer's samples folder. Please unpack them into the root folder of your local IIS installation, usually C:\Inetpub\wwwroot. Then call the IIS management console from the Control Panel and register the sample folder as IIS application.

Additionally make sure, that Microsoft.Net Framework 2.0 redistributables are installed and ASP.NET is registered within Internet Information Services (IIS). For registration use the ASP.NET IIS Registration tool with the command line

aspnet_regiis.exe -i

After having executed these steps, please reload this page. The C# samples are automatically displayed and can be executed.

Please note: If your IIS installation directory is not C:\Inetpub\wwwroot, then edit this page and change the value of the IISPath variable. If the IIS url is not http://localhost then change the value if the IISUrl variable.