adding getMaxExtent and getMaxRes
This commit is contained in:
@@ -29,6 +29,12 @@ ol.map = function(opt_arg){
|
||||
var projection;
|
||||
/** @type {ol.Projection|undefined} */
|
||||
var userProjection;
|
||||
/** @type {ol.Bounds|undefined} */
|
||||
var maxExtent;
|
||||
/** @type {array|undefined} */
|
||||
var resolutions;
|
||||
/** @type {array|undefined} */
|
||||
var layers;
|
||||
|
||||
if (arguments.length == 1) {
|
||||
if (opt_arg instanceof ol.Map) {
|
||||
@@ -40,6 +46,9 @@ ol.map = function(opt_arg){
|
||||
numZoomLevels = opt_arg['numZoomLevels'];
|
||||
projection = opt_arg['projection'];
|
||||
userProjection = opt_arg['userProjection'];
|
||||
maxExtent = opt_arg['maxExtent'];
|
||||
resolutions = opt_arg['resolutions'];
|
||||
layers = opt_arg['layers'];
|
||||
}
|
||||
else {
|
||||
throw new Error('ol.map');
|
||||
@@ -57,10 +66,19 @@ ol.map = function(opt_arg){
|
||||
map.setNumZoomLevels(numZoomLevels);
|
||||
}
|
||||
if (goog.isDef(projection)) {
|
||||
map.setProjection(projection);
|
||||
map.setProjection(ol.projection(projection));
|
||||
}
|
||||
if (goog.isDef(userProjection)) {
|
||||
map.setUserProjection(userProjection);
|
||||
map.setUserProjection(ol.projection(userProjection));
|
||||
}
|
||||
if (goog.isDef(maxExtent)) {
|
||||
map.setMaxExtent(ol.bounds(maxExtent));
|
||||
}
|
||||
if (goog.isDef(resolutions)) {
|
||||
map.setResolutions(resolutions);
|
||||
}
|
||||
if (goog.isDef(layers)) {
|
||||
map.setLayers(layers);
|
||||
}
|
||||
return map;
|
||||
|
||||
@@ -149,3 +167,15 @@ ol.Map.prototype.layers = function(opt_arg) {
|
||||
return this.getLayers();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array=} opt_arg
|
||||
* @returns {ol.Map|ol.Bounds|undefined} Map max extent.
|
||||
*/
|
||||
ol.Map.prototype.maxExtent = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setMaxExtent(ol.bounds(opt_arg));
|
||||
} else {
|
||||
return this.getMaxExtent();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,6 +128,24 @@ ol.Map.prototype.getLayers = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Bounds} the maxExtent for the map
|
||||
*/
|
||||
ol.Map.prototype.getMaxExtent = function() {
|
||||
if (goog.isDefAndNotNull(this.maxExtent_)) {
|
||||
return this.maxExtent_;
|
||||
} else {
|
||||
var extent = this.projection.getMaxExtent();
|
||||
if (goog.isDefAndNotNull(extent)) {
|
||||
return extent;
|
||||
} else {
|
||||
throw('maxExtent must be defined either in the map or the projection');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center Center.
|
||||
* @return {ol.Map} This.
|
||||
@@ -195,6 +213,15 @@ ol.Map.prototype.setLayers = function(layers) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Bounds} extent the maxExtent for the map
|
||||
* @return {ol.Map} This.
|
||||
*/
|
||||
ol.Map.prototype.setMaxExtent = function(extent) {
|
||||
this.maxExtent_ = extent;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Map.prototype.destroy = function() {
|
||||
|
||||
@@ -186,17 +186,106 @@ describe("ol.Map", function() {
|
||||
|
||||
it("resolutions array is mutable", function() {
|
||||
var map = ol.map();
|
||||
debugger;
|
||||
map.resolutions([1,2,3]);
|
||||
|
||||
var resolutions = map.resolutions();
|
||||
expect(resolutions[0]).toBe(1);
|
||||
|
||||
map.resolutions([10,9,8,7,6,5]);
|
||||
|
||||
var resolutions = map.resolutions();
|
||||
resolutions = map.resolutions();
|
||||
expect(resolutions.length).toBe(6);
|
||||
expect(resolutions[0]).toBe(10);
|
||||
expect(resolutions[2]).toBe(8);
|
||||
expect(resolutions[4]).toBe(6);
|
||||
});
|
||||
|
||||
it("returns correct maxExtent for default map", function() {
|
||||
var map = ol.map();
|
||||
|
||||
var extent = map.maxExtent();
|
||||
expect(extent instanceof ol.Bounds).toBe(true);
|
||||
expect(extent.minX()).toBe(-20037508.34);
|
||||
expect(extent.maxX()).toBe(-20037508.34);
|
||||
expect(extent.minY()).toBe(20037508.34);
|
||||
expect(extent.maxY()).toBe(20037508.34);
|
||||
|
||||
});
|
||||
|
||||
it("returns correct maxExtent for custom map extent", function() {
|
||||
var map = ol.map();
|
||||
map.maxExtent([-5,-4,7,9]);
|
||||
|
||||
var extent = map.maxExtent();
|
||||
expect(extent instanceof ol.Bounds).toBe(true);
|
||||
expect(extent.minX()).toBe(-5);
|
||||
expect(extent.maxX()).toBe(-4);
|
||||
expect(extent.minY()).toBe(7);
|
||||
expect(extent.maxY()).toBe(9);
|
||||
|
||||
});
|
||||
|
||||
it("returns correct maxExtent for custom projection extent", function() {
|
||||
var map = ol.map();
|
||||
map.projection("CRS:84");
|
||||
|
||||
var extent = map.maxExtent();
|
||||
expect(extent instanceof ol.Bounds).toBe(true);
|
||||
expect(extent.minX()).toBe(-180);
|
||||
expect(extent.maxX()).toBe(-90);
|
||||
expect(extent.minY()).toBe(180);
|
||||
expect(extent.maxY()).toBe(90);
|
||||
|
||||
});
|
||||
|
||||
it("throws an error whith no maxExtent available", function() {
|
||||
expect(function(){
|
||||
map({projection: ol.projection("bar")});
|
||||
extent = map.maxExtent();
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it("getMaxRes returns correct defaults", function() {
|
||||
var map = ol.map();
|
||||
|
||||
var res = map.maxRes();
|
||||
expect(res.toFixed(5)).toBe(1.40625);
|
||||
|
||||
});
|
||||
|
||||
it("allows setting of maxRes", function() {
|
||||
var map = ol.map({
|
||||
maxRes: 67
|
||||
});
|
||||
|
||||
var res = map.maxRes();
|
||||
expect(res).toBe(67);
|
||||
|
||||
});
|
||||
|
||||
it("getMaxRes returns correct for custom maxExtent", function() {
|
||||
var map = ol.map({
|
||||
projection: ol.projection({
|
||||
maxExtent: [0,0,90,90]
|
||||
})
|
||||
});
|
||||
|
||||
var res = map.maxRes();
|
||||
expect(res.toFixed(7)).toBe(0.3515625);
|
||||
|
||||
});
|
||||
|
||||
it("getResForZoom returns correct defaults", function() {
|
||||
var map = ol.map();
|
||||
|
||||
res = map.getResForZoom(0);
|
||||
expect(res.toFixed(5)).toBe(1.40625);
|
||||
res = map.getResForZoom(5);
|
||||
expect(res.toFixed(10)).toBe(0.0439453125);
|
||||
|
||||
});
|
||||
|
||||
it("has no layers by default", function() {
|
||||
var map = ol.map();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user