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
15
* @param {Object} A Rseference to the main application controller
17
init: function (controller) {
18
this.controller = controller;
23
* @description Add a new layer
25
addLayer: function (layer) {
26
this._layers.push(layer);
30
* @description Gets the number of layers currently loaded
31
* @return {Integer} Number of layers present.
34
return this._layers.length;
38
* Returns the index of the given layer if it exists, and -1 otherwise
40
indexOf: function (id) {
43
$.each(this._layers, function (i, item) {
53
* @description Returns the largest width and height of any layers (does not have to be from same layer)
54
* @return {Object} The width and height of the largest layer
56
getMaxDimensions: function () {
62
$.each(this._layers, function () {
63
var d = this.getDimensions();
65
maxLeft = Math.max(maxLeft, d.left);
66
maxTop = Math.max(maxTop, d.top);
67
maxBottom = Math.max(maxBottom, d.bottom);
68
maxRight = Math.max(maxRight, d.right);
71
return {width: maxLeft + maxRight, height: maxTop + maxBottom};
75
* @description Removes a layer
76
* @param {Object} The layer to remove
78
removeLayer: function (layer) {
79
layer.domNode.remove();
80
this._layers = $.grep(this._layers, function (e, i) {
81
return (e.id !== layer.id);
84
this.controller.viewport.updateSandbox();
88
* @description Reload layers (For tile layers, finds closest image)
90
reloadLayers: function () {
91
$.each(this._layers, function () {
97
* @description Resets each of the layers
99
resetLayers: function () {
100
$.each(this._layers, function () {
106
* @description Iterates through layers
108
each: function (fn) {
109
$.each(this._layers, fn);
113
* @description Returns a string representation of the layers currently being displayed
115
serialize: function () {
118
$.each(this._layers, function () {
119
layers += "[" + this.serialize() + "],";
122
// Remove trailing comma
123
layers = layers.slice(0, -1);
129
* @description Returns a JSON representation of the layers currently being displayed
131
toJSON: function () {
134
$.each(this._layers, function () {
135
layers.push(this.toJSON());