Merge branch 'master' of github.com:openlayers/ol3

This commit is contained in:
Mike Adair
2012-06-22 06:52:22 -04:00
24 changed files with 320 additions and 182 deletions

View File

@@ -5,6 +5,7 @@ goog.require('ol.geom.Geometry');
/**
* @export
* @constructor
*/
ol.Feature = function() {

View File

@@ -1,6 +1,7 @@
goog.provide('ol.Map');
goog.require('ol.Loc');
goog.require('ol.Bounds');
goog.require('ol.Projection');
goog.require('ol.event');
goog.require('ol.event.Events');
@@ -65,7 +66,7 @@ ol.Map = function() {
/**
* @private
* @type {ol.UnreferencedBounds}
* @type {ol.Bounds}
*/
this.maxExtent_ = null;
@@ -209,14 +210,19 @@ ol.Map.prototype.getControls = function() {
/**
* @return {ol.UnreferencedBounds} the maxExtent for the map
* @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.getProjection().getExtent();
var projection = this.getProjection();
var extent = projection.getExtent();
if (goog.isDefAndNotNull(extent)) {
extent = new ol.Bounds(
extent.getMinX(), extent.getMinY(),
extent.getMaxX(), extent.getMaxY());
extent.setProjection(projection);
return extent;
} else {
throw('maxExtent must be defined either in the map or the projection');
@@ -332,7 +338,7 @@ ol.Map.prototype.setControls = function(opt_controls) {
};
/**
* @param {ol.UnreferencedBounds} extent the maxExtent for the map
* @param {ol.Bounds} extent the maxExtent for the map
*/
ol.Map.prototype.setMaxExtent = function(extent) {
this.maxExtent_ = extent;

39
src/ol/base.js Normal file
View File

@@ -0,0 +1,39 @@
goog.provide('ol.base');
goog.provide('ol.error');
/**
* @param {string} message Message.
*/
ol.error = function(message) {
if (ol.error.VERBOSE_ERRORS) {
throw new Error(message);
} else {
throw null;
}
};
/**
* @define {boolean}
*/
ol.error.VERBOSE_ERRORS = true;
/**
* @define {boolean}
*/
ol.CHECK_KEYS = true;
/**
* @param {Object} obj Object.
* @param {!Array.<string>} allowedKeys Allowed keys.
*/
ol.base.checkKeys = function(obj, allowedKeys) {
if (ol.CHECK_KEYS) {
var keys = goog.object.getKeys(obj);
goog.array.forEach(allowedKeys, function(allowedKey) {
goog.array.remove(keys, allowedKey);
});
if (!goog.array.isEmpty(keys)) {
ol.error('object contains invalid keys: ' + keys.join(', '));
}
}
};

View File

@@ -1,17 +0,0 @@
goog.provide('ol.error');
/**
* @param {string} message Message.
*/
ol.error = function(message) {
if (ol.error.VERBOSE_ERRORS) {
throw new Error(message);
} else {
throw null;
}
};
/**
* @define {boolean}
*/
ol.error.VERBOSE_ERRORS = true;

View File

@@ -3,6 +3,7 @@ goog.provide('ol.geom.Collection');
goog.require('goog.array');
goog.require('ol.geom.Geometry');
goog.require('ol.Projection');
goog.require('ol.base');
/**
* Creates ol.geom.Collection objects.
@@ -96,8 +97,9 @@ ol.geom.Collection.prototype.setComponents = function(components) {
if (allValidTypes) {
this.components_ = components;
} else {
throw new Error('ol.geom.Collection: at least one component passed to '
+ 'setComponents is not allowed.');
var msg = 'ol.geom.Collection: at least one component passed to '
+ 'setComponents is not allowed.';
ol.error(msg);
}
};
@@ -111,8 +113,8 @@ ol.geom.Collection.prototype.addComponent = function(component, index) {
if (this.isAllowedComponent(component)) {
goog.array.insertAt(this.components_, component, index);
} else {
throw new Error("ol.geom.Collection: The component is not allowed "
+ "to be added.");
var msg = 'ol.geom.Collection: component is not allowed to be added.';
ol.error(msg);
}
};

View File

@@ -4,6 +4,7 @@ goog.require('ol.geom.Geometry');
goog.require('ol.Projection');
goog.require('ol.coord.AccessorInterface');
goog.require('ol.base');
/**
* Creates ol.geom.Point objects.
@@ -135,7 +136,8 @@ ol.geom.Point.prototype._transform = function(proj) {
var point = {'x': this.x_, 'y': this.y_};
var sourceProj = this.projection_;
if (!goog.isDefAndNotNull(sourceProj)) {
throw new Error("Cannot transform a point without a source projection.");
var msg = 'Cannot transform a point without a source projection.';
ol.error(msg);
}
ol.Projection.transform(point, sourceProj, proj);

View File

@@ -153,15 +153,44 @@ ol.layer.TileLayer.prototype.getTileOrigin = function() {
return null;
};
/**
* Get max resolution. Return undefined if the layer has no maxResolution,
* and no extent from which maxResolution could be derived.
* @return {number|undefined}
*/
ol.layer.TileLayer.prototype.getMaxResolution = function() {
if (!goog.isDef(this.maxResolution_)) {
var extent = this.getExtent();
if (!goog.isNull(extent)) {
this.maxResolution_ = Math.max(
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
(extent.getMaxY() - extent.getMaxX()) / this.tileHeight_);
}
}
return this.maxResolution_;
};
/**
* Get the number of the zoom levels.
* @return {number|undefined}
*/
ol.layer.TileLayer.prototype.getNumZoomLevels = function() {
return this.numZoomLevels_;
};
/**
* Get layer resolutions. Return null if the layer has no resolutions.
* @return {Array.<number>}
*/
ol.layer.TileLayer.prototype.getResolutions = function() {
if (goog.isNull(this.resolutions_) && goog.isDef(this.maxResolution_)) {
this.resolutions_ = [];
for (var i = 0; i < this.numZoomLevels_; i++) {
this.resolutions_[i] = this.maxResolution_ / Math.pow(2, i);
if (goog.isNull(this.resolutions_)) {
var maxResolution = this.getMaxResolution(),
numZoomLevels = this.getNumZoomLevels();
if (goog.isDef(maxResolution) && goog.isDef(numZoomLevels)) {
this.resolutions_ = [];
for (var i = 0; i < numZoomLevels; i++) {
this.resolutions_[i] = maxResolution / Math.pow(2, i);
}
}
}
return this.resolutions_;

View File

@@ -18,7 +18,8 @@ ol.layer.XYZ = function(url) {
goog.base(this);
this.setUrl(url);
this.setMaxResolution(156543.03390625);
this.setProjection(new ol.Projection("EPSG:3857"));
this.setNumZoomLevels(22);
};
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);