×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - How to create custom graphics marker

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - - Example code)
jasfox (Talk | contribs)
m (Jasfox - - For more on the HERE Maps API)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
+
[[Category:HERE Maps]][[Category:JavaScript]][[Category:Code Examples]]
{{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 HERE Maps using the GFX library. }}  The example creates a translucent ellipse which the user can drag around the map.
  
{{ArticleMetaData
+
{{ArticleMetaData <!-- v1.2 -->
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode=  [[https://github.com/heremaps/examples/blob/master/maps_api_for_javascript/advanced-examples/custom-graphics-marker.html custom-graphics-marker.html]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Internet Explorer, Firefox, Google Chrome, Opera
 
|devices= Internet Explorer, Firefox, Google Chrome, Opera
Line 9: Line 9:
 
|platform= Web browser
 
|platform= Web browser
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies=Nokia Maps 2.2.3
+
|dependencies= HERE Maps 2.5.3
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|keywords= Nokia Maps, JavaScript, markers, graphics
+
|keywords= HERE Maps, JavaScript, markers, graphics
|id= <!-- Article Id (Knowledge base articles only) -->
+
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only -->  
+
|translated-from-title= <!-- Title only -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
|update-by=[[User:avnee.nathani]]
+
|update-by= [[User:avnee.nathani]]
|update-timestamp=20111231
+
|update-timestamp= 20111231
|creationdate=20110621
+
|creationdate= 20110621
|author=[[User:Maveric]]
+
|author= [[User:Maveric]]
 
}}
 
}}
 
{{SeeAlso|
 
{{SeeAlso|
* [http://developer.here.net/javascript_api Nokia Maps API]
+
* [http://developer.here.com/javascript_api HERE Maps API]
* [http://developer.here.net/apiexplorer/examples/api-for-js/markers/image-markers-using-css-sprite.html Image Markers using Sprites]
+
* [http://heremaps.github.io/examples/index.html HERE Maps on Github]
* [http://developer.here.net/apiexplorer/examples/api-for-js/markers/svg-marker.html Creating a SVG marker]
+
* [http://developer.here.com/apiexplorer/examples/api-for-js/markers/image-markers-using-css-sprite.html Image Markers using Sprites]
 +
* [http://developer.here.com/apiexplorer/examples/api-for-js/markers/svg-marker.html Creating a SVG marker]
 
  }}
 
  }}
  
 
==Prerequisites==
 
==Prerequisites==
  
Nokia Maps API supported web browser (basically any modern web browser)
+
HERE Maps API supported web browser (basically any modern web browser)
  
 
==Important note about maps credentials==
 
==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
+
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
 
[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]
 
[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]
  
Line 51: Line 51:
  
 
<code javascript>
 
<code javascript>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
function createGraphicsMarker(map){
<html xmlns="http://www.w3.org/1999/xhtml">
+
var graphicsContext = new nokia.maps.gfx.Graphics();
    <head>
+
graphicsContext.beginImage(64,64);
      <title>Custom Graphics Markers</title>
+
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
// Compress a semi-transparent red color
      <script type="text/javascript"
+
            src="http://api.maps.nokia.com/2.2.3/jsl.js" charset="utf-8">
+
var my_fill_color = nokia.maps.gfx.Color.compress(255, 0, 0, 127);
        </script>
+
    </head>
+
graphicsContext.set("fillColor", my_fill_color);
    <body>
+
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}
 +
);
 +
map.objects.add(myGfxMarker);
 +
}</code>
  
        <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></code>
 
 
==Screenshot==
 
 
[[File:NokiaMapsGraphicsMarker.png|600px]]
 
[[File:NokiaMapsGraphicsMarker.png|600px]]
  
==For more on the Nokia Maps API==
+
The following fully working example can be found at:
  
Please check out the Nokia Maps API full documentation and API reference here:
+
http://heremaps.github.io/examples/examples.html#custom-graphics-marker
* [http://developer.here.net/javascript_api Nokia Maps API]
+
 
 +
==For more on the HERE Maps API==
 +
 
 +
Please check out the HERE Maps API full documentation and API reference here:
 +
* [http://developer.here.com/javascript_api HERE Maps API]
  
 
You may also access the interactive API explorer
 
You may also access the interactive API explorer
* [http://developer.here.net/javascript_api_explorer API explorer]
+
* [http://developer.here.com/javascript_api_explorer API explorer]
 +
 
 +
And additional examples on GitHub
 +
* [http://heremaps.github.io/examples/ HERE Maps on Github]

Latest revision as of 20:29, 12 March 2014

This article explains how to create a custom graphics marker on HERE Maps using the GFX library. The example creates a translucent ellipse which the user can drag around the map.

Article Metadata
Code ExampleTested with
Devices(s): Internet Explorer, Firefox, Google Chrome, Opera
Compatibility
Platform(s): Web browser
Dependencies: HERE Maps 2.5.3
Article
Keywords: HERE Maps, JavaScript, markers, graphics
Created: Maveric (21 Jun 2011)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (12 Mar 2014)

Contents

[edit] Prerequisites

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

[edit] 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

[edit] 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.


[edit] 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.

function createGraphicsMarker(map){
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}
);
map.objects.add(myGfxMarker);
}


NokiaMapsGraphicsMarker.png

The following fully working example can be found at:

http://heremaps.github.io/examples/examples.html#custom-graphics-marker

[edit] For more on the HERE Maps API

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

You may also access the interactive API explorer

And additional examples on GitHub

This page was last modified on 12 March 2014, at 20:29.
248 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.

×