2
* @fileOverview Contains class definition for a simple layer manager
3
* @author <a href="mailto:keith.hughitt@nasa.gov">Keith Hughitt</a>
5
/*jslint browser: true, white: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true,
6
bitwise: true, regexp: true, strict: true, newcap: true, immed: true, maxlen: 120, sub: true */
9
var LayerManager = Class.extend(
10
/** @lends LayerManager.prototype */
14
* @description Creates a new LayerManager
18
this._maxLayerDimensions = {width: 0, height: 0};
22
* @description Add a new layer
24
addLayer: function (layer) {
25
this._layers.push(layer);
29
* @description Gets the number of layers currently loaded
30
* @return {Integer} Number of layers present.
33
return this._layers.length;
37
* Returns the index of the given layer if it exists, and -1 otherwise
39
indexOf: function (id) {
42
$.each(this._layers, function (i, item) {
52
* Updates the stored maximum dimensions. If the specified dimensions for updated are {0,0}, e.g. after
53
* a layer is removed, then all layers will be checked
55
updateMaxDimensions: function (event) {
56
var type = event.type.split("-")[0];
57
this.refreshMaxDimensions(type);
61
* Rechecks maximum dimensions after a layer is removed
63
refreshMaxDimensions: function (type) {
64
var maxWidth = 0, maxHeight = 0, old = this._maxLayerDimensions;
66
$.each(this._layers, function () {
67
var d = this.getDimensions();
69
maxWidth = Math.max(maxWidth, d.width);
70
maxHeight = Math.max(maxHeight, d.height);
73
this._maxLayerDimensions = {
78
if ((this._maxLayerDimensions.width !== old.width) || (this._maxLayerDimensions.height !== old.height)) {
79
$(document).trigger("layer-max-dimensions-changed", [type, this._maxLayerDimensions]);
84
* @description Returns the largest width and height of any layers (does not have to be from same layer)
85
* @return {Object} The width and height of the largest layer
87
getMaxDimensions: function () {
88
return this._maxLayerDimensions;
92
* @description Removes a layer
93
* @param {string} The id of the layer to remove
95
removeLayer: function (id) {
96
var type = id.split("-")[0],
97
index = this.indexOf(id),
98
layer = this._layers[index];
100
layer.domNode.remove();
101
this._layers = $.grep(this._layers, function (e, i) {
102
return (e.id !== layer.id);
106
this.refreshMaxDimensions(type);
110
* @description Iterates through layers
112
each: function (fn) {
113
$.each(this._layers, fn);
117
* @description Returns a string representation of the layers currently being displayed
119
serialize: function () {
122
$.each(this._layers, function () {
123
layers += "[" + this.serialize() + "],";
126
// Remove trailing comma
127
layers = layers.slice(0, -1);
133
* @description Returns a JSON representation of the layers currently being displayed
135
toJSON: function () {
138
$.each(this._layers, function () {
139
layers.push(this.toJSON());