×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to pan the map

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps)
avnee.nathani (Talk | contribs)
(Avnee.nathani - Updated article for Nokia Maps Javascript API v2.0. (Released in Dec 2011))
Line 1: Line 1:
 
[[Category:Web]][[Category:Browser]][[Category:Web]][[Category:Nokia Maps]]
 
[[Category:Web]][[Category:Browser]][[Category:Web]][[Category:Nokia Maps]]
 
{{Abstract|This article explains how to use the panning method on the map. }}  
 
{{Abstract|This article explains how to use the panning method on the map. }}  
 
+
{{ArticleMetaData
 +
|platform= Web browser
 +
|update-by=[[User:avnee.nathani]]
 +
|update-timestamp=20111231
 +
}}
 
== Introduction ==
 
== Introduction ==
  
This article contains an example that you can use to study how the Ovi Maps API handles panning of the map. Feel free to modify and utilize whole or partial for your own purposes!
+
This article contains an example that you can use to study how the Nokia Maps API handles panning of the map. Feel free to modify and utilize whole or partial for your own purposes!
  
 
== Prerequistites ==
 
== Prerequistites ==
  
Ovi Maps API supported web browser (basically any modern browser should do).
+
Nokia Maps API supported web browser (basically any modern browser should do).
 
+
  
 
== Example code ==
 
== Example code ==
  
 
This example will start panning the map to the right, then after a moment changes direction to the left and continues forever(?) ;)
 
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.
 
Unless you stop it by pressing the button and clearing the timer and interval settings.
  
 
<code java>
 
<code java>
 
<script type="text/javascript">
 
<script type="text/javascript">
 
+
 
//Globals
 
//Globals
 
+
 
     var myInterval = 0;
 
     var myInterval = 0;
   
+
 
     var myTimer;
 
     var myTimer;
   
+
   
+
 
     var map_start_x = 100;
 
     var map_start_x = 100;
 
     var map_start_y = 100;
 
     var map_start_y = 100;
 
     var map_end_x = 120;
 
     var map_end_x = 120;
 
     var map_end_y = 100;
 
     var map_end_y = 100;
 
+
 
     var myMap;
 
     var myMap;
 
+
 
if (document.addEventListener)
 
if (document.addEventListener)
 
   document.addEventListener("DOMContentLoaded", all_is_ready, false);
 
   document.addEventListener("DOMContentLoaded", all_is_ready, false);
 
+
 
+
 
function all_is_ready(){
 
function all_is_ready(){
 
   
 
   
 
  alert("Click OK to start the panning.");
 
  alert("Click OK to start the panning.");
 
   
 
   
  myMap = new ovi.mapsapi.map.Display(document.getElementById("map"),
+
  myMap = new nokia.maps.map.Display(document.getElementById("map"),
 
     {
 
     {
                   components: [ new ovi.mapsapi.map.component.Behavior(),
+
                   components: [ new nokia.maps.map.component.Behavior(),
                             new ovi.mapsapi.map.component.ZoomBar(),
+
                             new nokia.maps.map.component.ZoomBar(),
                             new ovi.mapsapi.map.component.Overview(),                             
+
                             new nokia.maps.map.component.Overview(),                             
                             new ovi.mapsapi.map.component.TypeSelector(),     
+
                             new nokia.maps.map.component.TypeSelector(),     
                             new ovi.mapsapi.map.component.ScaleBar() ],
+
                             new nokia.maps.map.component.ScaleBar() ],
 
                   zoomLevel: 3,
 
                   zoomLevel: 3,
                   center: [52.51, 13.4]   
+
                   center: [19.119, 72.8957]   
 
   
 
   
 
     });
 
     });
   
+
 
  timerLauncher();
 
  timerLauncher();
 
   
 
   
Line 62: Line 64:
 
     myInterval = setInterval ("panTheMap()", 1000);   
 
     myInterval = setInterval ("panTheMap()", 1000);   
 
}
 
}
 
+
 
function panTheMap()
 
function panTheMap()
 
{   
 
{   
Line 69: Line 71:
 
     map_end_x = map_end_x - 1;
 
     map_end_x = map_end_x - 1;
 
     map_end_y = map_end_y + 1;
 
     map_end_y = map_end_y + 1;
           
+
 
     document.getElementById("showCoords").innerHTML = "("+map_start_x+","+map_start_y+","+map_end_x+","+map_end_y+")";
 
     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);
 
     myMap.pan(map_start_x, map_start_y, map_end_x, map_end_y);
   
+
 
     myTimer = setTimeout ('document.getElementById("showCoords").innerHTML = ""', 500);
 
     myTimer = setTimeout ('document.getElementById("showCoords").innerHTML = ""', 500);
 
}   
 
}   
 
+
 
function stopPanning()
 
function stopPanning()
 
{
 
{
Line 82: Line 84:
 
     clearInterval(myInterval);
 
     clearInterval(myInterval);
 
     alert("Timer and interval cleared. Example finished. Reload page to run again.");
 
     alert("Timer and interval cleared. Example finished. Reload page to run again.");
 
+
 
}
 
}
 
</script>
 
</script>
 
<html>
 
<html>
 
<head>
 
<head>
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
+
<script type="text/javascript"
 +
    src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
 +
</script>
 
</head>
 
</head>
 
<body>
 
<body>
Line 100: Line 104:
 
</html>
 
</html>
 
</code>
 
</code>
 +
 +
==For more on Nokia Maps API==
 +
 +
Please check out the Nokia Maps API full documentation and API reference here:
 +
* http://api.maps.nokia.com/2.0.0
 +
 +
You may also access the interactive Nokia Maps API playground,
 +
* http://api.maps.nokia.com/playground/index.html
  
 
== Summary ==
 
== 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...? =)
 
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...? =)

Revision as of 12:27, 31 December 2011

This article explains how to use the panning method on the map.

Article Metadata
Compatibility
Platform(s): Web browser
Article
Created: (31 Dec 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: avnee.nathani (31 Dec 2011)

Contents

Introduction

This article contains an example that you can use to study how the Nokia Maps API handles panning of the map. Feel free to modify and utilize whole or partial for your own purposes!

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.

<script type="text/javascript">
 
//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("map"),
{
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>
<html>
<head>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
</script>
</head>
<body>
<center>
<div id="map" style="width:80%; height:80%;"></div>
<div id="showCoords" style="height: 2.0em; font-size: 2em; color: blue;"></div>
<FORM>
<INPUT type="button" value="STOP panning" name="button6" onClick="stopPanning()">
</FORM>
</center>
</body>
</html>

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...? =)

114 page views in the last 30 days.
×