Merge pull request #1129 from elemoine/eventcoord

Add ol.Map#getEventPixel and ol.Map#getEventCoordinate
This commit is contained in:
Éric Lemoine
2013-10-15 04:03:07 -07:00
3 changed files with 27 additions and 5 deletions

View File

@@ -4,12 +4,15 @@
@exportProperty ol.Map.prototype.addOverlay
@exportProperty ol.Map.prototype.beforeRender
@exportProperty ol.Map.prototype.getControls
@exportProperty ol.Map.prototype.getEventCoordinate
@exportProperty ol.Map.prototype.getEventPixel
@exportProperty ol.Map.prototype.getFeatureInfo
@exportProperty ol.Map.prototype.getFeatures
@exportProperty ol.Map.prototype.getInteractions
@exportProperty ol.Map.prototype.getLayers
@exportProperty ol.Map.prototype.getOverlays
@exportProperty ol.Map.prototype.getRenderer
@exportProperty ol.Map.prototype.getViewport
@exportProperty ol.Map.prototype.removeControl
@exportProperty ol.Map.prototype.removeLayer
@exportProperty ol.Map.prototype.removeOverlay

View File

@@ -430,6 +430,27 @@ ol.Map.prototype.freezeRendering = function() {
};
/**
* Returns the map pixel position for a a browser event.
* @param {Event} event Event.
* @return {ol.Coordinate} Coordinate.
*/
ol.Map.prototype.getEventCoordinate = function(event) {
return this.getCoordinateFromPixel(this.getEventPixel(event));
};
/**
* Returns the geographical coordinate for a browser event.
* @param {Event} event Event.
* @return {ol.Pixel} Pixel.
*/
ol.Map.prototype.getEventPixel = function(event) {
var eventPosition = goog.style.getRelativePosition(event, this.viewport_);
return [eventPosition.x, eventPosition.y];
};
/**
* Get the map's renderer.
* @return {ol.renderer.Map} Renderer.

View File

@@ -7,7 +7,6 @@ goog.require('goog.events');
goog.require('goog.events.BrowserEvent');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
goog.require('goog.style');
goog.require('ol.BrowserFeature');
goog.require('ol.Coordinate');
goog.require('ol.FrameState');
@@ -54,7 +53,8 @@ goog.inherits(ol.MapBrowserEvent, ol.MapEvent);
*/
ol.MapBrowserEvent.prototype.getCoordinate = function() {
if (goog.isNull(this.coordinate_)) {
this.coordinate_ = this.map.getCoordinateFromPixel(this.getPixel());
this.coordinate_ = this.map.getEventCoordinate(
this.browserEvent.getBrowserEvent());
}
return this.coordinate_;
};
@@ -66,9 +66,7 @@ ol.MapBrowserEvent.prototype.getCoordinate = function() {
*/
ol.MapBrowserEvent.prototype.getPixel = function() {
if (goog.isNull(this.pixel_)) {
var eventPosition = goog.style.getRelativePosition(
this.browserEvent, this.map.getViewport());
this.pixel_ = [eventPosition.x, eventPosition.y];
this.pixel_ = this.map.getEventPixel(this.browserEvent.getBrowserEvent());
}
return this.pixel_;
};