Panning the Map
Programmatically pan the map so that it is continually in motion
HTML
<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css">
<!-- SCRIPTS -->
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
<!-- BODY -->
<h1>Panning the Map</h1>
<p>This example displays a map of the <b>Indian Ocean </b>which continuously pans using screen space X/Y coordinates.</p>
<hr/>
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
CSS
code, h1, h2, h3{
color: #124191;
letter-spacing: -0.03em;
}
body {
font-family:"Lucida Grande",Tahoma,sans-serif;
color: rgb(102, 102, 102);
font-size: 80%;
}
b, strong {
color: black;
}
code {
font-weight: 700;
font-size: 120%;
}
JavaScript
/**
* Pan the map so that it is continually in motion
*
* @param {H.Map} map A HERE Map instance within the application
*/
function panTheMap(map) {
var viewPort,
incX = 1,
incY = 2,
x = 100,
y = 100;
// Obtain the view port object of the map to manipulate its screen coordinates
var viewPort = map.getViewPort(),
// function calculates new screen coordinates and calls
// viewport's interaction method with them
pan = function() {
x = x + incX;
if (Math.abs(x) > 100) {
incX = -incX;
}
y = y + incY;
if (Math.abs(y) > 100) {
incY = -incY;
}
viewPort.interaction(x, y);
};
// set interaction modifier that provides information which map properties
// change with each "interact" call
viewPort.startInteraction(H.map.render.RenderEngine.InteractionModifiers.COORD);
// set up simple animation loop
setInterval(pan, 15);
}
/**
* Boilerplate map initialization code starts below:
*/
//Step 1: initialize communication with the platform
var platform = new H.service.Platform({
app_id: 'DemoAppId01082013GAL',
app_code: 'AJKnXv84fjrb0KIHawS0Tg',
useCIT: true,
useHTTPS: true
});
var defaultLayers = platform.createDefaultLayers();
//Step 2: initialize a map - this map is centered over New Delhi
var map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map,{
center: {lat: 19.11, lng: 72.89},
zoom: 4
});
panTheMap(map);
$('head').append('<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" type="text/css" />');