×
Namespaces

Variants
Actions
Revision as of 11:12, 22 June 2011 by Maveric (Talk | contribs)

HERE Maps API - How to create custom graphics marker

From Nokia Developer Wiki
Jump to: navigation, search

Contents

Introduction

In this article we will examine how to create a custom marker with using the GFX library. In the example we will create a transparent ellipse, which the user can drag around the map.

Prerequisites

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

Important about Maps credentials

With Ovi Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.

For more information on how to obtain the credentials, please start with the Ovi Maps API Developers Guide section "Acquiring API credentials"

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

You can test the example live here: http://mapswidgets.com/my_pictures_on_Ovi_Maps.php

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 src="http://api.maps.ovi.com/jsl.js" type="text/javascript" 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 ovi.mapsapi.map.Display(document.getElementById("map"), // new instance of Ovi Maps
{
 
components: [ new ovi.mapsapi.map.component.Behavior(),
new ovi.mapsapi.map.component.ZoomBar(),
new ovi.mapsapi.map.component.Overview(),
new ovi.mapsapi.map.component.TypeSelector(),
new ovi.mapsapi.map.component.ScaleBar()],
'zoomLevel': 8,
'center':[-33.9417, 150.9473]
});
 
map.set("baseMapType", map.NORMAL);
 
// Create a test layer
var testLayer = new ovi.mapsapi.map.Container();
map.objects.add(testLayer);
 
var graphicsContext = new ovi.mapsapi.gfx.Graphics();
graphicsContext.beginImage(64,64);
 
// Compress a semi-transparent red color
 
var my_fill_color = ovi.mapsapi.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 ovi.mapsapi.map.Marker(
{latitude:-33.9417, longitude:150.9473},
{
icon: new ovi.mapsapi.gfx.GraphicsImage(graphicsContext.getIDL()),
visibility: true,
anchor: new ovi.mapsapi.util.Point(0,0),
draggable: true
}
);
testLayer.objects.add(myGfxMarker);
 
</script>
</body>
</html>

For more on Ovi Maps API

Please check out the Ovi Maps API full documentation and API reference here:

http://api.maps.ovi.com

Tested with

Google Chrome 11.0x

Mozilla Firefox 5.0

259 page views in the last 30 days.