HERE Maps API - How to create custom graphics marker
hamishwillee
(Talk | contribs) m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps) |
(Avnee.nathani - Updated article for Nokia Maps Javascript API v2.0. (Released in Dec 2011)) |
||
| Line 1: | Line 1: | ||
[[Category:Web]][[Category:Browser]][[Category:Nokia Maps]] | [[Category:Web]][[Category:Browser]][[Category:Nokia Maps]] | ||
| + | {{Abstract|This article explains how to create a custom graphics marker on Nokia maps. }} | ||
| + | |||
| + | {{ArticleMetaData | ||
| + | |platform= Web browser | ||
| + | |update-by=[[User:avnee.nathani]] | ||
| + | |update-timestamp=20111231 | ||
| + | }} | ||
| + | |||
==Introduction== | ==Introduction== | ||
| Line 7: | Line 15: | ||
==Prerequisites== | ==Prerequisites== | ||
| − | + | Nokia Maps API supported web browser (basically any modern web browser) | |
==Important about Maps credentials== | ==Important about Maps credentials== | ||
| − | With | + | With Nokia 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. | 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 | + | For more information on how to obtain the credentials, please start with the Nokiai Maps API Developers Guide section "Acquiring API credentials" |
==Implementation== | ==Implementation== | ||
| Line 23: | Line 31: | ||
==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 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. | to zoom in more towards the images to see the ones that maybe layered under the top images. | ||
| − | |||
| − | |||
<code java> | <code java> | ||
<html> | <html> | ||
<head> | <head> | ||
| − | <script src="http://api.maps. | + | <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" /> | <link rel="stylesheet" href="style.css" /> | ||
</head> | </head> | ||
| Line 43: | Line 48: | ||
</body> | </body> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
| − | + | ||
| − | var map = new | + | var map = new nokia.maps.map.Display(document.getElementById("map"), // new instance of Nokia Maps |
{ | { | ||
| − | + | ||
| − | components: [ new | + | components: [ new nokia.maps.map.component.Behavior(), |
| − | new | + | new nokia.maps.map.component.ZoomBar(), |
| − | new | + | new nokia.maps.map.component.Overview(), |
| − | new | + | new nokia.maps.map.component.TypeSelector(), |
| − | new | + | new nokia.maps.map.component.ScaleBar()], |
| − | 'zoomLevel': | + | 'zoomLevel': 10, |
| − | 'center':[ | + | 'center':[19.119, 72.8957] |
}); | }); | ||
| − | + | ||
map.set("baseMapType", map.NORMAL); | map.set("baseMapType", map.NORMAL); | ||
| − | + | ||
// Create a test layer | // Create a test layer | ||
| − | var testLayer = new | + | var testLayer = new nokia.maps.map.Container(); |
map.objects.add(testLayer); | map.objects.add(testLayer); | ||
| − | + | ||
| − | var graphicsContext = new | + | var graphicsContext = new nokia.maps.gfx.Graphics(); |
graphicsContext.beginImage(64,64); | graphicsContext.beginImage(64,64); | ||
| − | + | ||
// Compress a semi-transparent red color | // Compress a semi-transparent red color | ||
| − | + | ||
| − | var my_fill_color = | + | var my_fill_color = nokia.maps.gfx.Color.compress(255, 0, 0, 127); |
| − | + | ||
graphicsContext.set("fillColor", my_fill_color); | graphicsContext.set("fillColor", my_fill_color); | ||
graphicsContext.set("strokeColor", "#000"); | graphicsContext.set("strokeColor", "#000"); | ||
| Line 75: | Line 80: | ||
graphicsContext.fill(); | graphicsContext.fill(); | ||
graphicsContext.stroke(); | graphicsContext.stroke(); | ||
| − | var myGfxMarker = new | + | var myGfxMarker = new nokia.maps.map.Marker( |
| − | {latitude: | + | {latitude:19.119, longitude:72.8957}, |
{ | { | ||
| − | icon: new | + | icon: new nokia.maps.gfx.GraphicsImage(graphicsContext.getIDL()), |
visibility: true, | visibility: true, | ||
| − | anchor: new | + | anchor: new nokia.maps.util.Point(0,0), |
draggable: true | draggable: true | ||
} | } | ||
); | ); | ||
testLayer.objects.add(myGfxMarker); | testLayer.objects.add(myGfxMarker); | ||
| − | + | ||
</script> | </script> | ||
</body> | </body> | ||
</html> | </html> | ||
| − | |||
</code> | </code> | ||
| − | ==For more on | + | ==For more on Nokia Maps API== |
| − | Please check out the | + | Please check out the Nokia Maps API full documentation and API reference here: |
| + | * http://api.maps.nokia.com/2.0.0 | ||
| − | http://api.maps. | + | You may also access the interactive Nokia Maps API playground, |
| + | * http://api.maps.nokia.com/playground/index.html | ||
==Tested with== | ==Tested with== | ||
| − | Google Chrome 11.0x | + | * Google Chrome 11.0x |
| − | + | * Mozilla Firefox 5.0 | |
| − | Mozilla Firefox 5.0 | + | |
Revision as of 12:22, 31 December 2011
This article explains how to create a custom graphics marker on Nokia maps.
Article Metadata
Compatibility
Article
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
Nokia Maps API supported web browser (basically any modern web browser)
Important about Maps credentials
With Nokia 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 Nokiai 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
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>
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

