This commit is contained in:
Marc Jansen
2012-06-20 11:30:43 +02:00
12 changed files with 312 additions and 352 deletions

View File

@@ -61,7 +61,8 @@ ol.bounds = function(opt_arg){
*/ */
ol.Bounds.prototype.projection = function(opt_arg){ ol.Bounds.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setProjection(opt_arg); this.setProjection(opt_arg);
return this;
} }
else { else {
return this.getProjection(); return this.getProjection();
@@ -76,7 +77,8 @@ ol.Bounds.prototype.projection = function(opt_arg){
*/ */
ol.Bounds.prototype.minX = function(opt_arg){ ol.Bounds.prototype.minX = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setMinX(opt_arg); this.setMinX(opt_arg);
return this;
} }
else { else {
return this.getMinX(); return this.getMinX();
@@ -91,7 +93,8 @@ ol.Bounds.prototype.minX = function(opt_arg){
*/ */
ol.Bounds.prototype.minY = function(opt_arg){ ol.Bounds.prototype.minY = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setMinY(opt_arg); this.setMinY(opt_arg);
return this;
} }
else { else {
return this.getMinY(); return this.getMinY();
@@ -106,7 +109,8 @@ ol.Bounds.prototype.minY = function(opt_arg){
*/ */
ol.Bounds.prototype.maxX = function(opt_arg){ ol.Bounds.prototype.maxX = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setMaxX(opt_arg); this.setMaxX(opt_arg);
return this;
} }
else { else {
return this.getMaxX(); return this.getMaxX();
@@ -121,7 +125,8 @@ ol.Bounds.prototype.maxX = function(opt_arg){
*/ */
ol.Bounds.prototype.maxY = function(opt_arg){ ol.Bounds.prototype.maxY = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setMaxY(opt_arg); this.setMaxY(opt_arg);
return this;
} }
else { else {
return this.getMaxY(); return this.getMaxY();

View File

@@ -75,7 +75,8 @@ ol.Loc.prototype.projection = function(opt_arg){
*/ */
ol.Loc.prototype.x = function(opt_arg){ ol.Loc.prototype.x = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setX(opt_arg); this.setX(opt_arg);
return this;
} }
else { else {
return this.getX(); return this.getX();
@@ -90,7 +91,8 @@ ol.Loc.prototype.x = function(opt_arg){
*/ */
ol.Loc.prototype.y = function(opt_arg){ ol.Loc.prototype.y = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setY(opt_arg); this.setY(opt_arg);
return this;
} }
else { else {
return this.getY(); return this.getY();

View File

@@ -31,9 +31,9 @@ ol.map = function(opt_arg){
var userProjection; var userProjection;
/** @type {ol.Bounds|undefined} */ /** @type {ol.Bounds|undefined} */
var maxExtent; var maxExtent;
/** @type {array|undefined} */ /** @type {Array.<number>|undefined} */
var resolutions; var resolutions;
/** @type {array|undefined} */ /** @type {Array|undefined} */
var layers; var layers;
if (arguments.length == 1) { if (arguments.length == 1) {
@@ -90,7 +90,8 @@ ol.map = function(opt_arg){
*/ */
ol.Map.prototype.center = function(opt_arg) { ol.Map.prototype.center = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(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 { } else {
return this.getCenter(); return this.getCenter();
} }
@@ -102,7 +103,8 @@ ol.Map.prototype.center = function(opt_arg) {
*/ */
ol.Map.prototype.projection = function(opt_arg) { ol.Map.prototype.projection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(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 { } else {
return this.getProjection(); return this.getProjection();
} }
@@ -114,7 +116,8 @@ ol.Map.prototype.projection = function(opt_arg) {
*/ */
ol.Map.prototype.userProjection = function(opt_arg) { ol.Map.prototype.userProjection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(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 { } else {
return this.getUserProjection(); return this.getUserProjection();
} }
@@ -126,7 +129,8 @@ ol.Map.prototype.userProjection = function(opt_arg) {
*/ */
ol.Map.prototype.zoom = function(opt_arg) { ol.Map.prototype.zoom = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setZoom(opt_arg); this.setZoom(opt_arg);
return this;
} else { } else {
return this.getZoom(); return this.getZoom();
} }
@@ -138,7 +142,8 @@ ol.Map.prototype.zoom = function(opt_arg) {
*/ */
ol.Map.prototype.numZoomLevels = function(opt_arg) { ol.Map.prototype.numZoomLevels = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setNumZoomLevels(opt_arg); this.setNumZoomLevels(opt_arg);
return this;
} else { } else {
return this.getNumZoomLevels(); return this.getNumZoomLevels();
} }
@@ -150,7 +155,8 @@ ol.Map.prototype.numZoomLevels = function(opt_arg) {
*/ */
ol.Map.prototype.resolutions = function(opt_arg) { ol.Map.prototype.resolutions = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setResolutions(opt_arg); this.setResolutions(opt_arg);
return this;
} else { } else {
return this.getResolutions(); return this.getResolutions();
} }
@@ -162,7 +168,8 @@ ol.Map.prototype.resolutions = function(opt_arg) {
*/ */
ol.Map.prototype.layers = function(opt_arg) { ol.Map.prototype.layers = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setLayers(opt_arg); this.setLayers(opt_arg);
return this;
} else { } else {
return this.getLayers(); return this.getLayers();
} }
@@ -170,11 +177,12 @@ ol.Map.prototype.layers = function(opt_arg) {
/** /**
* @param {Array=} 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) { ol.Map.prototype.maxExtent = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(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 { } else {
return this.getMaxExtent(); return this.getMaxExtent();
} }

View File

@@ -52,7 +52,8 @@ ol.projection = function(opt_arg){
*/ */
ol.Projection.prototype.code = function(opt_code){ ol.Projection.prototype.code = function(opt_code){
if (arguments.length == 1 && goog.isDef(opt_code)) { if (arguments.length == 1 && goog.isDef(opt_code)) {
return this.setCode(opt_code); this.setCode(opt_code);
return this;
} }
else { else {
return this.getCode(); return this.getCode();

View File

@@ -46,42 +46,6 @@ ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) {
}; };
goog.inherits(ol.Bounds, ol.UnreferencedBounds); 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. * @return {ol.Projection|undefined} Projection.
*/ */
@@ -91,9 +55,7 @@ ol.Bounds.prototype.getProjection = function() {
/** /**
* @param {ol.Projection|undefined} projection Projection. * @param {ol.Projection|undefined} projection Projection.
* @return {ol.Bounds} This.
*/ */
ol.Bounds.prototype.setProjection = function(projection) { ol.Bounds.prototype.setProjection = function(projection) {
this.projection_ = projection; this.projection_ = projection;
return this;
}; };

View File

@@ -74,41 +74,33 @@ ol.Loc.prototype.getZ = function() {
/** /**
* @param {ol.Projection|undefined} projection Projection. * @param {ol.Projection|undefined} projection Projection.
* @return {ol.Loc} This.
*/ */
ol.Loc.prototype.setProjection = function(projection) { ol.Loc.prototype.setProjection = function(projection) {
this.projection_ = projection; this.projection_ = projection;
return this;
}; };
/** /**
* @param {number} x X. * @param {number} x X.
* @return {ol.Loc} This.
*/ */
ol.Loc.prototype.setX = function(x) { ol.Loc.prototype.setX = function(x) {
this.x_ = x; this.x_ = x;
return this;
}; };
/** /**
* @param {number} y Y. * @param {number} y Y.
* @return {ol.Loc} This.
*/ */
ol.Loc.prototype.setY = function(y) { ol.Loc.prototype.setY = function(y) {
this.y_ = y; this.y_ = y;
return this;
}; };
/** /**
* @param {number|undefined} z Z. * @param {number|undefined} z Z.
* @return {ol.Loc} This.
*/ */
ol.Loc.prototype.setZ = function(z) { ol.Loc.prototype.setZ = function(z) {
this.z_ = z; this.z_ = z;
return this;
}; };
/** /**

View File

@@ -1,232 +1,215 @@
goog.provide('ol.Map'); goog.provide('ol.Map');
goog.require('ol.Loc'); goog.require('ol.Loc');
goog.require('ol.Projection'); goog.require('ol.Projection');
/** /**
* @constructor * @constructor
*/ */
ol.Map = function() { ol.Map = function() {
/** /**
* @private * @private
* @type {ol.Projection} * @type {ol.Projection}
*/ */
this.projection_ = null; this.projection_ = null;
/** /**
* @private * @private
* @type {ol.Projection} * @type {ol.Projection}
*/ */
this.userProjection_ = null; this.userProjection_ = null;
/** /**
* @private * @private
* @type {ol.Loc} * @type {ol.Loc}
*/ */
this.center_ = null; this.center_ = null;
/** /**
* @private * @private
* @type {number} * @type {number|undefined}
*/ */
this.zoom_ = undefined; this.zoom_ = undefined;
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.numZoomLevels_ = 22; this.numZoomLevels_ = 22;
/** /**
* @private * @private
* @type {Array|undefined} * @type {Array|undefined}
*/ */
this.resolutions_ = null; this.resolutions_ = null;
/** /**
* @private * @private
* @type {Array|undefined} * @type {Array|undefined}
*/ */
this.layers_ = null; this.layers_ = null;
}; };
/** /**
@const @const
@type {string} @type {string}
*/ */
ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857"; ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857";
/** /**
@const @const
@type {string} @type {string}
*/ */
ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326"; ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326";
/** /**
* @return {ol.Loc} Location. * @return {ol.Loc} Location.
*/ */
ol.Map.prototype.getCenter = function() { ol.Map.prototype.getCenter = function() {
return this.center_; return this.center_;
}; };
/** /**
* @return {!ol.Projection} Projection. * @return {!ol.Projection} Projection.
*/ */
ol.Map.prototype.getProjection = function() { ol.Map.prototype.getProjection = function() {
if (goog.isNull(this.projection_)) { if (goog.isNull(this.projection_)) {
this.projection_ = new ol.Projection(this.DEFAULT_PROJECTION); this.projection_ = new ol.Projection(this.DEFAULT_PROJECTION);
} }
return this.projection_; return this.projection_;
}; };
/** /**
* @return {!ol.Projection} User projection. * @return {!ol.Projection} User projection.
*/ */
ol.Map.prototype.getUserProjection = function() { ol.Map.prototype.getUserProjection = function() {
if (goog.isNull(this.userProjection_)) { if (goog.isNull(this.userProjection_)) {
this.userProjection_ = new ol.Projection(this.DEFAULT_USER_PROJECTION); this.userProjection_ = new ol.Projection(this.DEFAULT_USER_PROJECTION);
} }
return this.userProjection_; return this.userProjection_;
}; };
/** /**
* @return {number} Zoom. * @return {number|undefined} Zoom.
*/ */
ol.Map.prototype.getZoom = function() { ol.Map.prototype.getZoom = function() {
return this.zoom_; return this.zoom_;
}; };
/** /**
* @return {number} number of zoom levels. * @return {number} number of zoom levels.
*/ */
ol.Map.prototype.getNumZoomLevels = function() { ol.Map.prototype.getNumZoomLevels = function() {
return this.numZoomLevels_; return this.numZoomLevels_;
}; };
/** /**
* @return {Array|undefined} array of resolutions available for this map * @return {Array|undefined} array of resolutions available for this map
*/ */
ol.Map.prototype.getResolutions = function() { ol.Map.prototype.getResolutions = function() {
return this.resolutions_; return this.resolutions_;
}; };
/** /**
* @return {Array|undefined} array of layers available for this map * @return {Array|undefined} array of layers available for this map
*/ */
ol.Map.prototype.getLayers = function() { ol.Map.prototype.getLayers = function() {
return this.layers_; return this.layers_;
}; };
/** /**
* @return {ol.Bounds} the maxExtent for the map * @return {ol.UnreferencedBounds} the maxExtent for the map
*/ */
ol.Map.prototype.getMaxExtent = function() { ol.Map.prototype.getMaxExtent = function() {
if (goog.isDefAndNotNull(this.maxExtent_)) { if (goog.isDefAndNotNull(this.maxExtent_)) {
return this.maxExtent_; return this.maxExtent_;
} else { } else {
var extent = this.getProjection().getExtent(); var extent = this.getProjection().getExtent();
if (goog.isDefAndNotNull(extent)) { if (goog.isDefAndNotNull(extent)) {
return extent; return extent;
} else { } else {
throw('maxExtent must be defined either in the map or the projection'); throw('maxExtent must be defined either in the map or the projection');
} }
} }
};
};
/**
/** * @param {ol.Loc} center Center.
* @param {ol.Loc} center Center. */
* @return {ol.Map} This. ol.Map.prototype.setCenter = function(center) {
*/ this.center_ = center;
ol.Map.prototype.setCenter = function(center) { };
this.center_ = center;
return this;
}; /**
* @param {ol.Projection} projection Projection.
*/
/** ol.Map.prototype.setProjection = function(projection) {
* @param {ol.Projection} projection Projection. this.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.
}; */
ol.Map.prototype.setUserProjection = function(userProjection) {
this.userProjection_ = userProjection;
/** };
* @param {ol.Projection} userProjection set the user projection.
* @return {ol.Map} This.
*/ /**
ol.Map.prototype.setUserProjection = function(userProjection) { * @param {number} zoom Zoom.
this.userProjection_ = userProjection; */
return this; ol.Map.prototype.setZoom = function(zoom) {
}; this.zoom_ = zoom;
};
/**
* @param {number} zoom Zoom. /**
* @return {ol.Map} This. * @param {number} nZoom Zoom.
*/ */
ol.Map.prototype.setZoom = function(zoom) { ol.Map.prototype.setNumZoomLevels = function(nZoom) {
this.zoom_ = zoom; this.numZoomLevels_ = nZoom;
return this; };
};
/**
* @param {Array} resolutions the map resolutions if set on the map
/** */
* @param {number} nZoom Zoom. ol.Map.prototype.setResolutions = function(resolutions) {
* @return {ol.Map} This. this.resolutions_ = resolutions;
*/ };
ol.Map.prototype.setNumZoomLevels = function(nZoom) {
this.numZoomLevels_ = nZoom; /**
return this; * @param {Array} layers the layers set on the map
}; */
ol.Map.prototype.setLayers = function(layers) {
/** this.layers_ = layers;
* @param {Array} resolutions the map resolutions if set on the map };
* @return {ol.Map} This.
*/ /**
ol.Map.prototype.setResolutions = function(resolutions) { * @param {ol.Bounds} extent the maxExtent for the map
this.resolutions_ = resolutions; */
return this; ol.Map.prototype.setMaxExtent = function(extent) {
}; this.maxExtent_ = extent;
};
/**
* @param {Array} layers the layers set on the map /**
* @return {ol.Map} This. */
*/ ol.Map.prototype.destroy = function() {
ol.Map.prototype.setLayers = function(layers) { //remove layers, etc.
this.layers_ = layers; for (var key in this) {
return this; delete this[key];
}; }
};
/**
* @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];
}
};

View File

@@ -43,11 +43,9 @@ ol.Projection.prototype.getCode = function() {
/** /**
* @param {string} code Code. * @param {string} code Code.
* @return {!ol.Projection} This.
*/ */
ol.Projection.prototype.setCode = function(code) { ol.Projection.prototype.setCode = function(code) {
this.code_ = code; this.code_ = code;
return this;
}; };
/** /**
@@ -59,11 +57,9 @@ ol.Projection.prototype.getUnits = function() {
/** /**
* @param {string} units Units abbreviation. * @param {string} units Units abbreviation.
* @return {!ol.Projection} This.
*/ */
ol.Projection.prototype.setUnits = function(units) { ol.Projection.prototype.setUnits = function(units) {
this.units_ = units; this.units_ = units;
return this;
}; };
/** /**
@@ -77,11 +73,9 @@ ol.Projection.prototype.getExtent = function() {
/** /**
* @param {!ol.UnreferencedBounds} extent Validity extent. * @param {!ol.UnreferencedBounds} extent Validity extent.
* @return {ol.Projection} This.
*/ */
ol.Projection.prototype.setExtent = function(extent) { ol.Projection.prototype.setExtent = function(extent) {
this.extent_ = extent; this.extent_ = extent;
return this;
}; };
/** /**

View File

@@ -45,11 +45,9 @@ ol.UnreferencedBounds.prototype.getMinX = function() {
/** /**
* @param {number} minX Minimum X. * @param {number} minX Minimum X.
* @return {ol.UnreferencedBounds} This.
*/ */
ol.UnreferencedBounds.prototype.setMinX = function(minX) { ol.UnreferencedBounds.prototype.setMinX = function(minX) {
this.minX_ = minX; this.minX_ = minX;
return this;
}; };
/** /**
@@ -61,11 +59,9 @@ ol.UnreferencedBounds.prototype.getMinY = function() {
/** /**
* @param {number} minY Minimum Y. * @param {number} minY Minimum Y.
* @return {ol.UnreferencedBounds} This.
*/ */
ol.UnreferencedBounds.prototype.setMinY = function(minY) { ol.UnreferencedBounds.prototype.setMinY = function(minY) {
this.minY_ = minY; this.minY_ = minY;
return this;
}; };
/** /**
@@ -77,11 +73,9 @@ ol.UnreferencedBounds.prototype.getMaxX = function() {
/** /**
* @param {number} maxX Maximum X. * @param {number} maxX Maximum X.
* @return {ol.UnreferencedBounds} This.
*/ */
ol.UnreferencedBounds.prototype.setMaxX = function(maxX) { ol.UnreferencedBounds.prototype.setMaxX = function(maxX) {
this.maxX_ = maxX; this.maxX_ = maxX;
return this;
}; };
/** /**
@@ -93,10 +87,8 @@ ol.UnreferencedBounds.prototype.getMaxY = function() {
/** /**
* @param {number} maxY Maximum Y. * @param {number} maxY Maximum Y.
* @return {ol.UnreferencedBounds} This.
*/ */
ol.UnreferencedBounds.prototype.setMaxY = function(maxY) { ol.UnreferencedBounds.prototype.setMaxY = function(maxY) {
this.maxY_ = maxY; this.maxY_ = maxY;
return this;
}; };

View File

@@ -11,7 +11,7 @@ goog.require('goog.style');
/** /**
* Determine whether event was caused by a single touch * Determine whether event was caused by a single touch
* *
* @param {goog.events.BrowserEvent} evt * @param {Event} evt
* @return {boolean} * @return {boolean}
*/ */
ol.event.isSingleTouch = function(evt) { ol.event.isSingleTouch = function(evt) {
@@ -21,7 +21,7 @@ ol.event.isSingleTouch = function(evt) {
/** /**
* Determine whether event was caused by a multi touch * Determine whether event was caused by a multi touch
* *
* @param {goog.events.BrowserEvent} evt * @param {Event} evt
* @return {boolean} * @return {boolean}
*/ */
ol.event.isMultiTouch = function(evt) { ol.event.isMultiTouch = function(evt) {
@@ -49,27 +49,26 @@ ol.event.Events = function(object, opt_element, opt_includeXY) {
goog.base(this); goog.base(this);
/** /**
* @private
* @type {Object} * @type {Object}
* The object that this instance is bound to. * The object that this instance is bound to.
*/ */
this.object_ = object; this.object_ = object;
/** /**
* @type {EventTarget|undefined} * @private
* @type {EventTarget}
* The element that this instance listens to mouse events on. * The element that this instance listens to mouse events on.
*/ */
this.element_ = opt_element; this.element_ = null;
/** /**
* @private
* @type {boolean} * @type {boolean}
*/ */
this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false; this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false;
// if a dom element is specified, add a listeners list this.setElement(opt_element);
// for browser events on the element and register them
if (goog.isDef(opt_element)) {
this.attachToElement_(opt_element);
}
}; };
goog.inherits(ol.event.Events, goog.events.EventTarget); 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 * @param {boolean} includeXY
* fired on the provided element will be relayed by this instance.
*
* @param {!EventTarget} element A DOM element to attach
* browser events to.
*/ */
ol.event.Events.prototype.attachToElement_ = function(element) { ol.event.Events.prototype.setIncludeXY = function(includeXY) {
if (this.element_) { this._includeXY = includeXY;
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
);
}
}; };
/** /**
* 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() { ol.event.Events.prototype.getElement = function() {
var t, types = goog.events.EventType, return this.element_;
element = this.element_; };
if (goog.isDef(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) { for (t in types) {
// register the event cross-browser // register the event cross-browser
goog.events.unlisten( goog.events.unlisten(
element, types[t], this.handleBrowserEvent_, false, this this.element_, types[t], this.handleBrowserEvent, false, this
); );
} }
delete this.element_; 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 * Basically just a wrapper to the triggerEvent() function, but takes
* care to set a property 'xy' on the event with the current mouse position. * care to set a property 'xy' on the event with the current mouse position.
* *
* @private * @param {Event} evt
* @param {goog.events.BrowserEvent} evt
*/ */
ol.event.Events.prototype.handleBrowserEvent_ = function(evt) { ol.event.Events.prototype.handleBrowserEvent = function(evt) {
if (!goog.isDef(this.element_)) { if (!goog.isDef(this.element_)) {
return; return;
} }
@@ -279,10 +283,10 @@ ol.event.Events.prototype.handleBrowserEvent_ = function(evt) {
evt.clientX = x / num; evt.clientX = x / num;
evt.clientY = y / num; evt.clientY = y / num;
} }
var element = /** @type {!Element} */ this._element;
if (this.includeXY) { if (this.includeXY) {
var element = /** @type {!Element} */ this.element_;
evt.xy = goog.style.getRelativePosition(evt, element); evt.xy = goog.style.getRelativePosition(evt, element);
} }
this.dispatchEvent(evt); this.dispatchEvent(evt);
}; };

View File

@@ -4,10 +4,28 @@ describe("ol.Events", function() {
var events, element = document.createElement("div"); var events, element = document.createElement("div");
events = new ol.event.Events("foo"); events = new ol.event.Events("foo");
expect(events.getObject()).toBe("foo"); expect(events.getObject()).toBe("foo");
expect(events.getElement()).toBe(null);
events.destroy(); events.destroy();
events = new ol.event.Events("foo", element, true); events = new ol.event.Events("foo", element, true);
expect(events.element_).toBe(element); expect(events.getElement()).toBe(element);
expect(events.includeXY_).toBe(true); 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");
}); });
}); });

View File

@@ -133,7 +133,6 @@ describe("ol.Map", function() {
expect(proj instanceof ol.Projection).toBe(true); expect(proj instanceof ol.Projection).toBe(true);
expect(proj.code()).toBe("EPSG:4326"); expect(proj.code()).toBe("EPSG:4326");
debugger;
map.center([10, 20]); map.center([10, 20]);
map.userProjection("EPSG:3857"); map.userProjection("EPSG:3857");