Skip to content

Commit

Permalink
Merge pull request openlayers#1452 from tonio/vector-api-dragbox-webgl
Browse files Browse the repository at this point in the history
[vector-api] Re-enable dragzoom for every renderer
  • Loading branch information
tonio committed Jan 3, 2014
2 parents 975dd31 + 2ebfba2 commit fec4fd6
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 127 deletions.
52 changes: 0 additions & 52 deletions examples/dragzoom.html

This file was deleted.

38 changes: 0 additions & 38 deletions examples/dragzoom.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/objectliterals.jsdoc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@
* desired. Default is `true`.
* @property {boolean|undefined} mouseWheelZoom Whether mousewheel zoom is
* desired. Default is `true`.
* @property {boolean|undefined} shiftDragZoom Whether Shift-drag zoom is
* desired. Default is `true`.
* @property {boolean|undefined} touchPan Whether touch pan is
* desired. Default is `true`.
* @property {boolean|undefined} touchRotate Whether touch rotate is desired. Default is `true`.
Expand Down
12 changes: 9 additions & 3 deletions src/ol/interaction/dragboxinteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ ol.interaction.DragBox = function(opt_options) {
*/
this.box_ = new ol.render.Box(style);

/**
* @type {ol.Pixel}
* @private
*/
this.startPixel_ = null;

/**
* @private
* @type {ol.events.ConditionType}
Expand All @@ -107,8 +113,7 @@ goog.inherits(ol.interaction.DragBox, ol.interaction.Drag);
* @inheritDoc
*/
ol.interaction.DragBox.prototype.handleDrag = function(mapBrowserEvent) {
this.box_.setCoordinates(
this.startCoordinate, mapBrowserEvent.getCoordinate());
this.box_.setPixels(this.startPixel_, mapBrowserEvent.getPixel());
};


Expand Down Expand Up @@ -150,8 +155,9 @@ ol.interaction.DragBox.prototype.handleDragStart =
function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.browserEvent;
if (browserEvent.isMouseActionButton() && this.condition_(mapBrowserEvent)) {
this.box_.setCoordinates(this.startCoordinate, this.startCoordinate);
this.startPixel_ = mapBrowserEvent.getPixel();
this.box_.setMap(mapBrowserEvent.map);
this.box_.setPixels(this.startPixel_, this.startPixel_);
this.dispatchEvent(new ol.DragBoxEvent(ol.DragBoxEventType.BOXSTART,
mapBrowserEvent.getCoordinate()));
return true;
Expand Down
24 changes: 16 additions & 8 deletions src/ol/interaction/dragzoominteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ goog.provide('ol.interaction.DragZoom');

goog.require('goog.asserts');
goog.require('ol.events.condition');
goog.require('ol.extent');
goog.require('ol.interaction.DragBox');
goog.require('ol.interaction.Interaction');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');


/**
* @define {number} Timeout duration.
*/
ol.interaction.DRAGZOOM_ANIMATION_DURATION = 200;



/**
* Allows the user to zoom the map by clicking and dragging on the map,
Expand Down Expand Up @@ -47,12 +55,12 @@ goog.inherits(ol.interaction.DragZoom, ol.interaction.DragBox);
* @inheritDoc
*/
ol.interaction.DragZoom.prototype.onBoxEnd = function() {
this.getMap().withFrozenRendering(goog.bind(function() {
// FIXME works for View2D only
var view = this.getMap().getView().getView2D();

view.fitExtent(this.getGeometry().getExtent(), this.getMap().getSize());
// FIXME we should preserve rotation
view.setRotation(0);
}, this));
// FIXME works for View2D only
var map = this.getMap();
var view = map.getView().getView2D();
var extent = this.getGeometry().getExtent();
var center = ol.extent.getCenter(extent);
ol.interaction.Interaction.zoom(map, view,
view.getResolutionForExtent(extent, map.getSize()),
center, ol.interaction.DRAGZOOM_ANIMATION_DURATION);
};
7 changes: 7 additions & 0 deletions src/ol/interaction/interactiondefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ goog.require('ol.Kinetic');
goog.require('ol.interaction.DoubleClickZoom');
goog.require('ol.interaction.DragPan');
goog.require('ol.interaction.DragRotate');
goog.require('ol.interaction.DragZoom');
goog.require('ol.interaction.KeyboardPan');
goog.require('ol.interaction.KeyboardZoom');
goog.require('ol.interaction.MouseWheelZoom');
Expand Down Expand Up @@ -98,6 +99,12 @@ ol.interaction.defaults = function(opt_options) {
}));
}

var shiftDragZoom = goog.isDef(options.shiftDragZoom) ?
options.shiftDragZoom : true;
if (shiftDragZoom) {
interactions.push(new ol.interaction.DragZoom());
}

return interactions;

};
49 changes: 26 additions & 23 deletions src/ol/render/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
goog.provide('ol.render.Box');

goog.require('goog.Disposable');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('ol.geom.Polygon');
Expand Down Expand Up @@ -31,15 +32,15 @@ ol.render.Box = function(style) {

/**
* @private
* @type {ol.Coordinate}
* @type {ol.Pixel}
*/
this.startCoordinate_ = null;
this.startPixel_ = null;

/**
* @private
* @type {ol.Coordinate}
* @type {ol.Pixel}
*/
this.endCoordinate_ = null;
this.endPixel_ = null;

/**
* @private
Expand All @@ -62,19 +63,22 @@ goog.inherits(ol.render.Box, goog.Disposable);
* @return {ol.geom.Polygon} Geometry.
*/
ol.render.Box.prototype.createGeometry_ = function() {
goog.asserts.assert(!goog.isNull(this.startCoordinate_));
goog.asserts.assert(!goog.isNull(this.endCoordinate_));
var startCoordinate = this.startCoordinate_;
var endCoordinate = this.endCoordinate_;
var coordinates = [
goog.asserts.assert(!goog.isNull(this.startPixel_));
goog.asserts.assert(!goog.isNull(this.endPixel_));
goog.asserts.assert(!goog.isNull(this.map_));
var startPixel = this.startPixel_;
var endPixel = this.endPixel_;
var pixels = [
[
startCoordinate,
[startCoordinate[0], endCoordinate[1]],
endCoordinate,
[endCoordinate[0], startCoordinate[1]]
startPixel,
[startPixel[0], endPixel[1]],
endPixel,
[endPixel[0], startPixel[1]]
]
];
return new ol.geom.Polygon(coordinates);
var coordinates = goog.array.map(pixels[0],
this.map_.getCoordinateFromPixel, this.map_);
return new ol.geom.Polygon([coordinates]);
};


Expand All @@ -91,7 +95,6 @@ ol.render.Box.prototype.disposeInternal = function() {
* @private
*/
ol.render.Box.prototype.handleMapPostCompose_ = function(event) {
this.geometry_ = this.createGeometry_();
var style = this.style_;
goog.asserts.assert(!goog.isNull(style));
var render = event.getRender();
Expand All @@ -113,8 +116,8 @@ ol.render.Box.prototype.getGeometry = function() {
*/
ol.render.Box.prototype.requestMapRenderFrame_ = function() {
if (!goog.isNull(this.map_) &&
!goog.isNull(this.startCoordinate_) &&
!goog.isNull(this.endCoordinate_)) {
!goog.isNull(this.startPixel_) &&
!goog.isNull(this.endPixel_)) {
this.map_.requestRenderFrame();
}
};
Expand All @@ -141,12 +144,12 @@ ol.render.Box.prototype.setMap = function(map) {


/**
* @param {ol.Coordinate} startCoordinate Start coordinate.
* @param {ol.Coordinate} endCoordinate End coordinate.
* @param {ol.Pixel} startPixel Start pixel.
* @param {ol.Pixel} endPixel End pixel.
*/
ol.render.Box.prototype.setCoordinates =
function(startCoordinate, endCoordinate) {
this.startCoordinate_ = startCoordinate;
this.endCoordinate_ = endCoordinate;
ol.render.Box.prototype.setPixels = function(startPixel, endPixel) {
this.startPixel_ = startPixel;
this.endPixel_ = endPixel;
this.geometry_ = this.createGeometry_();
this.requestMapRenderFrame_();
};
Loading

0 comments on commit fec4fd6

Please sign in to comment.