×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to create custom graphics marker

From Nokia Developer Wiki
Jump to: navigation, search
Oskar Bukolt (Talk | contribs)
m (Oskar Bukolt - Update JS lib + API link)
Oskar Bukolt (Talk | contribs)
m (Oskar Bukolt - Update API links + minor text alteration)
Line 1: Line 1:
 
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
 
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
{{Abstract|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.
+
{{Abstract|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.
  
 
{{ArticleMetaData
 
{{ArticleMetaData
Line 48: Line 48:
 
==Example code==
 
==Example code==
  
Please note the images are being zoomed to be visible on the current zoom level. However, you would need
+
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.
 
to zoom in more towards the images to see the ones that maybe layered under the top images.
  
Line 128: Line 128:
  
 
Please check out the Nokia Maps API full documentation and API reference here:
 
Please check out the Nokia Maps API full documentation and API reference here:
* http://api.maps.nokia.com/
+
* http://api.maps.nokia.com/en/maps/intro.html
  
 
You may also access the interactive Nokia Maps API playground,
 
You may also access the interactive Nokia Maps API playground,
 
* http://api.maps.nokia.com/en/playground/env/desktop/
 
* http://api.maps.nokia.com/en/playground/env/desktop/

Revision as of 18:26, 16 July 2012

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
Tested with
Devices(s): Internet Explorer, Firefox, Google Chrome, Opera
Compatibility
Platform(s): Web browser
Dependencies: Nokia Maps 2.2.1
Article
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: Oskar Bukolt (16 Jul 2012)

Contents

Prerequisites

Nokia 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 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 free 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 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.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Custom Graphics Markers</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.1/jsl.js" charset="utf-8">
</script>
</head>
<body>
 
<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 http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
 
//
/////////////////////////////////////////////////////////////////////////////////////
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"), // 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,

231 page views in the last 30 days.
×