/**
* @class
* A strategy that orders the z-index of all LIMBs according to the distance to the target.
* LIMBs representing targets that are closest to the map will be shown above those that are further away.
*
* @constructor
* @param {lucid.maps.limbs.layout.OrderedLayoutStrategyOptions} options The options controlling the layout.
*/
lucid.maps.limbs.layout.OrderedLayoutStrategy = function( options )
{
lucid.maps.limbs.layout.LayoutStrategy.apply( this, [options] );
var limbs;
var maxDistance;
this.layout = function( div, position, mapDetails )
{
var distance = google.maps.geometry.spherical.computeDistanceBetween( mapDetails.viewCentre, mapDetails.targetLocation );
if (distance > maxDistance)
{
maxDistance = distance;
}
limbs[limbs.length] = { element: div,
position: position,
distance: distance };
};
this.init = function()
{
limbs = [];
maxDistance = 0;
};
this.complete = function()
{
var zIndexMin = this.getMinZIndex();
var zIndexMax = this.getMaxZIndex();
var zIndexRange = zIndexMax - zIndexMin;
var zIndexDistanceRatio = zIndexRange / maxDistance;
for (var i=0; i<limbs.length; i++)
{
var limb = limbs[i];
limb.element.css( "left", limb.position.x );
limb.element.css( "top", limb.position.y );
limb.element.css( "zIndex", computeLimbElementZIndex( limb.distance ) );
}
limbs = null;
maxDistance = null;
function computeLimbElementZIndex( distance )
{
return Math.floor( zIndexMax - (zIndexDistanceRatio * distance) );
}
};
};
/**
* @type {object}
* @augments lucid.maps.limbs.layout.LayoutStrategyOptions
*/
lucid.maps.limbs.layout.OrderedLayoutStrategyOptions = {};