×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to pan the map

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox -)
jasfox (Talk | contribs)
m (Jasfox - Update links)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]][[Category:Nokia Maps]]
+
[[Category:HERE Maps]][[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!
  
 
{{ArticleMetaData
 
{{ArticleMetaData
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode= [https://github.com/heremaps/examples/blob/master/maps_api_for_javascript/simple-examples/panning-the-map.html panning-the-map.html]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Internet Explorer, Firefox, Google Chrome, Opera
 
|devices= Internet Explorer, Firefox, Google Chrome, Opera
Line 9: Line 9:
 
|platform= Web browser
 
|platform= Web browser
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies=Nokia Maps 2.2.3
+
|dependencies=HERE Maps 2.5.3
 
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|keywords= Nokia Maps, JavaScript, Panning
+
|keywords= HERE Maps, JavaScript, Panning
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
Line 26: Line 26:
 
}}
 
}}
 
{{SeeAlso|
 
{{SeeAlso|
* [http://developer.here.net/javascript_api Nokia Maps API]
+
* [http://developer.here.net/javascript_api HERE Maps API]
 
* [http://developer.here.net/apiexplorer/examples/api-for-js/map/panning-the-map.html Panning the Map]
 
* [http://developer.here.net/apiexplorer/examples/api-for-js/map/panning-the-map.html Panning the Map]
 
  }}
 
  }}
Line 32: Line 32:
 
== Prerequistites ==
 
== Prerequistites ==
  
Nokia Maps API supported web browser (basically any modern browser should do).
+
HERE 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(?) ;)
+
After the map is intiallised, a timer is set up {{Icode|setInterval (panTheMap, 300);}} to pan the pan three times a second. The panning code is shown below:
Unless you stop it by pressing the button and clearing the timer and interval settings. Remember to add in your own [[How to Obtain Your Own Nokia appID and Token| AppId and Token]] to get it to work.
+
 
+
 
<code javascript>
 
<code javascript>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
function panTheMap() {  
<html xmlns="http://www.w3.org/1999/xhtml">
+
    x = x + incX;
    <head>
+
if (Math.abs(x) > 20 ){
      <title>Panning the map</title>
+
    incX = -incX;
        <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"
+
     y= y + incY;
            src="http://api.maps.nokia.com/2.2.3/jsl.js" charset="utf-8">
+
     if (Math.abs(y) > 20 ){
        </script>
+
    incY = -incY;
    </head>
+
    }
    <body onload="all_is_ready()">
+
 
   
+
    map.pan(0, 0, x, y);
        <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>
 
 
  </code>
 
  </code>
  
Line 136: Line 56:
 
[[File:NokiaMapsPanning.png|600px]]
 
[[File:NokiaMapsPanning.png|600px]]
  
==For more on the Nokia Maps API==
+
To see the example in action:
 +
 
 +
http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/simple-examples/panning-the-map.html
 +
 
 +
==For more on the HERE Maps API==
  
Please check out the Nokia Maps API full documentation and API reference here:
+
Please check out the HERE Maps API full documentation and API reference here:
* [http://developer.here.net/javascript_api Nokia Maps API]
+
* [http://developer.here.com/javascript_api HERE Maps API]
  
 
You may also access the interactive API explorer
 
You may also access the interactive API explorer
* [http://developer.here.net/javascript_api_explorer API explorer]
+
* [http://developer.here.com/javascript_api_explorer API explorer]
  
 
== 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...? =)

Latest revision as of 14:26, 28 November 2013

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
Code ExampleTested with
Devices(s): Internet Explorer, Firefox, Google Chrome, Opera
Compatibility
Platform(s): Web browser
Dependencies: HERE Maps 2.5.3
Article
Keywords: HERE Maps, JavaScript, Panning
Created: Maveric (27 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (28 Nov 2013)

Contents

[edit] Prerequistites

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

[edit] Example code

After the map is intiallised, a timer is set up setInterval (panTheMap, 300); to pan the pan three times a second. The panning code is shown below:

function panTheMap() {  
x = x + incX;
if (Math.abs(x) > 20 ){
incX = -incX;
}
 
y= y + incY;
if (Math.abs(y) > 20 ){
incY = -incY;
}
 
map.pan(0, 0, x, y);
}

[edit] Screenshot

NokiaMapsPanning.png

To see the example in action:

http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/simple-examples/panning-the-map.html

[edit] For more on the HERE Maps API

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

You may also access the interactive API explorer

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

This page was last modified on 28 November 2013, at 14:26.
195 page views in the last 30 days.
×