Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 12:16, 3 January 2013 by jasfox (Talk | contribs)

HERE Maps API - How to use sprite images as map marker icons

From Wiki
Jump to: navigation, search

A sprite is a two-dimensional image or animation that is integrated or overlaid into a larger scene. This article shows how to overlay sprites over a map using the Nokia Map API's GFX library method.

Article Metadata
Tested with
Devices(s): Mozilla FireFox , Internet Exploere, Google Chrome, Safari
Platform(s): Web
Dependencies: Nokia Maps 2.2.3
Keywords: Nokia Maps, JavaScript, sprites, markers
Created: Maveric (29 Nov 2011)
Last edited: jasfox (03 Jan 2013)



The example code below will load an online icon pack image (iconPackUrl) and then use the Map API's GFX library method (gfx.BitmapImage) to pick up images out of the pack defined by a position and a size. These bitmaps will then be attached to map marker icons to be displayed onscreen.

The icon image is a free icon pack called "1945" and can be obtained in various image formats, one is located here:

Note: this image is partially edited for transparency.

Example Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<title>Sprite Images</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="" charset="utf-8">
<div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<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
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
var iconPackUrl = "",
map = new"mapContainer"), {
center: new nokia.maps.geo.Coordinate(1.381667, 173.146944),
zoomLevel: 3,
components: [ new ]
// create an icon from the icon pack url, specify the size (30px x 30px) and an offset
// in the image where icon is (30px from the left border, 30px from the top).
shipBitmap = new nokia.maps.gfx.BitmapImage(iconPackUrl, null, 32, 180, 470, 310),
// create a second icon from the same url, specify the size (30px x 30px) and another offset
// in the image where icon is (52px from the left border, 13px from the top).
planeBitmap = new nokia.maps.gfx.BitmapImage(iconPackUrl, null, 50, 44, 308, 112),
// Create marker no 1
ship = new nokia.maps.geo.Coordinate(1.381667, 173.166944), {
icon: shipBitmap
// Create marker no 2
plane = new nokia.maps.geo.Coordinate(1.371667, 173.146944), {
icon: planeBitmap
// Set Map center point
map.set("center", [-1.366667, 176.466667]);
// Define the map type to be SATELLITE
map.set("baseMapType", map.SATELLITE);
// Create a new container
markerContainer = new
// Add marker 1 to the container
// Add marker 2 to the container
// Add the container to the map
// Zoom the map to cover the markers of the container

See this example online


You can see sprite images a Map marker icons below.

MapImg2.png MapImg1.png

115 page views in the last 30 days.