Nokia Maps API Reference

Contents

Class nokia.maps.gfx.GraphicsImage

Class Summary

The class GraphicsImage is designed to render images within the client application at run time. The graphics image is not rendered at construction time for the same reason that a bitmap image is not loaded at construction time: rendering occurs when it is really necessary. Imagine there are 1000 map objects and the image for each object must be rendered depending on the properties of the object, for example, because the object contains traffic information. It would cost large amounts of CPU time to render all the images and consume a lot of memory to keep the image data in memory while perhaps only a few of the objects may be visible in the current view.

The rendering of a graphics image is done by a function that is not called as soon as the image is needed. The same function can be used for multiple graphics images, therefore it is possible to implement a multi-painter, so a function that renders all markers and uses the marker properties as a source of information about how to render the markers.

It is also possible to create an instance of GraphicsImage without a rendering function, but using a pre-created nokia.maps.gfx.IDL or nokia.maps.gfx.Graphics context.

Examples:
// Create a few shortcuts.
var GraphicsImage = nokia.maps.gfx.GraphicsImage,
     Color = nokia.maps.gfx.Color,
     parseCss = Color.parseCss;

// Create a reference to the document body.
var body = document.body || document.documentElement;

// Create a new graphics image.
var image = new GraphicsImage( function( graphics, graphicsImage ) {
   // This will clear the canvas and set it's size to 64 x 64 pixel
	  graphics.beginImage(64, 64, "MyImage");

	  // Let's draw a circle with a 2 pixel black border and fill it with semi
	  // transparent red color
	  graphics.set("lineWidth", 2 );
	  graphics.set("strokeColor", parseCss("black"));
	  graphics.set("fillColor", parseCss("red", 0.5));

   // Create the path using a helper function.
   graphics.drawEllipse(16,16, 32,32);
   
   // Stroke and fill the path.
   graphics.stroke();
   graphics.fill();
});

// Add the graphics image to the body. 
body.appendChild( image.createElement() );
new nokia.maps.gfx.GraphicsImage (render_fn, [context, [doc, [painter]]])
Method Summary
abstract clone ([doc]) : nokia.maps.gfx.Image This method clones the given image and optionally binds it to a different document.
abstract createElement ([opacity]) : Node This method creates a DOM node containing the given image.
abstract getDocument () : Document This method retrieves the document to which the given image is bound.
getIDL () : nokia.maps.gfx.IDL This method retrieves the IDL object created by the given instance of graphics context.
abstract prepare (callback, [context]) : nokia.maps.gfx.Image This method prepares the given image and calls a callback on completion or failure.
abstract setOpacity (element, opacity) : nokia.maps.gfx.Image This method changes the global opacity of an element returned by the createElement().
Field Summary
abstract Number height This property holds the height of the image in pixels.
Boolean isGraphics This property indicates if an image is an instace of GraphicsImage (true) or not (false).
abstract Number opacity This property holds the default opacity for the image.
abstract Number state This property holds the state of the image.
abstract Number width This property holds the width of the image in pixels.
Constructor Detail

This method creates a new graphics image instance.

new nokia.maps.gfx.GraphicsImage(render_fn, [context, [doc, [painter]]])
Examples:
// Create a few shortcuts.
var GraphicsImage = nokia.maps.gfx.GraphicsImage,
     Color = nokia.maps.gfx.Color,
     parseCss = Color.parseCss;

// Create a reference to the document body.
var body = document.body || document.documentElement;

// Create a new graphics image.
var image = new GraphicsImage( function( graphics, graphicsImage ) {
   // This will clear the canvas and set it's size to 64 x 64 pixel
	  graphics.beginImage(64, 64, "MyImage");

	  // Let's draw a circle with a 2 pixel black border and fill it with semi
	  // transparent red color
	  graphics.set("lineWidth", 2 );
	  graphics.set("strokeColor", parseCss("black"));
	  graphics.set("fillColor", parseCss("red", 0.5));

   // Create the path using a helper function.
   graphics.drawEllipse(16,16, 32,32);
   
   // Stroke and fill the path.
   graphics.stroke();
   graphics.fill();
});

// Add the graphics image to the body. 
body.appendChild( image.createElement() );
Parameters:
{Function | nokia.maps.gfx.IDL | nokia.maps.gfx.Graphics} render_fn A function to be called as soon as the image is required; the function gets as its first argument the graphics context (an instance of nokia.maps.gfx.Graphics) that it uses to render the image, and as a second parameter an instance of nokia.maps.gfx.GraphicsImage, which represents the image to render; if the constructor is called with additional arguments, these are forwarded as additional arguments to the rendering function; optionally, an instance of nokia.maps.gfx.IDL or nokia.maps.gfx.Graphics context can be supplied to create a new graphics image instantly
{Object} [context]: The context in which the rendering function is to be executed; if not specified the context (this) is bound to the given instance of nokia.maps.gfx.GraphicsImage
{Document} [doc]: The document to which the given graphics image is bound; if omitted, the image is bound to the current document
{nokia.maps.gfx.Painter} [painter]: The painter to be used to paint; if not supplied, the painter currently assigned to the static property defaultPainter of the class nokia.maps.gfx.Painter is used; if this argument has an invalid value, it is ignored and the defaultPainter is used
{Object} [args...]: An arbitrary number of additional arguments to be forwarded to the rendering function
Method Detail
getIDL () : nokia.maps.gfx.IDL
This method retrieves the IDL object created by the given instance of graphics context.
Returns:
{nokia.maps.gfx.IDL} The IDL generated by the given instance of graphics context
Field Detail
Boolean isGraphics
This property indicates if an image is an instace of GraphicsImage (true) or not (false).
Default Value:
true
Documentation generated on Mon Oct 24 2011 14:24:32 GMT+0200 (CEST).