×
Namespaces

Variants
Actions

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 HERE Maps using the GFX library. The example creates a translucent ellipse which the user can drag around the map.

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, markers, graphics
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (12 Mar 2014)

Contents

Prerequisites

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

Important note about maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but you must obtain and use authentication and authorization credentials to use the services. Please read the Terms and Conditions and check the Pricing Plans 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 free for free following the instructions here

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 that the images are zoomed to be visible on the current zoom level. You would need to zoom in more towards the images to see the ones that maybe layered under the top images. Remember to add in your own AppId and Token.

function createGraphicsMarker(map){
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}
);
map.objects.add(myGfxMarker);
}


NokiaMapsGraphicsMarker.png

The following fully working example can be found at:

http://heremaps.github.io/examples/examples.html#custom-graphics-marker

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

And additional examples on GitHub

This page was last modified on 12 March 2014, at 17:29.
266 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×