Show:

File: ia\maps\layers\ImageLayer.js

/** 
 * The base class for Image layers - ags and wms.
 *
 * @author J Clare
 * @class ia.ImageLayer
 * @extends ia.LayerBase
 * @constructor
 */
ia.ImageLayer = function()
{
	ia.ImageLayer.baseConstructor.call(this, "");
	
	this._item = undefined;
	this.url = "";
	this.params = "";
	this.layers = "";
	this.srs = "";
	this.version = "";
};
ia.extend(ia.LayerBase, ia.ImageLayer);

/**
 * The url.
 *
 * @property url
 * @type String
 * @default ""
 */
ia.ImageLayer.prototype.url;

/**
 * Any additional params.
 *
 * @property params
 * @type String
 * @default ""
 */
ia.ImageLayer.prototype.params;

/**
 * Determines which layers appear on the exported map.
 *
 * @property layers
 * @type String
 * @default ""
 */
ia.ImageLayer.prototype.layers;

/**
 * The spatial reference system. 
 *
 * @property srs
 * @type String
 * @default ""
 */
ia.ImageLayer.prototype.srs;

/**
 * The version number. 
 *
 * @property version
 * @type String
 * @default ""
 */
ia.ImageLayer.prototype.version;

/** 
 * Renders the image.
 *
 * @method render
 */
ia.ImageLayer.prototype.render = function() 
{
	if (this.map && this.getVisible())  
	{
		// Draw cached images straight away to avoid blank background.
		this.clear();
		this.draw(this.context);

			$j.support.cors = true;
		// Create a new image this._item.
		var img = new Image();
		
		this._item = {};
		this._item.bBox = this.map.getBBox().clone();
		this._item.img = img;
		
		var me = this;
		// Draw image as soon as loaded
		img.onload = function() 
		{
			var r = me.map.getPixelRect(me._item.bBox);
			me.clear();
			me.context.drawImage(me._item.img, r.x, r.y, r.width, r.height);
		};
		//img.crossOrigin = 'anonymous'; // Doesnt work unless server specifies it can.
		img.src = this.getUrl(this.map.getBBox(), this.map.canvasWidth, this.map.canvasHeight);
	}
};
	
/**
 * Draws the image without reloading it.
 *
 * @method draw
 * @param {HTML Canvas Context} ctx The context to render to.
 */
ia.ImageLayer.prototype.draw = function(ctx)
{
	try 
	{		
		if (this._item && this._item.img)
		{
			var r = this.map.getPixelRect(this._item.bBox);
			ctx.drawImage(this._item.img, r.x, r.y, r.width, r.height);
		}
	} 
	catch (error) 
	{
		ia.log(error)
	}
}

/**
 * Returns the required url.
 * 
 * @method getUrl
 * @return The url for retrieving the layer info.
 */
ia.ImageLayer.prototype.getUrl = function(bb, w, h) {};