Skip to content

Commit

Permalink
(wip) gmf-drawfeature, fix bugs in menu while mouse hovering
Browse files Browse the repository at this point in the history
  • Loading branch information
adube committed Apr 13, 2016
1 parent c4e3dd0 commit 53b23a4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contribs/gmf/src/directives/drawfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ gmf.DrawfeatureController.prototype.handleMenuActionClick_ = function(evt) {
break;
case gmf.DrawfeatureController.MenuActionType.MOVE:
this.translate_.setActive(true);
this.scope_.$apply();
break;
default:
// FIXME
Expand All @@ -457,6 +458,7 @@ gmf.DrawfeatureController.prototype.handleMenuActionClick_ = function(evt) {
*/
gmf.DrawfeatureController.prototype.handleTranslateEnd_ = function(evt) {
this.translate_.setActive(false);
this.scope_.$apply();
};


Expand Down
42 changes: 42 additions & 0 deletions src/ol-ext/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ ngeo.Menu = function(menuOptions, opt_overlayOptions) {
*/
this.listenerKeys_ = [];

/**
* @type {Array.<ol.events.Key>}
* @private
*/
this.olListenerKeys_ = [];

var contentEl = $('<div/>', {
'class': 'panel panel-default'
});
Expand Down Expand Up @@ -143,13 +149,18 @@ goog.inherits(ngeo.Menu, ol.Overlay);
ngeo.Menu.prototype.setMap = function(map) {

var keys = this.listenerKeys_;
var olKeys = this.olListenerKeys_;

var currentMap = this.getMap();
if (currentMap) {
keys.forEach(function(key) {
goog.events.unlistenByKey(key);
}, this);
keys.length = 0;
olKeys.forEach(function(key) {
ol.events.unlistenByKey(key);
}, this);
olKeys.length = 0;
}

goog.base(this, 'setMap', map);
Expand All @@ -169,6 +180,14 @@ ngeo.Menu.prototype.setMap = function(map) {
)
);
}, this);
olKeys.push(
ol.events.listen(
map,
ol.MapBrowserEvent.EventType.POINTERMOVE,
this.handleMapPointerMove_,
this
)
);
}

};
Expand All @@ -195,3 +214,26 @@ ngeo.Menu.prototype.handleActionClick_ = function(action) {
this.close();
}
};


/**
* When the mouse is hovering the menu, set the event coordinate and pixel
* values to Infinity to do as if the mouse had been move out of range of the
* map. This prevents behaviours such as vertex still appearing while mouse
* hovering edges of features bound to an active modify control while the
* cursor is on top of the menu.
* @param {ol.MapBrowserEvent} evt Event.
* @private
*/
ngeo.Menu.prototype.handleMapPointerMove_ = function(evt) {
var target = evt.originalEvent.target;
goog.asserts.assertInstanceof(target, Element);

var element = this.getElement();
goog.asserts.assertInstanceof(element, Element);

if (goog.dom.contains(element, target)) {
evt.coordinate = [Infinity, Infinity];
evt.pixel = [Infinity, Infinity];
}
};

0 comments on commit 53b23a4

Please sign in to comment.