Use ol.base.checkKeys to check keys

This commit is contained in:
Tom Payne
2012-06-22 11:52:00 +02:00
parent afd6369da7
commit 3e15ce93bb
6 changed files with 19 additions and 17 deletions

View File

@@ -38,6 +38,7 @@ ol.bounds = function(opt_arg){
maxX = opt_arg[2]; maxX = opt_arg[2];
maxY = opt_arg[3]; maxY = opt_arg[3];
} else if (goog.isObject(opt_arg)) { } else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['minX', 'minY', 'maxX', 'maxY', 'projection']);
minX = opt_arg['minX']; minX = opt_arg['minX'];
minY = opt_arg['minY']; minY = opt_arg['minY'];
maxX = opt_arg['maxX']; maxX = opt_arg['maxX'];

View File

@@ -1,5 +1,6 @@
goog.provide('ol.feature'); goog.provide('ol.feature');
goog.require('ol.base');
goog.require('ol.Feature'); goog.require('ol.Feature');
goog.require('ol.geom.Geometry'); goog.require('ol.geom.Geometry');
@@ -29,6 +30,7 @@ ol.feature = function(opt_arg){
return opt_arg; return opt_arg;
} }
else if (goog.isObject(opt_arg)) { else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['geometry', 'properties', 'type']);
properties = opt_arg['properties']; properties = opt_arg['properties'];
geometry = opt_arg['geometry']; geometry = opt_arg['geometry'];
type = opt_arg['type']; type = opt_arg['type'];

View File

@@ -43,6 +43,7 @@ ol.loc = function(opt_arg){
z = opt_arg[2]; z = opt_arg[2];
projection = opt_arg[3]; projection = opt_arg[3];
} else if (goog.isObject(opt_arg)) { } else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['projection', 'x', 'y', 'z']);
x = opt_arg['x']; x = opt_arg['x'];
y = opt_arg['y']; y = opt_arg['y'];
z = opt_arg['z']; z = opt_arg['z'];

View File

@@ -49,33 +49,18 @@ ol.map = function(opt_arg) {
return opt_arg; return opt_arg;
} }
else if (goog.isObject(opt_arg)) { else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['center', 'zoom', 'numZoomLevels', 'projection', 'userProjection', 'maxExtent', 'maxRes', 'resolutions', 'renderTo', 'layers', 'controls']);
center = opt_arg['center']; center = opt_arg['center'];
delete opt_arg['center'];
zoom = opt_arg['zoom']; zoom = opt_arg['zoom'];
delete opt_arg['zoom'];
numZoomLevels = opt_arg['numZoomLevels']; numZoomLevels = opt_arg['numZoomLevels'];
delete opt_arg['numZoomLevels'];
projection = opt_arg['projection']; projection = opt_arg['projection'];
delete opt_arg['projection'];
userProjection = opt_arg['userProjection']; userProjection = opt_arg['userProjection'];
delete opt_arg['userProjection'];
maxExtent = opt_arg['maxExtent']; maxExtent = opt_arg['maxExtent'];
delete opt_arg['maxExtent'];
maxRes = opt_arg['maxRes']; maxRes = opt_arg['maxRes'];
delete opt_arg['maxRes'];
resolutions = opt_arg['resolutions']; resolutions = opt_arg['resolutions'];
delete opt_arg['resolutions'];
renderTo = opt_arg['renderTo']; renderTo = opt_arg['renderTo'];
delete opt_arg['renderTo'];
layers = opt_arg['layers']; layers = opt_arg['layers'];
delete opt_arg['layers'];
controls = opt_arg['controls']; controls = opt_arg['controls'];
delete opt_arg['controls'];
var k = goog.object.getAnyKey(opt_arg);
if (goog.isDef(k)) {
ol.error(k + ' is not a map option');
}
} }
else { else {
throw new Error('ol.map'); throw new Error('ol.map');

View File

@@ -1,10 +1,11 @@
goog.provide('ol.projection'); goog.provide('ol.projection');
goog.require('ol.base');
goog.require('ol.Projection'); goog.require('ol.Projection');
/** /**
* @typedef {ol.Projection|string} * @typedef {ol.Projection|Object|string}
*/ */
ol.ProjectionLike; ol.ProjectionLike;
@@ -32,6 +33,7 @@ ol.projection = function(opt_arg){
code = opt_arg; code = opt_arg;
} }
else if (goog.isObject(opt_arg)) { else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['code', 'maxExtent', 'units']);
if (goog.isString(opt_arg['code'])) { if (goog.isString(opt_arg['code'])) {
code = opt_arg['code']; code = opt_arg['code'];
} else { } else {

View File

@@ -27,5 +27,16 @@ describe("ol.bounds", function() {
}); });
it("raises an error on invalid keys", function() {
expect(function() {
ol.bounds({
minX: 9,
minY: 10,
maxX: 11,
maxWhy: 12
});
}).toThrow();
});
}); });