×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to pan the map

From Nokia Developer Wiki
Jump to: navigation, search
Oskar Bukolt (Talk | contribs)
m (Oskar Bukolt - Update API link)
Oskar Bukolt (Talk | contribs)
m (Oskar Bukolt - Update for 2.2.1 in IE)
Line 1: Line 1:
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
+
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]][[Category:Code Examples]]
 
{{Abstract|This article explains how to use the panning method on the map. }}  Feel free to modify and utilize whole or partial for your own purposes!
 
{{Abstract|This article explains how to use the panning method on the map. }}  Feel free to modify and utilize whole or partial for your own purposes!
  
Line 44: Line 44:
 
     <head>
 
     <head>
 
       <title>Panning the map</title>
 
       <title>Panning the map</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
        <meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9"/>
 +
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
 
       <script type="text/javascript"
 
       <script type="text/javascript"
             src="http://api.maps.nokia.com/2.2.0/jsl.js" charset="utf-8">
+
             src="http://api.maps.nokia.com/2.2.1/jsl.js" charset="utf-8">
 
         </script>
 
         </script>
 
     </head>
 
     </head>
     <body>
+
     <body onload="all_is_ready()">
 
+
 
         <div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
 
         <div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
 
         <div id="showCoords" style="height: 2.0em; font-size: 2em; color: blue;"></div>
 
         <div id="showCoords" style="height: 2.0em; font-size: 2em; color: blue;"></div>
Line 63: Line 64:
 
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");  
 
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");  
 
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
 
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
 
+
 
//
 
//
 
/////////////////////////////////////////////////////////////////////////////////////
 
/////////////////////////////////////////////////////////////////////////////////////
 
+
 
//Globals
 
//Globals
 
   
 
   
Line 77: Line 78:
 
     var myMap;
 
     var myMap;
 
   
 
   
if (document.addEventListener)
+
//if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", all_is_ready, false);
+
// document.addEventListener("DOMContentLoaded", all_is_ready, false);
 
   
 
   
 
   
 
   

Revision as of 13:29, 11 July 2012

This article explains how to use the panning method on the map. Feel free to modify and utilize whole or partial for your own purposes!

Article Metadata
Tested with
Devices(s): Internet Explorer, Firefox, Google Chrome, Opera
Compatibility
Platform(s): Web browser
Dependencies: Nokia Maps 2.2.0
Article
Created: Maveric (27 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: Oskar Bukolt (11 Jul 2012)

Contents

Prerequistites

Nokia Maps API supported web browser (basically any modern browser should do).

Example code

This example will start panning the map to the right, then after a moment changes direction to the left and continues forever(?) ;) Unless you stop it by pressing the button and clearing the timer and interval settings.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Panning the map</title>
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.1/jsl.js" charset="utf-8">
</script>
</head>
<body onload="all_is_ready()">
 
<div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<div id="showCoords" style="height: 2.0em; font-size: 2em; color: blue;"></div>
<input type="button" value="STOP panning" name="button6" onclick="stopPanning()" />
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
 
//
/////////////////////////////////////////////////////////////////////////////////////
 
//Globals
 
var myInterval = 0;
var myTimer;
var map_start_x = 100;
var map_start_y = 100;
var map_end_x = 120;
var map_end_y = 100;
var myMap;
 
//if (document.addEventListener)
// document.addEventListener("DOMContentLoaded", all_is_ready, false);
 
 
function all_is_ready(){
 
alert("Click OK to start the panning.");
 
myMap = new nokia.maps.map.Display(document.getElementById("mapContainer"),
{
components: [ new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 3,
center: [19.119, 72.8957]
 
});
 
timerLauncher();
 
}
function timerLauncher()
{
// Start the timer
myInterval = setInterval ("panTheMap()", 1000);
}
 
function panTheMap()
{
map_start_x = map_start_x + 1;
map_start_y = map_start_y + 1;
map_end_x = map_end_x - 1;
map_end_y = map_end_y + 1;
 
document.getElementById("showCoords").innerHTML = "("+map_start_x+","+map_start_y+","+map_end_x+","+map_end_y+")";
 
myMap.pan(map_start_x, map_start_y, map_end_x, map_end_y);
 
myTimer = setTimeout ('document.getElementById("showCoords").innerHTML = ""', 500);
}
 
function stopPanning()
{
clearTimeout(myTimer);
clearInterval(myInterval);
alert("Timer and interval cleared. Example finished. Reload page to run again.");
 
}
</script>
</body>
</html>

Screenshot

NokiaMapsPanning.png

For more on Nokia Maps API

Please check out the Nokia Maps API full documentation and API reference here:

You may also access the interactive Nokia Maps API playground,

Summary

Using the map panning feature you could create e.g. a game, where the map is moving and the user should e.g. find something on the map and click it before the area vanishes from sight, just an idea ;) develop your own =)? Side scrolling game...? =)

262 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×