Merge branch 'master' into event

Conflicts:
	src/ol/Map.js
	src/ol/event/Drag.js
This commit is contained in:
Éric Lemoine
2012-07-09 08:57:55 +02:00
14 changed files with 670 additions and 381 deletions

View File

@@ -43,9 +43,7 @@ ol.control.Attribution.prototype.setMap = function(map) {
var staticOverlay = map.getStaticOverlay();
if (goog.isNull(this.container_)) {
this.container_ = goog.dom.createDom('div', this.CLS);
// This is not registered as priority listener, so priority listeners
// can still get the click event.
map.getEvents().register('click', this.stopLinkClick, this);
goog.events.listen(this.container_, 'click', ol.event.stopPropagation);
}
if (!goog.isNull(staticOverlay)) {
goog.dom.append(staticOverlay, this.container_);
@@ -53,16 +51,6 @@ ol.control.Attribution.prototype.setMap = function(map) {
goog.base(this, 'setMap', map);
};
/**
* Prevent clicks on links in the attribution from getting through to
* listeners.
*/
ol.control.Attribution.prototype.stopLinkClick = function(evt) {
var node = evt.target;
return node.nodeName !== 'A' ||
!goog.dom.getAncestorByClass(node, this.CLS);
};
/** @inheritDoc */
ol.control.Attribution.prototype.activate = function() {
var active = goog.base(this, 'activate');
@@ -96,6 +84,7 @@ ol.control.Attribution.prototype.update = function() {
};
ol.control.Attribution.prototype.destroy = function() {
goog.events.unlisten(this.container_, 'click', ol.event.stopPropagation);
goog.dom.removeNode(this.container_);
goog.base(this, 'destroy');
};

View File

@@ -20,6 +20,12 @@ ol.control.Navigation = function(opt_autoActivate) {
this.autoActivate_ =
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
/**
* @type {number?}
* @private
*/
this.zoomBlocked_ = null;
};
goog.inherits(ol.control.Navigation, ol.control.Control);
@@ -52,7 +58,7 @@ ol.control.Navigation.prototype.deactivate = function() {
* @param {Object} evt
*/
ol.control.Navigation.prototype.moveMap = function(evt) {
this.map_.moveByPx(evt.deltaX, evt.deltaY);
this.map_.moveByViewportPx(evt.deltaX, evt.deltaY);
return false;
};
@@ -60,12 +66,17 @@ ol.control.Navigation.prototype.moveMap = function(evt) {
* @param {Event} evt
*/
ol.control.Navigation.prototype.zoomMap = function(evt) {
var map = this.map_,
delta = ((evt.deltaY / 3) | 0);
if (Math.abs(delta) === 0) {
var me = this;
if (evt.deltaY === 0 || me.zoomBlocked_) {
return;
}
map.setZoom(map.getZoom()-delta, map.getEvents().getPointerPosition(evt));
me.zoomBlocked_ = window.setTimeout(function() {
me.zoomBlocked_ = null;
}, 200);
var map = me.map_,
step = evt.deltaY / Math.abs(evt.deltaY);
map.setZoom(map.getZoom()-step, map.getEvents().getPointerPosition(evt));
// We don't want the page to scroll.
evt.preventDefault();
return false;

View File

@@ -12,13 +12,23 @@ goog.require('goog.dom');
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.Zoom = function(opt_autoActivate) {
goog.base(this, opt_autoActivate);
/**
* @type {Node}
*/
this.inButton_ = null;
/**
* @type {Node}
*/
this.outButton_ = null;
/**
* Activate this control when it is added to a map. Default is true.
*
* @type {boolean} autoActivate
* @type {boolean}
*/
this.autoActivate_ =
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
@@ -30,38 +40,38 @@ goog.inherits(ol.control.Zoom, ol.control.Control);
* @param {ol.Map} map
*/
ol.control.Zoom.prototype.setMap = function(map) {
goog.base(this, 'setMap', map);
var container = goog.dom.createDom('div', ol.control.Zoom.RES.CLS);
var inButton = goog.dom.createDom(
this.inButton_ = goog.dom.createDom(
'div', ol.control.Zoom.RES.IN_CLS,
goog.dom.createDom('a', {'href': '#zoomIn'})
);
goog.dom.setTextContent(
/** @type {Element} */ (inButton.firstChild),
/** @type {Element} */ (this.inButton_.firstChild),
ol.control.Zoom.RES.IN_TEXT
);
var outButton = goog.dom.createDom(
this.outButton_ = goog.dom.createDom(
'div', ol.control.Zoom.RES.OUT_CLS,
goog.dom.createDom('a', {'href': '#zoomOut'})
);
goog.dom.setTextContent(
/** @type {Element} */ (outButton.firstChild),
/** @type {Element} */ (this.outButton_.firstChild),
ol.control.Zoom.RES.OUT_TEXT
);
goog.dom.append(container, inButton, outButton);
goog.dom.append(container, this.inButton_, this.outButton_);
var overlay = map.getStaticOverlay();
if (goog.isDefAndNotNull(overlay)) {
goog.dom.append(overlay, container);
}
goog.base(this, 'setMap', map);
};
/** @inheritDoc */
ol.control.Zoom.prototype.activate = function() {
var active = goog.base(this, 'activate');
if (active) {
this.map_.getEvents().register('click', this.handle, this);
this.map_.getEvents().register('keypress', this.handle, this);
goog.events.listen(this.inButton_, 'click', this.handleIn, false, this);
goog.events.listen(this.outButton_, 'click', this.handleOut, false, this);
}
return active;
};
@@ -70,37 +80,28 @@ ol.control.Zoom.prototype.activate = function() {
ol.control.Zoom.prototype.deactivate = function() {
var inactive = goog.base(this, 'deactivate');
if (inactive) {
this.map_.getEvents().unregister('click', this.handle, this);
this.map_.getEvents().unregister('keypress', this.handle, this);
goog.events.unlisten(this.inButton_, 'click', this.handleIn, false, this);
goog.events.unlisten(this.outButton_, 'click', this.handleOut, false, this);
}
return inactive;
};
/**
* @param {Event} evt
* @return {boolean}
*/
ol.control.Zoom.prototype.handle = function(evt) {
var target = /** @type {Node} */ (evt.target),
handled = false;
if (evt.type === 'click' || ol.event.isEnterOrSpace(evt)) {
if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.IN_CLS)) {
this.map_.zoomIn();
handled = true;
} else
if (goog.dom.getAncestorByClass(target, ol.control.Zoom.RES.OUT_CLS)) {
this.map_.zoomOut();
handled = true;
}
if (handled) {
// Stop default behavior (i.e. don't follow link to anchor)
evt.preventDefault();
// On Android 2.3, the above does not prevent the link from being
// followed, but stopPropagation does.
evt.stopPropagation();
}
}
return !handled;
ol.control.Zoom.prototype.handleIn = function(evt) {
this.map_.zoomIn();
evt.preventDefault();
evt.stopPropagation();
};
/**
* @param {Event} evt
*/
ol.control.Zoom.prototype.handleOut = function(evt) {
this.map_.zoomOut();
evt.preventDefault();
evt.stopPropagation();
};
ol.control.Zoom.prototype.destroy = function() {