add layers and resolutions array
This commit is contained in:
@@ -125,3 +125,27 @@ ol.Map.prototype.numZoomLevels = function(opt_arg) {
|
|||||||
return this.getNumZoomLevels();
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
+47
-1
@@ -40,6 +40,18 @@ ol.Map = function() {
|
|||||||
*/
|
*/
|
||||||
this.numZoomLevels_ = 22;
|
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.
|
* @param {ol.Loc} center Center.
|
||||||
* @return {ol.Map} This.
|
* @return {ol.Map} This.
|
||||||
@@ -149,11 +177,29 @@ ol.Map.prototype.setNumZoomLevels = function(nZoom) {
|
|||||||
return this;
|
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() {
|
ol.Map.prototype.destroy = function() {
|
||||||
//remove layers, etc.
|
//remove layers, etc.
|
||||||
for (key in this) {
|
for (var key in this) {
|
||||||
delete this[key];
|
delete this[key];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ describe("ol.Map", function() {
|
|||||||
var proj;
|
var proj;
|
||||||
|
|
||||||
// at construction
|
// at construction
|
||||||
debugger;
|
|
||||||
var map = ol.map({
|
var map = ol.map({
|
||||||
projection: ol.projection("EPSG:4326")
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user