add layers and resolutions array

This commit is contained in:
Mike Adair
2012-06-19 11:17:55 -04:00
parent 28955dc0b1
commit 6ed79a3d36
3 changed files with 103 additions and 2 deletions

View File

@@ -125,3 +125,27 @@ ol.Map.prototype.numZoomLevels = function(opt_arg) {
return this.getNumZoomLevels();
}
};
/**
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.resolutions = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setResolutions(opt_arg);
} else {
return this.getResolutions();
}
};
/**
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.layers = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setLayers(opt_arg);
} else {
return this.getLayers();
}
};

View File

@@ -40,6 +40,18 @@ ol.Map = function() {
*/
this.numZoomLevels_ = 22;
/**
* @private
* @type {Array|undefined}
*/
this.resolutions_ = null;
/**
* @private
* @type {Array|undefined}
*/
this.layers_ = null;
};
/**
@@ -100,6 +112,22 @@ ol.Map.prototype.getNumZoomLevels = function() {
};
/**
* @return {Array|undefined} array of resolutions available for this map
*/
ol.Map.prototype.getResolutions = function() {
return this.resolutions_;
};
/**
* @return {Array|undefined} array of layers available for this map
*/
ol.Map.prototype.getLayers = function() {
return this.layers_;
};
/**
* @param {ol.Loc} center Center.
* @return {ol.Map} This.
@@ -149,11 +177,29 @@ ol.Map.prototype.setNumZoomLevels = function(nZoom) {
return this;
};
/**
* @param {Array} resolutions the map resolutions if set on the map
* @return {ol.Map} This.
*/
ol.Map.prototype.setResolutions = function(resolutions) {
this.resolutions_ = resolutions;
return this;
};
/**
* @param {Array} layers the layers set on the map
* @return {ol.Map} This.
*/
ol.Map.prototype.setLayers = function(layers) {
this.layers_ = layers;
return this;
};
/**
*/
ol.Map.prototype.destroy = function() {
//remove layers, etc.
for (key in this) {
for (var key in this) {
delete this[key];
}
};

View File

@@ -83,7 +83,6 @@ describe("ol.Map", function() {
var proj;
// at construction
debugger;
var map = ol.map({
projection: ol.projection("EPSG:4326")
});
@@ -174,4 +173,36 @@ describe("ol.Map", function() {
});
it("allows setting the resolutions array", function() {
var map = ol.map();
map.resolutions([1,2,3]);
var resolutions = map.resolutions();
expect(resolutions.length).toBe(3);
expect(resolutions[0]).toBe(1);
expect(resolutions[1]).toBe(2);
expect(resolutions[2]).toBe(3);
});
it("resolutions array is mutable", function() {
var map = ol.map();
map.resolutions([1,2,3]);
map.resolutions([10,9,8,7,6,5]);
var resolutions = map.resolutions();
expect(resolutions.length).toBe(6);
expect(resolutions[0]).toBe(10);
expect(resolutions[2]).toBe(8);
expect(resolutions[4]).toBe(6);
});
it("has no layers by default", function() {
var map = ol.map();
var layers = map.layers();
expect(layers).toBe(null);
});
});