- Legend to Symbols

-
Class nokia.maps.gfx.BitmapImage
The class BitmapImage loads a bitmap (PNG, GIF, JPEG and others) from a
Web server and makes it available as a GFX image. The difference between a GFX image
and a native DOM image is that a GFX image is not loaded unless it is necessary
or forced by calling prepare(). Additionally, a GFX image can be clipped
(sprite creation).
The main purpose of sprite images is to save server requests by adding multiple images into one image and then clip this single image to produce multiple images from one. GFX images are also used if it is unclear exactly when an image should be loaded. This applies for example to instances of nokia.maps.map.Marker and their icons. For example, you may add a thousand markers with different icon images to the map, but you only need to load those for the markers that are within the visible viewport.
// Create a reference to the document body.
var body = document.body || document._documentElement;
// Create a new bitmap.
var bitmap = new nokia.maps.gfx.BitmapImage("http://www.w3.org/Icons/WWW/w3c_home_nb.png");
// Add the bitmap in original size into the body.
body.appendChild(bitmap.createElement());
// Clone the bitmap, pick out the center of the image (from pixel 16,16 a square of 32 pixel)
// and add that to the document body.
var sprite = bitmap.clone(document, 32,32, 16,16);
body.appendChild(sprite.createElement());
// Display the size of the image as soon as it is known.
sprite.prepare(function (img) {
alert("natural image size: " + img.naturalWidth + "x" + img.naturalHeight);
alert("current sprite offset-x/y: " + img.offsetX + ", " + img.offsetY + " with " + img.width + "x" + img.height + "px size");
});
createElement().
undefined, if the image is not to be used to create a sprite.
undefined, if the image is not to be used to create a sprite.
This method creates a new image from an image URL or an already loaded HTML image.
The method accepts four optional parameters for width, height, x- and y-offset to define a viewport for an image and to allow for spriting. If only the width and height are supplied, but no x- and y-offset, then the image is scaled to match these dimensions. If no width or height are provided by the caller at all, the image size remains unchanged.
// Create a reference to the document body.
var body = document.body || document._documentElement;
// Create a new bitmap.
var bitmap = new nokia.maps.gfx.BitmapImage("http://www.w3.org/Icons/WWW/w3c_home_nb.png");
// Add the bitmap in original size into the body.
body.appendChild(bitmap.createElement());
// Clone the bitmap, pick out the center of the image (from pixel 16,16 a square of 32 pixel)
// and add that to the document body.
var sprite = bitmap.clone(document, 32,32, 16,16);
body.appendChild(sprite.createElement());
// Display the size of the image as soon as it is known.
sprite.prepare(function (img) {
alert("natural image size: " + img.naturalWidth + "x" + img.naturalHeight);
alert("current sprite offset-x/y: " + img.offsetX + ", " + img.offsetY + " with " + img.width + "x" + img.height + "px size");
});
| {String | Image} | image | Either a URL of an image or an already loaded HTML image |
| {Document} | [doc]: |
The document to which the instance of BitmapImage is to be bound;
if this argument is omitted, the current document is used
|
| {Number} | [width]: | The target width of the image in pixels |
| {Number} | [height]: | The target height of the image in pixels |
| {Number} | [offsetX]: | The x-offset within the image to create a sprite (in pixels) |
| {Number} | [offsetY]: | The y-offset within the image to create a sprite (in pixels) |
| {Document} | [doc]: | A reference to a document to which the image should be attached |
| {Number} | [width]: | The target width of the image in pixels; if not provided, the current value is used |
| {Number} | [height]: | The target height of the image in pixels; if not provided, the current value is used |
| {Number} | [offsetX]: | The x-offset within the image to create a sprite (in pixels); if not provided, the current value is used |
| {Number} | [offsetY]: | The y-offset within the image to create a sprite (in pixels); if not provided, the current value is used |
| {nokia.maps.gfx.BitmapImage} | An object representing the cloned image |
- Default Value:
- true
undefined until
the image has been prepared successfully.
undefined until
the image has been prepared successfully.
undefined, if the image is not to be used to
create a sprite.