×
Namespaces

Variants
Actions
Revision as of 15:33, 14 February 2012 by jasfox (Talk | contribs)

HERE Maps API - How to create custom graphics marker

From Nokia Developer Wiki
Jump to: navigation, search

This article explains how to create a custom graphics marker on Nokia maps using the GFX library. The example creates a transparent ellipse which the user can drag around the map.

Article Metadata
Compatibility
Platform(s): Web browser
Dependencies: Nokia Maps 2.1.0
Article
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (14 Feb 2012)

Contents

Prerequisites

Nokia Maps API supported web browser (basically any modern web browser)

Important about Maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but if you complete the free registration process and obtain authentication and authorization credentials, your application will have priority access to the service and will thus avoid a potential performance penalty. Please read the Location API Business Models and Usage Restrictions page to decide which business model best fits your needs. Authentication requires unique Maps API credentials, namely an AppId and a token. You can get these credentials from the Nokia Developer API Registration page.

Implementation

We will create a map with the set of basic user controls, and center the map with a zoom level. The testLayer refers to a new map Container we create. We then add the container to the map objects and graphicsContext variable will have an instance of the GFX library Graphics object.


Example code

Please note the images are being zoomed to be visible on the current zoom level. However, you would need to zoom in more towards the images to see the ones that maybe layered under the top images.

<html>
<head>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.0.0/jsl.js" charset="utf-8">
</script>
<link rel="stylesheet" href="style.css" />
</head>
<div id="map" style="width:100%; height:80%;"></div>
<body style = "width:80%; height:80%;">
</div>
</body>
<script type="text/javascript">
 
var map = new nokia.maps.map.Display(document.getElementById("map"), // new instance of Nokia Maps
{
 
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': 10,
'center':[19.119, 72.8957]
});
 
map.set("baseMapType", map.NORMAL);
 
// Create a test layer
var testLayer = new nokia.maps.map.Container();
map.objects.add(testLayer);
 
var graphicsContext = new nokia.maps.gfx.Graphics();
graphicsContext.beginImage(64,64);
 
// Compress a semi-transparent red color
 
var my_fill_color = nokia.maps.gfx.Color.compress(255, 0, 0, 127);
 
graphicsContext.set("fillColor", my_fill_color);
graphicsContext.set("strokeColor", "#000");
graphicsContext.set("lineWidth", 4);
graphicsContext.drawEllipse(1, 1, 48, 48);
graphicsContext.fill();
graphicsContext.stroke();
var myGfxMarker = new nokia.maps.map.Marker(
{latitude:19.119, longitude:72.8957},
{
icon: new nokia.maps.gfx.GraphicsImage(graphicsContext.getIDL()),
visibility: true,
anchor: new nokia.maps.util.Point(0,0),
draggable: true
}
);
testLayer.objects.add(myGfxMarker);
 
</script>
</body>
</html>

Screenshot

NokiaMapsGraphicsMarker.png

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,

Tested with

  • Google Chrome 11.0x
  • Mozilla Firefox 5.0
264 page views in the last 30 days.