- Legend to Symbols

-
Class nokia.maps.gfx.Image
This class is an abstract base class for all kinds of image implementations.
An image is immutable: after an image instance has been created, it is prepared
for painting, and once it has been prepared, it can no longer be modified. If
the prepare() method is not called explicitly after an image has
been created, the method createElement() invokes prepare()
implicitly. Preparation depends on the image type, for example, the BitmapImage
class loads the binary data of the image from a Web server, while the class
GraphicsImage generates an IDL object that makes it possible to
render the final image directly within the client, resulting in a VML, SVG
or a Canvas element.
Further implementation are possible, each implementation must add a listener to
the static array fromObjectListener to convert arbitrary objects
into instances of the Image class automatically.
Note that each image is bound to a document and can only be used with that
document. The binding must be set at image construction time and can not be
changed later. The reason is that the prepare() method call is
optional and can be explicit after the construction of the image and before
the image is used or it is called implicitly by createElement(),
which can be invoked on demand. If the document were passed as an argument to
createElement(), problems might arise for explicitly prepared images
as preparation may require knowledge about the document to which the image is to
be added.
The following code extract shows how an image can be used in different frames:
var someFunction = function (gfxImage) {
// Ensure that the given image is valid for our
// current document and if not, import it.
if (gfxImage.getDocument() !== document)
gfxImage = gfxImage.clone(document);
}
createElement().
| {Document} | [doc]: | A reference to the document to which to bind the image clone; if provided and different from the document to which the image is currently bound, the clone is bound to the document to which this argument refers |
| {nokia.maps.gfx.Image} | A reference to the image clone |
This method is synchronous and returns a rendered DOM node
that represents the image. If the image is not yet successfully
prepared, the preparation has failed or is ongoing, the returned
image may be a blank image, with a size of 0 x 0 pixels. If
the image is not yet prepared and no preparation is currently
ongoing, this method calls the prepare() method.
Note that if an image is being prepared and the returned DOM node
has the size of 0 x 0 pixels, the size may be updated automatically
as soon as the preparation has finished successfully. Therefore,
it is fail-safe to create, for example, a BitmapImage
and to call the method createElement() directly,
because if the image has not yet been loaded, it will then be
loaded asynchronously and the returned DOM node will be extended
as soon as the image is available.
// Create a bitmap image. var myImage = new nokia.maps.gfx.BitmapImage( "http://www.w3.org/Icons/WWW/w3c_home_nb.png"); // Add the image to the document, prepare() is called // by the method createElement(). var body = document.body || document.documentElement; body.appendChild(myImage.createElement());
| {Number} | [opacity]: |
If provided, the value of this argument represents the opacity of the image
being created; valid values lie between 0 (transparent) and 1 (opaque); if
the argument is not provided, the value of the image property opacity |
| {Node} | A reference to the DOM node that can be added to the document containing the given image |
// If GraphicsImage is included in the gfx // package, it returns a graphics image on // execution of the following code: var myImage = nokia.maps.gfx.Image.fromObject( '<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="600" viewBox="0 0 5 3">'+ '<rect id="black_stripe" width="5" height="3" y="0" x="0" fill="#000"/>'+ '<rect id="red_stripe" width="5" height="2" y="1" x="0" fill="#D00"/>'+ '<rect id="gold_stripe" width="5" height="1" y="2" x="0" fill="#FFCE00"/>' '</svg>' );
| {Object} | obj |
An object to be converted into an Image instance
|
| {Document} | [doc]: |
The document to which the new Image instance is to be bound;
if not provided, the current document is used
|
| {nokia.maps.gfx.Image} |
An instance of the Image class created from the received
object or null if no Image object can be created
|
| {Document} | The document to which the given image is bound (set by the constructor and cannot be modified) |
Calling this method on an image that is already prepared leads to the callback being invoked immediately. If the method is called multiple times, all the supplied callback handlers are called in the order in which the method has been called.
// Create a new bitmap image.
var myImage = new nokia.maps.gfx.BitmapImage("http://www.w3.org/Icons/WWW/w3c_home_nb.png");
// Create a callback handler that shall be called as
// soon as the image is loaded.
var myCallback = function (image, msg) {
// If preparing the image failed, show an error
// message and return.
if (image.state<1) return alert ("Failed to load image!");
// Show the message supplied to the prepare method,
// if any.
if (msg) alert (msg);
// Paint the image into the document.
var body = image.doc.body || image.doc.documentElement;
body.appendChild(image.createElement());
};
// Start the image preparation which (in this case)
// loads the bitmap from the Web server and then calls
// the callback. If the image is within the browser's
// cache, it may happen that the callback method is
// called immediately.
myImage.prepare(myCallback, null, "Hello World!");
| {Function} | callback | A function to call as soon as the preparation is finished, whether successfully or not. The function must be able to receives as its first argument a reference to the GFX image, followed by all the additional parameters passed to this method |
| {Object} | [context]: | An object representing the context in which to call the callback; if not supplied, the context (this) is bound to the given image object. |
| {Object} | [args...]: | An arbitrary number of additional arguments to be passed to the callback |
| {nokia.maps.gfx.Image} |
An instance of gfx.Image representing the given image (this)
|
createElement().
| {Node} | element |
The DOM node that was returned by the createElement()
|
| {Number} | opacity | The global opacity for the node as a number between 0 and 1 |
| {nokia.maps.gfx.Image} |
The reference to the given image object (this)
|
Note that the default value is zero, because a calculation with undefined
would lead to an NaN result
createElement() is called without a parameter. The value
must be between 0 and 1 (default).
The list below shows the possible values and explains their meaning:
- undefined - the image preparation has not been started yet
- -2 - the image preparation failed and calling the prepare again won't solve the problem
- -1 - the image preparation failed, but calling the prepare again might solve the problem
- 0 - the image preparation is currently ongoing
- 1 - the image preparation is finished successfully
Creating DOM nodes for an unprepared image or an image whose preparation failed results in an empty image with a size of 0 x 0 pixels.