×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to create custom graphics marker

From Nokia Developer Wiki
Jump to: navigation, search
Maveric (Talk | contribs)
m (Maveric - - Example code)
jasfox (Talk | contribs)
m (Jasfox - - Example code)
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Ovi]][[Category:Web]][[Category:Browser]]
+
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
==Introduction==
+
{{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.
  
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,
+
{{ArticleMetaData
which the user can drag around the map.
+
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= Internet Explorer, Firefox, Google Chrome, Opera
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= Web browser
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies=Nokia Maps 2.2.3
 +
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= Nokia Maps, JavaScript, markers, graphics
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by=<!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by=[[User:avnee.nathani]]
 +
|update-timestamp=20111231
 +
|creationdate=20110621
 +
|author=[[User:Maveric]]
 +
}}
 +
{{SeeAlso|
 +
* [http://developer.here.net/javascript_api Nokia Maps API]
 +
* [http://developer.here.net/apiexplorer/examples/api-for-js/markers/image-markers-using-css-sprite.html Image Markers using Sprites]
 +
* [http://developer.here.net/apiexplorer/examples/api-for-js/markers/svg-marker.html Creating a SVG marker]
 +
}}
  
 
==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 note 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
+
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
offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.
+
[http://developer.here.net/terms_conditions Terms and Conditions] and check the [http://developer.here.net/web/guest/plans 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 [http://developer.here.net/docs/maps_js/topics/credentials.html#acquiring-credentials here]
 
+
For more information on how to obtain the credentials, please start with the  Ovi Maps API Developers Guide section "Acquiring API credentials"
+
  
 
==Implementation==
 
==Implementation==
Line 24: Line 48:
 
==Example code==
 
==Example code==
  
You can test the example live here: http://mapswidgets.com/my_pictures_on_Ovi_Maps.php
+
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 [[How to Obtain Your Own Nokia appID and Token| AppId and Token]].
  
Please note the images are being zoomed to be visible on the current zoom level. However, you would need
+
<code javascript>
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.3/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");
  
 
+
//
<code java>
+
/////////////////////////////////////////////////////////////////////////////////////
<html>
+
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"),  // new instance of Nokia Maps
<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(),
+
     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 106:
 
             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==
+
 
+
Please check out the Ovi Maps API full documentation and API reference here:
+
  
http://api.maps.ovi.com
+
==Screenshot==
 +
[[File:NokiaMapsGraphicsMarker.png|600px]]
  
==Tested with==
+
==For more on the Nokia Maps API==
  
Google Chrome 11.0x
+
Please check out the Nokia Maps API full documentation and API reference here:
 +
* [http://developer.here.net/javascript_api Nokia Maps API]
  
Mozilla Firefox 5.0
+
You may also access the interactive API explorer
 +
* [http://developer.here.net/javascript_api_explorer API explorer]

Revision as of 14:26, 4 January 2013

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.3
Article
Keywords: Nokia Maps, JavaScript, markers, graphics
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (04 Jan 2013)

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

<!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.3/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 the Nokia Maps API

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

You may also access the interactive API explorer

339 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.

×