Merge branch 'master' of github.com:openlayers/ol3
This commit is contained in:
@@ -38,6 +38,7 @@ ol.bounds = function(opt_arg){
|
||||
maxX = opt_arg[2];
|
||||
maxY = opt_arg[3];
|
||||
} else if (goog.isObject(opt_arg)) {
|
||||
ol.base.checkKeys(opt_arg, ['minX', 'minY', 'maxX', 'maxY', 'projection']);
|
||||
minX = opt_arg['minX'];
|
||||
minY = opt_arg['minY'];
|
||||
maxX = opt_arg['maxX'];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.feature');
|
||||
|
||||
goog.require('ol.base');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
@@ -29,6 +30,7 @@ ol.feature = function(opt_arg){
|
||||
return opt_arg;
|
||||
}
|
||||
else if (goog.isObject(opt_arg)) {
|
||||
ol.base.checkKeys(opt_arg, ['geometry', 'properties', 'type']);
|
||||
properties = opt_arg['properties'];
|
||||
geometry = opt_arg['geometry'];
|
||||
type = opt_arg['type'];
|
||||
@@ -56,6 +58,7 @@ ol.feature = function(opt_arg){
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @param {!string} attr The name of the attribute to be set.
|
||||
* @param {string|number|boolean} value The value of the attribute to be set.
|
||||
* @returns {ol.Feature} The feature so calls can be chained
|
||||
@@ -66,6 +69,7 @@ ol.Feature.prototype.set = function(attr, value) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @param {!string} attr The name of the attribute to be set.
|
||||
* @returns {string|number|boolean|undefined} The attribute value requested.
|
||||
*/
|
||||
@@ -74,6 +78,7 @@ ol.Feature.prototype.get = function(attr) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @param {ol.geom.Geometry=} opt_arg
|
||||
* @returns {ol.Feature|ol.geom.Geometry|undefined} get or set the geometry on a feature
|
||||
*/
|
||||
@@ -85,5 +90,3 @@ ol.Feature.prototype.geometry = function(opt_arg) {
|
||||
return this.getGeometry();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ ol.loc = function(opt_arg){
|
||||
z = opt_arg[2];
|
||||
projection = opt_arg[3];
|
||||
} else if (goog.isObject(opt_arg)) {
|
||||
ol.base.checkKeys(opt_arg, ['projection', 'x', 'y', 'z']);
|
||||
x = opt_arg['x'];
|
||||
y = opt_arg['y'];
|
||||
z = opt_arg['z'];
|
||||
|
||||
@@ -49,33 +49,18 @@ ol.map = function(opt_arg) {
|
||||
return 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'];
|
||||
delete opt_arg['center'];
|
||||
zoom = opt_arg['zoom'];
|
||||
delete opt_arg['zoom'];
|
||||
numZoomLevels = opt_arg['numZoomLevels'];
|
||||
delete opt_arg['numZoomLevels'];
|
||||
projection = opt_arg['projection'];
|
||||
delete opt_arg['projection'];
|
||||
userProjection = opt_arg['userProjection'];
|
||||
delete opt_arg['userProjection'];
|
||||
maxExtent = opt_arg['maxExtent'];
|
||||
delete opt_arg['maxExtent'];
|
||||
maxRes = opt_arg['maxRes'];
|
||||
delete opt_arg['maxRes'];
|
||||
resolutions = opt_arg['resolutions'];
|
||||
delete opt_arg['resolutions'];
|
||||
renderTo = opt_arg['renderTo'];
|
||||
delete opt_arg['renderTo'];
|
||||
layers = opt_arg['layers'];
|
||||
delete opt_arg['layers'];
|
||||
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 {
|
||||
throw new Error('ol.map');
|
||||
@@ -236,7 +221,7 @@ ol.Map.prototype.controls = function(opt_arg) {
|
||||
/**
|
||||
* @export
|
||||
* @param {Array=} opt_arg
|
||||
* @returns {ol.Map|ol.UnreferencedBounds|undefined} Map max extent.
|
||||
* @returns {ol.Map|ol.Bounds|undefined} Map max extent.
|
||||
*/
|
||||
ol.Map.prototype.maxExtent = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
@@ -247,28 +232,6 @@ ol.Map.prototype.maxExtent = function(opt_arg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @param {number=} opt_arg
|
||||
* @returns {ol.Map|number|undefined} Map maximum resolution
|
||||
*/
|
||||
ol.Map.prototype.maxRes = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
this.setMaxRes(opt_arg);
|
||||
return this;
|
||||
} else {
|
||||
return this.getMaxRes();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} arg
|
||||
* @returns {number} resolution for a given zoom level
|
||||
*/
|
||||
ol.Map.prototype.getResForZoom = function(arg) {
|
||||
return this.getResolutionForZoom(arg);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string|Element} arg Render the map to a container
|
||||
* @returns {ol.Map}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
goog.provide('ol.projection');
|
||||
|
||||
goog.require('ol.base');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {ol.Projection|string}
|
||||
* @typedef {ol.Projection|Object|string}
|
||||
*/
|
||||
ol.ProjectionLike;
|
||||
|
||||
@@ -32,6 +33,7 @@ ol.projection = function(opt_arg){
|
||||
code = opt_arg;
|
||||
}
|
||||
else if (goog.isObject(opt_arg)) {
|
||||
ol.base.checkKeys(opt_arg, ['code', 'maxExtent', 'units']);
|
||||
if (goog.isString(opt_arg['code'])) {
|
||||
code = opt_arg['code'];
|
||||
} else {
|
||||
|
||||
@@ -45,3 +45,18 @@ goog.exportProperty( ol.Bounds.prototype, 'minX', ol.Bounds.prototype.minX );
|
||||
goog.exportProperty( ol.Bounds.prototype, 'minY', ol.Bounds.prototype.minY );
|
||||
goog.exportProperty( ol.Bounds.prototype, 'maxX', ol.Bounds.prototype.maxX );
|
||||
goog.exportProperty( ol.Bounds.prototype, 'maxY', ol.Bounds.prototype.maxY );
|
||||
|
||||
// ol.feature
|
||||
goog.exportSymbol('ol.feature', ol.feature);
|
||||
goog.exportSymbol('ol.Feature', ol.Feature);
|
||||
goog.exportProperty(ol.Feature.prototype, 'set', ol.Feature.prototype.set);
|
||||
goog.exportProperty(ol.Feature.prototype, 'get', ol.Feature.prototype.get);
|
||||
goog.exportProperty(ol.Feature.prototype, 'geometry', ol.Feature.prototype.geometry);
|
||||
|
||||
// ol.geom.point
|
||||
goog.exportSymbol('ol.geom.point', ol.geom.point);
|
||||
goog.exportSymbol('ol.geom.Point', ol.geom.Point);
|
||||
goog.exportProperty(ol.geom.Point.prototype, 'x', ol.geom.Point.prototype.x);
|
||||
goog.exportProperty(ol.geom.Point.prototype, 'y', ol.geom.Point.prototype.y);
|
||||
goog.exportPropertz(ol.geom.Point.prototzpe, 'z', ol.geom.Point.prototzpe.z);
|
||||
goog.exportProperty(ol.geom.Point.prototype, 'projection', ol.geom.Point.prototype.projection);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
goog.provide("ol");
|
||||
|
||||
goog.require('ol.base');
|
||||
goog.require('ol.bounds');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.control.Navigation');
|
||||
|
||||
@@ -5,6 +5,7 @@ goog.require('ol.geom.Geometry');
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @constructor
|
||||
*/
|
||||
ol.Feature = function() {
|
||||
|
||||
@@ -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
39
src/ol/base.js
Normal 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(', '));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user