Reset cursor when translate interaction is removed or deactivated
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol.interaction.Translate');
|
|||||||
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
|
goog.require('ol.events');
|
||||||
goog.require('ol.events.Event');
|
goog.require('ol.events.Event');
|
||||||
goog.require('ol.functions');
|
goog.require('ol.functions');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
@@ -82,6 +83,11 @@ ol.interaction.Translate = function(opt_options) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.lastFeature_ = null;
|
this.lastFeature_ = null;
|
||||||
|
|
||||||
|
ol.events.listen(this,
|
||||||
|
ol.Object.getChangeEventType(ol.interaction.Property.ACTIVE),
|
||||||
|
this.handleActiveChanged_, this);
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.interaction.Translate, ol.interaction.Pointer);
|
ol.inherits(ol.interaction.Translate, ol.interaction.Pointer);
|
||||||
|
|
||||||
@@ -233,6 +239,43 @@ ol.interaction.Translate.prototype.setHitTolerance = function(hitTolerance) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.interaction.Translate.prototype.setMap = function(map) {
|
||||||
|
var oldMap = this.getMap();
|
||||||
|
ol.interaction.Pointer.prototype.setMap.call(this, map);
|
||||||
|
this.updateState_(oldMap);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.interaction.Translate.prototype.handleActiveChanged_ = function() {
|
||||||
|
this.updateState_(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Map} oldMap Old map.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.interaction.Translate.prototype.updateState_ = function(oldMap) {
|
||||||
|
var map = this.getMap();
|
||||||
|
var active = this.getActive();
|
||||||
|
if ((!map || !active) && this.previousCursor_ !== undefined) {
|
||||||
|
if (!map) {
|
||||||
|
map = oldMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
var elem = map.getTargetElement();
|
||||||
|
elem.style.cursor = this.previousCursor_;
|
||||||
|
this.previousCursor_ = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* Events emitted by {@link ol.interaction.Translate} instances are instances of
|
* Events emitted by {@link ol.interaction.Translate} instances are instances of
|
||||||
|
|||||||
@@ -233,6 +233,50 @@ describe('ol.interaction.Translate', function() {
|
|||||||
expect(element.style.cursor).to.eql('pointer');
|
expect(element.style.cursor).to.eql('pointer');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resets css cursor when interaction is deactivated while pointer is on feature', function() {
|
||||||
|
simulateEvent('pointermove', 10, 20);
|
||||||
|
expect(element.style.cursor).to.match(/grab$/);
|
||||||
|
|
||||||
|
translate.setActive(false);
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 0, 0);
|
||||||
|
expect(element.style.cursor).to.eql('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets css cursor to existing cursor when interaction is deactivated while pointer is on feature', function() {
|
||||||
|
element.style.cursor = 'pointer';
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 10, 20);
|
||||||
|
expect(element.style.cursor).to.match(/grab$/);
|
||||||
|
|
||||||
|
translate.setActive(false);
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 0, 0);
|
||||||
|
expect(element.style.cursor).to.eql('pointer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets css cursor interaction is removed while pointer is on feature', function() {
|
||||||
|
simulateEvent('pointermove', 10, 20);
|
||||||
|
expect(element.style.cursor).to.match(/grab$/);
|
||||||
|
|
||||||
|
map.removeInteraction(translate);
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 0, 0);
|
||||||
|
expect(element.style.cursor).to.eql('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resets css cursor to existing cursor interaction is removed while pointer is on feature', function() {
|
||||||
|
element.style.cursor = 'pointer';
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 10, 20);
|
||||||
|
expect(element.style.cursor).to.match(/grab$/);
|
||||||
|
|
||||||
|
map.removeInteraction(translate);
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 0, 0);
|
||||||
|
expect(element.style.cursor).to.eql('pointer');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user