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 15:39, 3 January 2013 by jasfox (Talk | contribs)

HERE Maps API - How to create a custom overlay

From Wiki
Jump to: navigation, search

Tip.pngTip: Although the background information here is still correct, the code in the article refers to an outdated version of the API. Much of the code has been superseded as it is now possible create custom overlays directly using the technique described here: The code may still prove useful when creating and attempting to align your own custom overlay over a the map however.

This article explains how to create a custom overlay and add data from your own tile server to the map.

Article Metadata
Code ExampleTested with
Devices(s): Internet Explorer, Google Chrome, Firefox
Platform(s): Web
Dependencies: Nokia Maps 2.2.3
Keywords: Nokia Maps, Overlay, Map Provider, Data
Created: jasfox (15 Jun 2012)
Last edited: jasfox (03 Jan 2013)



For extremely large data sets, it no longer makes sense to add each data point as an individual marker, image or polyline. In situations such as displaying weather or traffic conditions over a map, it would be less processor intensive to retrieve pre-built images from a tiler server rather than re-calculating and adding a large number of mapObjects on to the map display. The cost of making a few extra round trips to retrieve data from a server will be much smaller than the equivalent client side processing of adding hundreds of thousands of objects onto the map.

This article introduces a JavaScript library to overlay images over a map. It handles the data calls to an arbitrary tile server which generates tiles in the Normalised Mercator projection, which is the commonest format for online maps. It also handles the necessary attribution of the overlay images. The code example retrieves Map Tiles from a tile server run by the National Library of Scotland . The mapping is based on out-of-copyright Ordnance Survey maps, dating from the 1920s to the 1940s.

How Map Providers and Overlays Work

For the base map providers, the globe is divided into individual map tiles. These are retrieved online from Nokia’s map tile service.

  • At minimum zoom, the world is contained in a single 256x256 pixel tile.
  • At the next zoom level up, the world is 2 tiles wide and 2 tiles high. Then 4x4, 8x8, 16x16 etc.
  • Each zoom level splits the tiles in two, doubling the number of tiles across the width and height
  • Each Map is based on the Normalized Mercator projection.

Custom overlays work in the same fashion - using your own map tile server complex visual data can be displayed at different zoom levels.

  • One tile at minimum zoom, then 2x2, 4x4 and so on.
  • Must be based on the Normalized Mercator projection.
  • Use .png tiles to support transparency, so underlying map can be seen beneath your data.

Nm overlay.png

Normalised Mercator Projection

The Nokia Maps API offers maps using the Normalised Mercator Projection. This covers the globe as a square from 85.0511°N to 85.0511°S and across all longitudes. At the lowest zoom this is contained within an individual map tile. The number of map tiles displayed doubles on each axis as the zoom level increases, therefore it is possible to obtain a map tile image at any location {x, y} on the globe (apart from the poles) at any zoom where:

  • The x axis runs from 0 (left edge is 180°W) to 2^zoom -1 (right edge is 180 °E)
  • The y axis runs from 0 (top edge is 85.0511°N) to 2^zoom -1 (bottom edge is 85.0511 °S)

The relationship between the longitude λ and latitude φ in radians and the map tiles {x, y} is defined as follows:

  • {λ, φ} -> [-1, 1] x [-1, 1]
  • x = λ / π
  • y = ln(tan(π/4 + φ/2)) / π

Obviously as the zoom level increase, the number of tiles across the width of the globe also increases:

Zoom Level Tile Width
1st zoom level 1 tile
2nd zoom level 2 tiles
3rd zoom level 4 tiles
nth zoom level 2^n tiles

Adding Attribution

Unless you own your own map tile source, you will have to comply with the licensing agreement of the map tile provider. In many cases this will mean giving some attribution to the original owner, even if the tiles are being offered without cost. Here is the licensing agreement from the National Library of Scotland used in the example:

"You can embed the map in your own website, display your own markers or mapping data on top of it, use it for research purposes, or create derivative work from it. The only condition is that you must display an attribution to the National Library of Scotland, together with a link to the National Library of Scotland website whenever our map is used. If you create derivative work, the documentation of your work must contain this attribution"

var copyright = new Copyright(new nokia.maps.geo.BoundingBox (new nokia.maps.geo.Coordinate (90, 180),
new nokia.maps.geo.Coordinate (-90, -180)),
"Historical maps from <br/><a href=''>NLS Maps API<\/a>");


Through using the functions in the Code Example it is possible to overlay map tile data over a Nokia map. If the images are returned in the .png format, transparency will be respected and the Nokia Map will show through underneath. - feel free to adapt the code to your own use.

Nm overlay2.png

279 page views in the last 30 days.