×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to create custom graphics marker

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps)
avnee.nathani (Talk | contribs)
(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==
  
Ovi Maps API supported web browser (basically any modern web browser)
+
Nokia Maps API supported web browser (basically any modern web browser)
  
 
==Important about Maps credentials==
 
==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  
+
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  Ovi Maps API Developers Guide section "Acquiring API credentials"
+
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==
 
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
 
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.ovi.com/jsl.js" type="text/javascript" charset="utf-8">
+
     <script type="text/javascript"
    </script>
+
    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 ovi.mapsapi.map.Display(document.getElementById("map"),  // new instance of Ovi Maps
+
var map = new nokia.maps.map.Display(document.getElementById("map"),  // new instance of Nokia Maps
 
{
 
{
 
+
     components: [ new ovi.mapsapi.map.component.Behavior(),
+
     components: [ new nokia.maps.map.component.Behavior(),
                 new ovi.mapsapi.map.component.ZoomBar(),
+
                 new nokia.maps.map.component.ZoomBar(),
                 new ovi.mapsapi.map.component.Overview(),                             
+
                 new nokia.maps.map.component.Overview(),                             
                 new ovi.mapsapi.map.component.TypeSelector(),     
+
                 new nokia.maps.map.component.TypeSelector(),     
                 new ovi.mapsapi.map.component.ScaleBar()],
+
                 new nokia.maps.map.component.ScaleBar()],
     'zoomLevel': 8,  
+
     'zoomLevel': 10,  
     'center':[-33.9417, 150.9473]
+
     '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 ovi.mapsapi.map.Container();
+
             var testLayer = new nokia.maps.map.Container();
 
             map.objects.add(testLayer);     
 
             map.objects.add(testLayer);     
           
+
             var graphicsContext = new ovi.mapsapi.gfx.Graphics();
+
             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 = ovi.mapsapi.gfx.Color.compress(255, 0, 0, 127);
+
             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 ovi.mapsapi.map.Marker(
+
             var myGfxMarker = new nokia.maps.map.Marker(
                 {latitude:-33.9417, longitude:150.9473},
+
                 {latitude:19.119, longitude:72.8957},
 
                 {
 
                 {
                 icon: new ovi.mapsapi.gfx.GraphicsImage(graphicsContext.getIDL()),
+
                 icon: new nokia.maps.gfx.GraphicsImage(graphicsContext.getIDL()),
 
                 visibility: true,
 
                 visibility: true,
                 anchor: new ovi.mapsapi.util.Point(0,0),
+
                 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 Ovi Maps API==
+
==For more on Nokia Maps API==
  
Please check out the Ovi 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/2.0.0
  
http://api.maps.ovi.com
+
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
Platform(s): Web browser
Article
Created: (31 Dec 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: avnee.nathani (31 Dec 2011)

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
239 page views in the last 30 days.