Getting started with ASP MapServices is really easy!
In the example below we will demonstrate how
to create a simple map using popular web-mapping framwork OpenLayers.
First, you need to load OpenLayers library and create a placeholder for the map:
And javascript that renders a map looks like this:
var token = "<%=request.getSession().getServletContext().getAttribute("token")%>"; //your token goes here
var options = {
maxExtent: new OpenLayers.Bounds(0, 0, 3000000, 9000000),
tileSize: new OpenLayers.Size(250, 250),
units: 'm',
projection: 'EPSG:3006',
resolutions: [1.3, 2.6, 4, 6.6, 13.2, 26.5, 66.1, 132.3, 264.6, 793.8, 1322.9, 2645.8, 13229.2, 26458.3],
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.MousePosition({numDigits:0})
],
layers: [
new OpenLayers.Layer.TMS("TMS", "http://tms.asp-mapservices.com/",
{ layername: token + '/5', type: 'png' })
]
}
var map = new OpenLayers.Map("map", options);
map.setCenter(new OpenLayers.LonLat(611149, 6660307), 3);
Noticed that "token" variable on the first line? That's the key you generate on the serverside by making a call to our authentication webservice. Here's an example of how to generate token in Java but it can of course be done in any language of your choice:
String username = "username";
String password = "password";
URL url = new URL("http://www.asp-mapservices.com/WebGISTileServer/ServerAdminServlet?action=login&username=" + username + "&password=" + password);
URLConnection urlc= url.openConnection();
int length = urlc.getContentLength();
InputStream in = urlc.getInputStream();
byte[] buff = new byte[length];
int bytesRead=0;
while(bytesRead < length)
{
bytesRead += in.read(buff,bytesRead,in.available());
}
String token = new String(buff);
token = token.replaceAll("[\\r\\f]","");
token = token.trim();
request.getSession().getServletContext().setAttribute("token", token);