Convert ol.MapBrowserEvent#get* methods into properties

This commit is contained in:
Tom Payne
2014-01-27 16:07:34 +01:00
parent 390b61762e
commit 318fc68159
26 changed files with 89 additions and 87 deletions
+10 -39
View File
@@ -18,6 +18,7 @@ goog.require('ol.Pixel');
/**
* @constructor
* @extends {ol.MapEvent}
* @implements {oli.MapBrowserEvent}
* @param {string} type Event type.
* @param {ol.Map} map Map.
* @param {goog.events.BrowserEvent} browserEvent Browser event.
@@ -35,55 +36,25 @@ ol.MapBrowserEvent = function(type, map, browserEvent, opt_frameState) {
this.browserEvent = browserEvent;
/**
* @private
* @type {ol.Coordinate}
* @const
* @type {Event}
*/
this.coordinate_ = null;
this.originalEvent = browserEvent.getBrowserEvent();
/**
* @type {ol.Coordinate}
*/
this.coordinate = map.getEventCoordinate(this.originalEvent);
/**
* @private
* @type {ol.Pixel}
*/
this.pixel_ = null;
this.pixel = map.getEventPixel(this.originalEvent);
};
goog.inherits(ol.MapBrowserEvent, ol.MapEvent);
/**
* @return {Event} The underlying browser event object.
*/
ol.MapBrowserEvent.prototype.getBrowserEvent = function() {
return this.browserEvent.getBrowserEvent();
};
/**
* @return {ol.Coordinate} Coordinate.
* @todo stability experimental
*/
ol.MapBrowserEvent.prototype.getCoordinate = function() {
if (goog.isNull(this.coordinate_)) {
this.coordinate_ = this.map.getEventCoordinate(
this.browserEvent.getBrowserEvent());
}
return this.coordinate_;
};
/**
* Get pixel offset of the event from the top-left corner of the map viewport.
* @return {ol.Pixel} Pixel offset.
* @todo stability experimental
*/
ol.MapBrowserEvent.prototype.getPixel = function() {
if (goog.isNull(this.pixel_)) {
this.pixel_ = this.map.getEventPixel(this.browserEvent.getBrowserEvent());
}
return this.pixel_;
};
/**
* Prevents the default browser action.
* @see https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault