stop clicks on the point handler - this means no more clicks sneaking through while editing - if you wanted that behavior, speak up - r=crschmidt (closes #1020)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5523 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -172,9 +172,26 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.lastUp = null;
|
this.lastUp = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: click
|
||||||
|
* Handle clicks. Clicks are stopped from propagating to other listeners
|
||||||
|
* on map.events or other dom elements.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* evt - {Event} The browser event
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Boolean} Allow event propagation
|
||||||
|
*/
|
||||||
|
click: function(evt) {
|
||||||
|
OpenLayers.Event.stop(evt);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: dblclick
|
* Method: dblclick
|
||||||
* Handle double clicks.
|
* Handle double-clicks. Double-clicks are stopped from propagating to other
|
||||||
|
* listeners on map.events or other dom elements.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* evt - {Event} The browser event
|
* evt - {Event} The browser event
|
||||||
|
|||||||
+156
-100
@@ -1,48 +1,104 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script src="../../lib/OpenLayers.js"></script>
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function test_Handler_Point_constructor(t) {
|
function test_Handler_Point_constructor(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
var control = new OpenLayers.Control();
|
var control = new OpenLayers.Control();
|
||||||
control.id = Math.random();
|
control.id = Math.random();
|
||||||
var callbacks = {foo: "bar"};
|
var callbacks = {foo: "bar"};
|
||||||
var options = {bar: "foo"};
|
var options = {bar: "foo"};
|
||||||
|
|
||||||
var oldInit = OpenLayers.Handler.prototype.initialize;
|
var oldInit = OpenLayers.Handler.prototype.initialize;
|
||||||
|
|
||||||
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
|
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
|
||||||
t.eq(con.id, control.id,
|
t.eq(con.id, control.id,
|
||||||
"constructor calls parent with the correct control");
|
"constructor calls parent with the correct control");
|
||||||
t.eq(call, callbacks,
|
t.eq(call, callbacks,
|
||||||
"constructor calls parent with the correct callbacks");
|
"constructor calls parent with the correct callbacks");
|
||||||
t.eq(opt, options,
|
t.eq(opt, options,
|
||||||
"constructor calls parent with the correct options");
|
"constructor calls parent with the correct options");
|
||||||
}
|
}
|
||||||
var handler = new OpenLayers.Handler.Point(control, callbacks, options);
|
var handler = new OpenLayers.Handler.Point(control, callbacks, options);
|
||||||
|
|
||||||
OpenLayers.Handler.prototype.initialize = oldInit;
|
OpenLayers.Handler.prototype.initialize = oldInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Handler_Point_activation(t) {
|
function test_Handler_Point_activation(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
var control = new OpenLayers.Control();
|
var control = new OpenLayers.Control();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
var handler = new OpenLayers.Handler.Point(control);
|
var handler = new OpenLayers.Handler.Point(control);
|
||||||
handler.active = true;
|
handler.active = true;
|
||||||
var activated = handler.activate();
|
var activated = handler.activate();
|
||||||
t.ok(!activated,
|
t.ok(!activated,
|
||||||
"activate returns false if the handler was already active");
|
"activate returns false if the handler was already active");
|
||||||
handler.active = false;
|
handler.active = false;
|
||||||
activated = handler.activate();
|
activated = handler.activate();
|
||||||
t.ok(activated,
|
t.ok(activated,
|
||||||
"activate returns true if the handler was not already active");
|
"activate returns true if the handler was not already active");
|
||||||
activated = handler.deactivate();
|
activated = handler.deactivate();
|
||||||
t.ok(activated,
|
t.ok(activated,
|
||||||
"deactivate returns true if the handler was active already");
|
"deactivate returns true if the handler was active already");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Handler_Point_events(t) {
|
||||||
|
t.plan(29);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var control = {
|
||||||
|
map: map
|
||||||
|
};
|
||||||
|
var handler = new OpenLayers.Handler.Point(control);
|
||||||
|
|
||||||
|
// list below events that should be handled (events) and those
|
||||||
|
// that should not be handled (nonevents) by the handler
|
||||||
|
var events = ["click", "dblclick", "mousedown", "mouseup", "mousemove"];
|
||||||
|
var nonevents = ["mouseout", "resize", "focus", "blur"];
|
||||||
|
map.events.registerPriority = function(type, obj, func) {
|
||||||
|
var r = func();
|
||||||
|
if(typeof r == "string") {
|
||||||
|
// this is one of the mock handler methods
|
||||||
|
t.eq(OpenLayers.Util.indexOf(nonevents, type), -1,
|
||||||
|
"registered method is not one of the events " +
|
||||||
|
"that should not be handled");
|
||||||
|
t.ok(OpenLayers.Util.indexOf(events, type) > -1,
|
||||||
|
"activate calls registerPriority with browser event: " + type);
|
||||||
|
t.eq(typeof func, "function",
|
||||||
|
"activate calls registerPriority with a function");
|
||||||
|
t.eq(func(), type,
|
||||||
|
"activate calls registerPriority with the correct method");
|
||||||
|
t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.Point",
|
||||||
|
"activate calls registerPriority with the handler");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set browser event like properties on the handler
|
||||||
|
for(var i=0; i<events.length; ++i) {
|
||||||
|
setMethod(events[i]);
|
||||||
|
}
|
||||||
|
function setMethod(key) {
|
||||||
|
handler[key] = function() {return key};
|
||||||
|
}
|
||||||
|
|
||||||
|
var activated = handler.activate();
|
||||||
|
handler.destroy();
|
||||||
|
|
||||||
|
// test that click and dblclick are stopped
|
||||||
|
var handler = new OpenLayers.Handler.Point(control);
|
||||||
|
var oldStop = OpenLayers.Event.stop;
|
||||||
|
OpenLayers.Event.stop = function(evt) {
|
||||||
|
t.ok(evt.type == "click" || evt.type == "dblclick",
|
||||||
|
evt.type + " stopped");
|
||||||
|
}
|
||||||
|
t.eq(handler.click({type: "click"}), false, "click returns false");
|
||||||
|
t.eq(handler.dblclick({type: "dblclick"}), false, "dblclick returns false");
|
||||||
|
OpenLayers.Event.stop = oldStop;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function test_Handler_Point_deactivation(t) {
|
function test_Handler_Point_deactivation(t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
@@ -56,58 +112,58 @@
|
|||||||
t.eq(handler.layer, null,
|
t.eq(handler.layer, null,
|
||||||
"deactivate doesn't throw an error if layer was" +
|
"deactivate doesn't throw an error if layer was" +
|
||||||
" previously destroyed");
|
" previously destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Handler_Point_bounds(t) {
|
function test_Handler_Point_bounds(t) {
|
||||||
t.plan(4);
|
t.plan(4);
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
||||||
map.zoomToMaxExtent();
|
map.zoomToMaxExtent();
|
||||||
var control = new OpenLayers.Control();
|
var control = new OpenLayers.Control();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
var handler = new OpenLayers.Handler.Point(control);
|
var handler = new OpenLayers.Handler.Point(control);
|
||||||
var activated = handler.activate();
|
var activated = handler.activate();
|
||||||
var px = new OpenLayers.Pixel(150, 75);
|
var px = new OpenLayers.Pixel(150, 75);
|
||||||
var evt = {xy: px, which: 1};
|
var evt = {xy: px, which: 1};
|
||||||
handler.mousedown(evt);
|
handler.mousedown(evt);
|
||||||
var lonlat = map.getLonLatFromPixel(px);
|
var lonlat = map.getLonLatFromPixel(px);
|
||||||
t.eq(handler.point.geometry.x, lonlat.lon, "X is correct");
|
t.eq(handler.point.geometry.x, lonlat.lon, "X is correct");
|
||||||
t.eq(handler.point.geometry.y, lonlat.lat, "Y is correct");
|
t.eq(handler.point.geometry.y, lonlat.lat, "Y is correct");
|
||||||
t.ok(handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(lonlat.lon,lonlat.lat,lonlat.lon,lonlat.lat)), "Correct bounds");
|
t.ok(handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(lonlat.lon,lonlat.lat,lonlat.lon,lonlat.lat)), "Correct bounds");
|
||||||
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
|
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
|
||||||
handler.mousemove(evt);
|
handler.mousemove(evt);
|
||||||
t.ok(!handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(0,0,0,0)), "Bounds changed after moving mouse");
|
t.ok(!handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(0,0,0,0)), "Bounds changed after moving mouse");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Handler_Point_destroy(t) {
|
function test_Handler_Point_destroy(t) {
|
||||||
t.plan(4);
|
t.plan(4);
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
||||||
map.zoomToMaxExtent();
|
map.zoomToMaxExtent();
|
||||||
var control = new OpenLayers.Control();
|
var control = new OpenLayers.Control();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'});
|
var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'});
|
||||||
|
|
||||||
handler.activate();
|
handler.activate();
|
||||||
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
||||||
handler.mousedown(evt);
|
handler.mousedown(evt);
|
||||||
|
|
||||||
t.ok(handler.layer,
|
t.ok(handler.layer,
|
||||||
"handler has a layer prior to destroy");
|
"handler has a layer prior to destroy");
|
||||||
t.ok(handler.point,
|
t.ok(handler.point,
|
||||||
"handler has a point prior to destroy");
|
"handler has a point prior to destroy");
|
||||||
handler.destroy();
|
handler.destroy();
|
||||||
t.eq(handler.layer, null,
|
t.eq(handler.layer, null,
|
||||||
"handler.layer is null after destroy");
|
"handler.layer is null after destroy");
|
||||||
t.eq(handler.point, null,
|
t.eq(handler.point, null,
|
||||||
"handler.point is null after destroy");
|
"handler.point is null after destroy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map" style="width: 300px; height: 150px;"/>
|
<div id="map" style="width: 300px; height: 150px;"/>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user