As a new feature of the MapTP Ajax API 2.3, you can switch the tiles that represent the map graphics.
This means you can choose if you want to show the map, satellite image or a mixture of both. You can switch the tile mode at any time, calling one simple function.
Note :
In order to use this feature, your MapTP account needs to support the access to satellite images.
At this point, this is not the case if you are using a Free MapTP Ajax API application key.
For more information about how to to upgrade your account, feel free to contact us.
- Load the API. Since the wrapper classes are not needed in this tutorial, only the core classes are loaded.
function goMap24() {
//Load the API
Map24.loadApi( ["core_api"] , map24ApiLoaded );
}
-
Implement the callback function. This function initializes the mapping client. The steps necessary to do this with the core classes are a little bit more complex than with the wrapper classes. For a detailed description see
Getting Started with the Core Classes. Note that besides initializing the mapping client, the map24ApiLoaded() function opens a local connection that will be needed in the next step to send the request for setting the tile mode.
//The MapTP AJAX API is ready
function map24ApiLoaded(){
//Create the map
map = new Map24.Map();
//Define the viewport
var canvas = new Map24.Canvas({ NodeName: "maparea" });
//Add the canvas to the map
map.addCanvas(canvas, "c");
//Create a static map client
var staticClient = new Map24.MapClient.Static();
//Add the static map client to the map
map.addMapClient(staticClient, "Static");
//Show the map
map.show("Static", "c");
//Open a local connection
locConn = map.Local.openConnection();
}
- To set the tile mode, you have to construct a MapletRemoteControl (MRC) request. The tile mode is set in a ControlComponents command. You have to set "TILES" in the Component parameter. The tile mode is set as value of the Properties array, and must be provided in upper case letters.
Note: Although the request looks like it is sent to a remote Web service, it is processed directly on the client using the local connection object (locConn) that was created in the map24ApiLoaded() function. However, the request structure is the same, whether the request is processed locally or remotely.
Further Information:
//Switch the tiles mode
//Possible values are "MAP", "HYBRID" or "SATELLITE"
function setTileState(tile_state) {
//Send a ControlComponent command via the local connection to set the new state of the tiles
locConn.mapletRemoteControl(
new Map24.WebServices.Message.mapletRemoteControlRequest({
MapletRemoteControlRequest: new Map24.WebServices.MapletRemoteControlRequest({
Map24MRC: new Map24.WebServices.Map24MRC({
Commands: [
new Map24.WebServices.XMLCommandWrapper({
ControlComponent: new Map24.WebServices.ControlComponent({
Component: "TILES",
Properties: [new Map24.WebServices.Property({
Key: "setstate",
Value: tile_state.toUpperCase()
})]
})
})
]
})
})
})
);
}
View example
Executable code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Switch Tiles Mode</title>
<script type="text/javascript" language="javascript" src="http://api.maptp.map24.com/ajax?appkey=Your AJAX application key goes here"></script>
<script language="javascript" type="text/javascript">
var map = null;
var locConn = null;
//Load the MapTP AJAX API
function goMap24(){
Map24.loadApi(["core_api"], map24ApiLoaded);
}
//The MapTP AJAX API is ready
function map24ApiLoaded(){
//Create the map
map = new Map24.Map();
//Define the viewport
var canvas = new Map24.Canvas({ NodeName: "maparea" });
//Add the canvas to the map
map.addCanvas(canvas, "c");
//Create a static map client
var staticClient = new Map24.MapClient.Static();
//Add the static map client to the map
map.addMapClient(staticClient, "Static");
//Show the map
map.show("Static", "c");
//Open a local connection
locConn = map.Local.openConnection();
}
//Switch the tiles mode
//Possible values are "MAP", "HYBRID" or "SATELLITE"
function setTileState(tile_state) {
//Send a ControlComponent command via the local connection
//to set the new state of the tiles
locConn.mapletRemoteControl(
new Map24.WebServices.Message.mapletRemoteControlRequest({
MapletRemoteControlRequest: new Map24.WebServices.MapletRemoteControlRequest({
Map24MRC: new Map24.WebServices.Map24MRC({
Commands: [
new Map24.WebServices.XMLCommandWrapper({
ControlComponent: new Map24.WebServices.ControlComponent({
Component: "TILES",
Properties: [new Map24.WebServices.Property({
Key: "setstate",
Value: tile_state.toUpperCase()
})]
})
})
]
})
})
})
);
}
</script>
</head>
<body onload="goMap24();">
<h2>Different Tile Modes with the MapTP Ajax API 2.3</h2>
<div id="maparea" style="height: 500px; width: 500px"></div>
<p>
<button id="map_tiles" onclick="setTileState('MAP')">Enable Map View</button>
<button id="satellite_tiles" onclick="setTileState('SATELLITE')">Enable Satellite View</button>
<button id="hybrid_tiles" onclick="setTileState('HYBRID')">Enable Hybrid View</button>
</p>
</body>
</html>