Merge branch 'master' of https://github.com/openlayers/ol3
This commit is contained in:
@@ -61,7 +61,8 @@ ol.bounds = function(opt_arg){
|
||||
*/
|
||||
ol.Bounds.prototype.projection = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setProjection(opt_arg);
|
||||
this.setProjection(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getProjection();
|
||||
@@ -76,7 +77,8 @@ ol.Bounds.prototype.projection = function(opt_arg){
|
||||
*/
|
||||
ol.Bounds.prototype.minX = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setMinX(opt_arg);
|
||||
this.setMinX(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getMinX();
|
||||
@@ -91,7 +93,8 @@ ol.Bounds.prototype.minX = function(opt_arg){
|
||||
*/
|
||||
ol.Bounds.prototype.minY = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setMinY(opt_arg);
|
||||
this.setMinY(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getMinY();
|
||||
@@ -106,7 +109,8 @@ ol.Bounds.prototype.minY = function(opt_arg){
|
||||
*/
|
||||
ol.Bounds.prototype.maxX = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setMaxX(opt_arg);
|
||||
this.setMaxX(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getMaxX();
|
||||
@@ -121,7 +125,8 @@ ol.Bounds.prototype.maxX = function(opt_arg){
|
||||
*/
|
||||
ol.Bounds.prototype.maxY = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setMaxY(opt_arg);
|
||||
this.setMaxY(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getMaxY();
|
||||
|
||||
@@ -75,7 +75,8 @@ ol.Loc.prototype.projection = function(opt_arg){
|
||||
*/
|
||||
ol.Loc.prototype.x = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setX(opt_arg);
|
||||
this.setX(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getX();
|
||||
@@ -90,7 +91,8 @@ ol.Loc.prototype.x = function(opt_arg){
|
||||
*/
|
||||
ol.Loc.prototype.y = function(opt_arg){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setY(opt_arg);
|
||||
this.setY(opt_arg);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getY();
|
||||
|
||||
@@ -31,9 +31,9 @@ ol.map = function(opt_arg){
|
||||
var userProjection;
|
||||
/** @type {ol.Bounds|undefined} */
|
||||
var maxExtent;
|
||||
/** @type {array|undefined} */
|
||||
/** @type {Array.<number>|undefined} */
|
||||
var resolutions;
|
||||
/** @type {array|undefined} */
|
||||
/** @type {Array|undefined} */
|
||||
var layers;
|
||||
|
||||
if (arguments.length == 1) {
|
||||
@@ -90,7 +90,8 @@ ol.map = function(opt_arg){
|
||||
*/
|
||||
ol.Map.prototype.center = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setCenter(ol.loc(opt_arg));
|
||||
this.setCenter(ol.loc(opt_arg));
|
||||
return this;
|
||||
} else {
|
||||
return this.getCenter();
|
||||
}
|
||||
@@ -102,7 +103,8 @@ ol.Map.prototype.center = function(opt_arg) {
|
||||
*/
|
||||
ol.Map.prototype.projection = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setProjection(ol.projection(opt_arg));
|
||||
this.setProjection(ol.projection(opt_arg));
|
||||
return this;
|
||||
} else {
|
||||
return this.getProjection();
|
||||
}
|
||||
@@ -114,7 +116,8 @@ ol.Map.prototype.projection = function(opt_arg) {
|
||||
*/
|
||||
ol.Map.prototype.userProjection = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setUserProjection(ol.projection(opt_arg));
|
||||
this.setUserProjection(ol.projection(opt_arg));
|
||||
return this;
|
||||
} else {
|
||||
return this.getUserProjection();
|
||||
}
|
||||
@@ -126,7 +129,8 @@ ol.Map.prototype.userProjection = function(opt_arg) {
|
||||
*/
|
||||
ol.Map.prototype.zoom = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setZoom(opt_arg);
|
||||
this.setZoom(opt_arg);
|
||||
return this;
|
||||
} else {
|
||||
return this.getZoom();
|
||||
}
|
||||
@@ -138,7 +142,8 @@ ol.Map.prototype.zoom = function(opt_arg) {
|
||||
*/
|
||||
ol.Map.prototype.numZoomLevels = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setNumZoomLevels(opt_arg);
|
||||
this.setNumZoomLevels(opt_arg);
|
||||
return this;
|
||||
} else {
|
||||
return this.getNumZoomLevels();
|
||||
}
|
||||
@@ -150,7 +155,8 @@ ol.Map.prototype.numZoomLevels = function(opt_arg) {
|
||||
*/
|
||||
ol.Map.prototype.resolutions = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setResolutions(opt_arg);
|
||||
this.setResolutions(opt_arg);
|
||||
return this;
|
||||
} else {
|
||||
return this.getResolutions();
|
||||
}
|
||||
@@ -162,7 +168,8 @@ ol.Map.prototype.resolutions = function(opt_arg) {
|
||||
*/
|
||||
ol.Map.prototype.layers = function(opt_arg) {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setLayers(opt_arg);
|
||||
this.setLayers(opt_arg);
|
||||
return this;
|
||||
} else {
|
||||
return this.getLayers();
|
||||
}
|
||||
@@ -170,11 +177,12 @@ ol.Map.prototype.layers = function(opt_arg) {
|
||||
|
||||
/**
|
||||
* @param {Array=} opt_arg
|
||||
* @returns {ol.Map|ol.Bounds|undefined} Map max extent.
|
||||
* @returns {ol.Map|ol.UnreferencedBounds|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));
|
||||
this.setMaxExtent(ol.bounds(opt_arg));
|
||||
return this;
|
||||
} else {
|
||||
return this.getMaxExtent();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ ol.projection = function(opt_arg){
|
||||
*/
|
||||
ol.Projection.prototype.code = function(opt_code){
|
||||
if (arguments.length == 1 && goog.isDef(opt_code)) {
|
||||
return this.setCode(opt_code);
|
||||
this.setCode(opt_code);
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return this.getCode();
|
||||
|
||||
@@ -46,42 +46,6 @@ ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) {
|
||||
};
|
||||
goog.inherits(ol.Bounds, ol.UnreferencedBounds);
|
||||
|
||||
/**
|
||||
* @param {number} minX Minimum X.
|
||||
* @return {!ol.Bounds} This.
|
||||
*/
|
||||
ol.Bounds.prototype.setMinX = function(minX) {
|
||||
this.minX_ = minX;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} maxX Maximum X.
|
||||
* @return {!ol.Bounds} This.
|
||||
*/
|
||||
ol.Bounds.prototype.setMaxX = function(maxX) {
|
||||
this.maxX_ = maxX;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} minY Minimum Y.
|
||||
* @return {!ol.Bounds} This.
|
||||
*/
|
||||
ol.Bounds.prototype.setMinY = function(minY) {
|
||||
this.minY_ = minY;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} maxY Maximum Y.
|
||||
* @return {!ol.Bounds} This.
|
||||
*/
|
||||
ol.Bounds.prototype.setMaxY = function(maxY) {
|
||||
this.maxY_ = maxY;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ol.Projection|undefined} Projection.
|
||||
*/
|
||||
@@ -91,9 +55,7 @@ ol.Bounds.prototype.getProjection = function() {
|
||||
|
||||
/**
|
||||
* @param {ol.Projection|undefined} projection Projection.
|
||||
* @return {ol.Bounds} This.
|
||||
*/
|
||||
ol.Bounds.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -74,41 +74,33 @@ ol.Loc.prototype.getZ = function() {
|
||||
|
||||
/**
|
||||
* @param {ol.Projection|undefined} projection Projection.
|
||||
* @return {ol.Loc} This.
|
||||
*/
|
||||
ol.Loc.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
* @return {ol.Loc} This.
|
||||
*/
|
||||
ol.Loc.prototype.setX = function(x) {
|
||||
this.x_ = x;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} y Y.
|
||||
* @return {ol.Loc} This.
|
||||
*/
|
||||
ol.Loc.prototype.setY = function(y) {
|
||||
this.y_ = y;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} z Z.
|
||||
* @return {ol.Loc} This.
|
||||
*/
|
||||
ol.Loc.prototype.setZ = function(z) {
|
||||
this.z_ = z;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
447
src/ol/Map.js
447
src/ol/Map.js
@@ -1,232 +1,215 @@
|
||||
goog.provide('ol.Map');
|
||||
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
ol.Map = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.userProjection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Loc}
|
||||
*/
|
||||
this.center_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.zoom_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.numZoomLevels_ = 22;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array|undefined}
|
||||
*/
|
||||
this.resolutions_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array|undefined}
|
||||
*/
|
||||
this.layers_ = null;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@const
|
||||
@type {string}
|
||||
*/
|
||||
ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857";
|
||||
/**
|
||||
@const
|
||||
@type {string}
|
||||
*/
|
||||
ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326";
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Loc} Location.
|
||||
*/
|
||||
ol.Map.prototype.getCenter = function() {
|
||||
return this.center_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {!ol.Projection} Projection.
|
||||
*/
|
||||
ol.Map.prototype.getProjection = function() {
|
||||
if (goog.isNull(this.projection_)) {
|
||||
this.projection_ = new ol.Projection(this.DEFAULT_PROJECTION);
|
||||
}
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {!ol.Projection} User projection.
|
||||
*/
|
||||
ol.Map.prototype.getUserProjection = function() {
|
||||
if (goog.isNull(this.userProjection_)) {
|
||||
this.userProjection_ = new ol.Projection(this.DEFAULT_USER_PROJECTION);
|
||||
}
|
||||
return this.userProjection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Zoom.
|
||||
*/
|
||||
ol.Map.prototype.getZoom = function() {
|
||||
return this.zoom_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} number of zoom levels.
|
||||
*/
|
||||
ol.Map.prototype.getNumZoomLevels = function() {
|
||||
return this.numZoomLevels_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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();
|
||||
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.
|
||||
*/
|
||||
ol.Map.prototype.setCenter = function(center) {
|
||||
this.center_ = center;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
* @return {ol.Map} This.
|
||||
*/
|
||||
ol.Map.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} userProjection set the user projection.
|
||||
* @return {ol.Map} This.
|
||||
*/
|
||||
ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||
this.userProjection_ = userProjection;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom Zoom.
|
||||
* @return {ol.Map} This.
|
||||
*/
|
||||
ol.Map.prototype.setZoom = function(zoom) {
|
||||
this.zoom_ = zoom;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} nZoom Zoom.
|
||||
* @return {ol.Map} This.
|
||||
*/
|
||||
ol.Map.prototype.setNumZoomLevels = function(nZoom) {
|
||||
this.numZoomLevels_ = nZoom;
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
//remove layers, etc.
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
goog.provide('ol.Map');
|
||||
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
ol.Map = function() {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.projection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.userProjection_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Loc}
|
||||
*/
|
||||
this.center_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.zoom_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.numZoomLevels_ = 22;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array|undefined}
|
||||
*/
|
||||
this.resolutions_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array|undefined}
|
||||
*/
|
||||
this.layers_ = null;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@const
|
||||
@type {string}
|
||||
*/
|
||||
ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857";
|
||||
/**
|
||||
@const
|
||||
@type {string}
|
||||
*/
|
||||
ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326";
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Loc} Location.
|
||||
*/
|
||||
ol.Map.prototype.getCenter = function() {
|
||||
return this.center_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {!ol.Projection} Projection.
|
||||
*/
|
||||
ol.Map.prototype.getProjection = function() {
|
||||
if (goog.isNull(this.projection_)) {
|
||||
this.projection_ = new ol.Projection(this.DEFAULT_PROJECTION);
|
||||
}
|
||||
return this.projection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {!ol.Projection} User projection.
|
||||
*/
|
||||
ol.Map.prototype.getUserProjection = function() {
|
||||
if (goog.isNull(this.userProjection_)) {
|
||||
this.userProjection_ = new ol.Projection(this.DEFAULT_USER_PROJECTION);
|
||||
}
|
||||
return this.userProjection_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Zoom.
|
||||
*/
|
||||
ol.Map.prototype.getZoom = function() {
|
||||
return this.zoom_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} number of zoom levels.
|
||||
*/
|
||||
ol.Map.prototype.getNumZoomLevels = function() {
|
||||
return this.numZoomLevels_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.UnreferencedBounds} the maxExtent for the map
|
||||
*/
|
||||
ol.Map.prototype.getMaxExtent = function() {
|
||||
if (goog.isDefAndNotNull(this.maxExtent_)) {
|
||||
return this.maxExtent_;
|
||||
} else {
|
||||
var extent = this.getProjection().getExtent();
|
||||
if (goog.isDefAndNotNull(extent)) {
|
||||
return extent;
|
||||
} else {
|
||||
throw('maxExtent must be defined either in the map or the projection');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center Center.
|
||||
*/
|
||||
ol.Map.prototype.setCenter = function(center) {
|
||||
this.center_ = center;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.Map.prototype.setProjection = function(projection) {
|
||||
this.projection_ = projection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} userProjection set the user projection.
|
||||
*/
|
||||
ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||
this.userProjection_ = userProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom Zoom.
|
||||
*/
|
||||
ol.Map.prototype.setZoom = function(zoom) {
|
||||
this.zoom_ = zoom;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} nZoom Zoom.
|
||||
*/
|
||||
ol.Map.prototype.setNumZoomLevels = function(nZoom) {
|
||||
this.numZoomLevels_ = nZoom;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} resolutions the map resolutions if set on the map
|
||||
*/
|
||||
ol.Map.prototype.setResolutions = function(resolutions) {
|
||||
this.resolutions_ = resolutions;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} layers the layers set on the map
|
||||
*/
|
||||
ol.Map.prototype.setLayers = function(layers) {
|
||||
this.layers_ = layers;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ol.Bounds} extent the maxExtent for the map
|
||||
*/
|
||||
ol.Map.prototype.setMaxExtent = function(extent) {
|
||||
this.maxExtent_ = extent;
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
ol.Map.prototype.destroy = function() {
|
||||
//remove layers, etc.
|
||||
for (var key in this) {
|
||||
delete this[key];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,11 +43,9 @@ ol.Projection.prototype.getCode = function() {
|
||||
|
||||
/**
|
||||
* @param {string} code Code.
|
||||
* @return {!ol.Projection} This.
|
||||
*/
|
||||
ol.Projection.prototype.setCode = function(code) {
|
||||
this.code_ = code;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -59,11 +57,9 @@ ol.Projection.prototype.getUnits = function() {
|
||||
|
||||
/**
|
||||
* @param {string} units Units abbreviation.
|
||||
* @return {!ol.Projection} This.
|
||||
*/
|
||||
ol.Projection.prototype.setUnits = function(units) {
|
||||
this.units_ = units;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -77,11 +73,9 @@ ol.Projection.prototype.getExtent = function() {
|
||||
|
||||
/**
|
||||
* @param {!ol.UnreferencedBounds} extent Validity extent.
|
||||
* @return {ol.Projection} This.
|
||||
*/
|
||||
ol.Projection.prototype.setExtent = function(extent) {
|
||||
this.extent_ = extent;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,11 +45,9 @@ ol.UnreferencedBounds.prototype.getMinX = function() {
|
||||
|
||||
/**
|
||||
* @param {number} minX Minimum X.
|
||||
* @return {ol.UnreferencedBounds} This.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMinX = function(minX) {
|
||||
this.minX_ = minX;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -61,11 +59,9 @@ ol.UnreferencedBounds.prototype.getMinY = function() {
|
||||
|
||||
/**
|
||||
* @param {number} minY Minimum Y.
|
||||
* @return {ol.UnreferencedBounds} This.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMinY = function(minY) {
|
||||
this.minY_ = minY;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -77,11 +73,9 @@ ol.UnreferencedBounds.prototype.getMaxX = function() {
|
||||
|
||||
/**
|
||||
* @param {number} maxX Maximum X.
|
||||
* @return {ol.UnreferencedBounds} This.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMaxX = function(maxX) {
|
||||
this.maxX_ = maxX;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -93,10 +87,8 @@ ol.UnreferencedBounds.prototype.getMaxY = function() {
|
||||
|
||||
/**
|
||||
* @param {number} maxY Maximum Y.
|
||||
* @return {ol.UnreferencedBounds} This.
|
||||
*/
|
||||
ol.UnreferencedBounds.prototype.setMaxY = function(maxY) {
|
||||
this.maxY_ = maxY;
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ goog.require('goog.style');
|
||||
/**
|
||||
* Determine whether event was caused by a single touch
|
||||
*
|
||||
* @param {goog.events.BrowserEvent} evt
|
||||
* @param {Event} evt
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.event.isSingleTouch = function(evt) {
|
||||
@@ -21,7 +21,7 @@ ol.event.isSingleTouch = function(evt) {
|
||||
/**
|
||||
* Determine whether event was caused by a multi touch
|
||||
*
|
||||
* @param {goog.events.BrowserEvent} evt
|
||||
* @param {Event} evt
|
||||
* @return {boolean}
|
||||
*/
|
||||
ol.event.isMultiTouch = function(evt) {
|
||||
@@ -49,27 +49,26 @@ ol.event.Events = function(object, opt_element, opt_includeXY) {
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
* The object that this instance is bound to.
|
||||
*/
|
||||
this.object_ = object;
|
||||
|
||||
/**
|
||||
* @type {EventTarget|undefined}
|
||||
* @private
|
||||
* @type {EventTarget}
|
||||
* The element that this instance listens to mouse events on.
|
||||
*/
|
||||
this.element_ = opt_element;
|
||||
this.element_ = null;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false;
|
||||
|
||||
// if a dom element is specified, add a listeners list
|
||||
// for browser events on the element and register them
|
||||
if (goog.isDef(opt_element)) {
|
||||
this.attachToElement_(opt_element);
|
||||
}
|
||||
this.setElement(opt_element);
|
||||
};
|
||||
goog.inherits(ol.event.Events, goog.events.EventTarget);
|
||||
|
||||
@@ -81,41 +80,47 @@ ol.event.Events.prototype.getObject = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach this instance to a DOM element. If this is called, all browser events
|
||||
* fired on the provided element will be relayed by this instance.
|
||||
*
|
||||
* @param {!EventTarget} element A DOM element to attach
|
||||
* browser events to.
|
||||
* @param {boolean} includeXY
|
||||
*/
|
||||
ol.event.Events.prototype.attachToElement_ = function(element) {
|
||||
if (this.element_) {
|
||||
this.detachFromElement_();
|
||||
}
|
||||
this.element_ = element;
|
||||
var t, types = goog.events.EventType;
|
||||
for (t in types) {
|
||||
// register the event cross-browser
|
||||
goog.events.listen(
|
||||
element, types[t], this.handleBrowserEvent_, false, this
|
||||
);
|
||||
}
|
||||
ol.event.Events.prototype.setIncludeXY = function(includeXY) {
|
||||
this._includeXY = includeXY;
|
||||
};
|
||||
|
||||
/**
|
||||
* Detach this instance from a DOM element.
|
||||
* @return {EventTarget} The element that this instance currently
|
||||
* listens to browser events on.
|
||||
*/
|
||||
ol.event.Events.prototype.detachFromElement_ = function() {
|
||||
var t, types = goog.events.EventType,
|
||||
element = this.element_;
|
||||
if (goog.isDef(element)) {
|
||||
ol.event.Events.prototype.getElement = function() {
|
||||
return this.element_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach this instance to a DOM element. When called, all browser events fired
|
||||
* on the provided element will be relayed by this instance.
|
||||
*
|
||||
* @param {EventTarget=} opt_element A DOM element to attach
|
||||
* browser events to. If called without this argument, all browser events
|
||||
* will be detached from the element they are currently attached to.
|
||||
*/
|
||||
ol.event.Events.prototype.setElement = function(opt_element) {
|
||||
var t, types = goog.events.EventType;
|
||||
if (this.element_) {
|
||||
for (t in types) {
|
||||
// register the event cross-browser
|
||||
goog.events.unlisten(
|
||||
element, types[t], this.handleBrowserEvent_, false, this
|
||||
this.element_, types[t], this.handleBrowserEvent, false, this
|
||||
);
|
||||
}
|
||||
delete this.element_;
|
||||
|
||||
}
|
||||
if (goog.isDef(opt_element)) {
|
||||
this.element_ = opt_element;
|
||||
for (t in types) {
|
||||
// register the event cross-browser
|
||||
goog.events.listen(
|
||||
opt_element, types[t], this.handleBrowserEvent, false, this
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -250,10 +255,9 @@ ol.event.Events.prototype.triggerEvent = function(type, evt) {
|
||||
* Basically just a wrapper to the triggerEvent() function, but takes
|
||||
* care to set a property 'xy' on the event with the current mouse position.
|
||||
*
|
||||
* @private
|
||||
* @param {goog.events.BrowserEvent} evt
|
||||
* @param {Event} evt
|
||||
*/
|
||||
ol.event.Events.prototype.handleBrowserEvent_ = function(evt) {
|
||||
ol.event.Events.prototype.handleBrowserEvent = function(evt) {
|
||||
if (!goog.isDef(this.element_)) {
|
||||
return;
|
||||
}
|
||||
@@ -279,10 +283,10 @@ ol.event.Events.prototype.handleBrowserEvent_ = function(evt) {
|
||||
evt.clientX = x / num;
|
||||
evt.clientY = y / num;
|
||||
}
|
||||
var element = /** @type {!Element} */ this._element;
|
||||
if (this.includeXY) {
|
||||
var element = /** @type {!Element} */ this.element_;
|
||||
evt.xy = goog.style.getRelativePosition(evt, element);
|
||||
}
|
||||
}
|
||||
this.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,10 +4,28 @@ describe("ol.Events", function() {
|
||||
var events, element = document.createElement("div");
|
||||
events = new ol.event.Events("foo");
|
||||
expect(events.getObject()).toBe("foo");
|
||||
expect(events.getElement()).toBe(null);
|
||||
events.destroy();
|
||||
events = new ol.event.Events("foo", element, true);
|
||||
expect(events.element_).toBe(element);
|
||||
expect(events.getElement()).toBe(element);
|
||||
expect(events.includeXY_).toBe(true);
|
||||
events.destroy();
|
||||
});
|
||||
|
||||
it("destroys properly", function() {
|
||||
var events = new ol.event.Events("foo");
|
||||
events.destroy();
|
||||
expect(events.getObject()).toBe(undefined);
|
||||
});
|
||||
|
||||
it("respects event priority", function() {
|
||||
var log = [], events = new ol.event.Events("foo");
|
||||
events.register("bar", function() {log.push("normal");});
|
||||
events.register(
|
||||
"bar", function() {log.push("priority");}, undefined, true);
|
||||
events.triggerEvent("bar");
|
||||
expect(log[0]).toBe("priority");
|
||||
expect(log[1]).toBe("normal");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -133,7 +133,6 @@ describe("ol.Map", function() {
|
||||
expect(proj instanceof ol.Projection).toBe(true);
|
||||
expect(proj.code()).toBe("EPSG:4326");
|
||||
|
||||
debugger;
|
||||
map.center([10, 20]);
|
||||
|
||||
map.userProjection("EPSG:3857");
|
||||
|
||||
Reference in New Issue
Block a user