update default behaviour of popups. now you can click and drag inside a popup without the events dropping through to the map, yet if you are dragging a zoombox over a popup, it still responds. this is all thanks to a new function i am adding to Util.js which is called OpenLayers.Util.safeStopPropagaition(). Turns out the default Event.stop() from prototype.js is also calling a function called preventDefault() which disallows things like selecting text or clicking a hyperlink. all tests pass.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1438 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#map {
|
#map {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 512px;
|
height: 100%;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: blue;
|
background-color: blue;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-6
@@ -3,8 +3,8 @@
|
|||||||
<meta http-equiv="imagetoolbar" content="no"> <!--ie image gizmo OFF!-->
|
<meta http-equiv="imagetoolbar" content="no"> <!--ie image gizmo OFF!-->
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#map {
|
#map {
|
||||||
width: 512px;
|
width: 400px;
|
||||||
height: 512px;
|
height: 400px;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -22,6 +22,15 @@
|
|||||||
|
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
map.zoomToMaxExtent();
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar(e) {
|
||||||
|
alert("body");
|
||||||
|
}
|
||||||
|
function foo(e) {
|
||||||
|
alert("yo");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function changer() {
|
function changer() {
|
||||||
@@ -70,9 +79,10 @@
|
|||||||
function mousedown(evt) {
|
function mousedown(evt) {
|
||||||
if (popup == null) {
|
if (popup == null) {
|
||||||
popup = feature.createPopup();
|
popup = feature.createPopup();
|
||||||
|
popup.setContentHTML("<a href='http://www.somethingconstructive.net' target='_blank'>click me</a>");
|
||||||
popup.setBackgroundColor("yellow");
|
popup.setBackgroundColor("yellow");
|
||||||
popup.setOpacity(0.7);
|
popup.setOpacity(0.7);
|
||||||
popup.events.register("mousedown", popup, onPopupMouseDown);
|
// popup.events.register("mousedown", popup, onPopupMouseDown);
|
||||||
markers.map.addPopup(popup);
|
markers.map.addPopup(popup);
|
||||||
} else {
|
} else {
|
||||||
markers.map.removePopup(popup);
|
markers.map.removePopup(popup);
|
||||||
@@ -112,12 +122,14 @@
|
|||||||
</head>
|
</head>
|
||||||
<body onload="init()">
|
<body onload="init()">
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
<div style="background-color:purple" onclick="add()"> click to add Popup to map</div>
|
<div id="foo" style="background-color:purple" onclick="add()"> click to add Popup to map</div>
|
||||||
<div style="background-color:green" onclick="addMarker()"> click to add a Marker with an AnchoredBubble popup</div>
|
<div style="background-color:green" onclick="addMarker()"> click to add a Marker with an AnchoredBubble popup</div>
|
||||||
<div style="background-color:blue" onclick="changer()"> click to modify popup's attributes</div>
|
<div style="background-color:blue" onclick="changer()"> click to modify popup's attributes</div>
|
||||||
<div style="background-color:red" onclick="remove()"> click to remove the popup from map</div>
|
<div style="background-color:red" onclick="remove()"> click to remove the popup from map</div>
|
||||||
<div style="background-color:grey" onclick="removelayer()"> click to remove the markers layer</div>
|
<div style="background-color:grey" onclick="removelayer()"> click to remove the markers layer</div>
|
||||||
<div style="background-color:orange" onclick="alert(marker.onScreen())"> marker.onscreen()?</div>
|
<div id="yar" style="background-color:orange" onclick="alert(marker.onScreen())"> marker.onscreen()?</div>
|
||||||
<div style="background-color:yellow" onclick="destroy()"> click to destroy the popup from map</div>
|
<div id="ar" style="background-color:yellow">
|
||||||
|
<a href='http://www.somethingconstructive.net' target='_blank'>click me</a>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+82
-1
@@ -75,7 +75,7 @@ OpenLayers.Popup.prototype = {
|
|||||||
this.div = OpenLayers.Util.createDiv(this.id, null, null,
|
this.div = OpenLayers.Util.createDiv(this.id, null, null,
|
||||||
null, null, null, "hidden");
|
null, null, null, "hidden");
|
||||||
|
|
||||||
this.events = new OpenLayers.Events(this, this.div, null);
|
this.registerEvents();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,5 +231,86 @@ OpenLayers.Popup.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/** Do this in a separate function so that subclasses can
|
||||||
|
* choose to override it if they wish to deal differently
|
||||||
|
* with mouse events
|
||||||
|
*
|
||||||
|
* Note in the following handler functions that some special
|
||||||
|
* care is needed to deal correctly with mousing and popups.
|
||||||
|
*
|
||||||
|
* Because the user might select the zoom-rectangle option and
|
||||||
|
* then drag it over a popup, we need a safe way to allow the
|
||||||
|
* mousemove and mouseup events to pass through the popup when
|
||||||
|
* they are initiated from outside.
|
||||||
|
*
|
||||||
|
* Otherwise, we want to essentially kill the event propagation
|
||||||
|
* for all other events, though we have to do so carefully,
|
||||||
|
* without disabling basic html functionality, like clicking on
|
||||||
|
* hyperlinks or drag-selecting text.
|
||||||
|
*/
|
||||||
|
registerEvents:function() {
|
||||||
|
Event.observe(this.div, "mousedown",
|
||||||
|
this.onmousedown.bindAsEventListener(this));
|
||||||
|
Event.observe(this.div, "mousemove",
|
||||||
|
this.onmousemove.bindAsEventListener(this));
|
||||||
|
Event.observe(this.div, "mouseup",
|
||||||
|
this.onmouseup.bindAsEventListener(this));
|
||||||
|
Event.observe(this.div, "click",
|
||||||
|
OpenLayers.Util.safeStopPropagation);
|
||||||
|
Event.observe(this.div, "mouseout",
|
||||||
|
this.onmouseout.bindAsEventListener(this));
|
||||||
|
Event.observe(this.div, "dblclick",
|
||||||
|
OpenLayers.Util.safeStopPropagation);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** When mouse goes down within the popup, make a note of
|
||||||
|
* it locally, and then do not propagate the mousedown
|
||||||
|
* (but do so safely so that user can select text inside)
|
||||||
|
*
|
||||||
|
* @param {Event} evt
|
||||||
|
*/
|
||||||
|
onmousedown: function (evt) {
|
||||||
|
this.mousedown = true;
|
||||||
|
OpenLayers.Util.safeStopPropagation(evt);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** If the drag was started within the popup, then
|
||||||
|
* do not propagate the mousemove (but do so safely
|
||||||
|
* so that user can select text inside)
|
||||||
|
*
|
||||||
|
* @param {Event} evt
|
||||||
|
*/
|
||||||
|
onmousemove: function (evt) {
|
||||||
|
if (this.mousedown) {
|
||||||
|
OpenLayers.Util.safeStopPropagation(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/** When mouse comes up within the popup, after going down
|
||||||
|
* in it, reset the flag, and then (once again) do not
|
||||||
|
* propagate the event, but do so safely so that user can
|
||||||
|
* select text inside
|
||||||
|
*
|
||||||
|
* @param {Event} evt
|
||||||
|
*/
|
||||||
|
onmouseup: function (evt) {
|
||||||
|
if (this.mousedown) {
|
||||||
|
this.mousedown = false;
|
||||||
|
OpenLayers.Util.safeStopPropagation(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/** When mouse goes out of the popup set the flag to false so that
|
||||||
|
* if they let go and then drag back in, we won't be confused.
|
||||||
|
*
|
||||||
|
* @param {Event} evt
|
||||||
|
*
|
||||||
|
* @type Boolean
|
||||||
|
*/
|
||||||
|
onmouseout: function (evt) {
|
||||||
|
this.mousedown = false;
|
||||||
|
},
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Popup"
|
CLASS_NAME: "OpenLayers.Popup"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -516,3 +516,16 @@ OpenLayers.Util.getResolutionFromScale = function (scale, units) {
|
|||||||
* OpenLayers.DOTS_PER_INCH);
|
* OpenLayers.DOTS_PER_INCH);
|
||||||
return resolution;
|
return resolution;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Safely stop the propagation of an event *without* preventing
|
||||||
|
* the default browser action from occurring.
|
||||||
|
*
|
||||||
|
* @param {Event} evt
|
||||||
|
*/
|
||||||
|
OpenLayers.Util.safeStopPropagation = function(evt) {
|
||||||
|
if (evt.stopPropagation) {
|
||||||
|
evt.stopPropagation();
|
||||||
|
}
|
||||||
|
evt.returnValue = false;
|
||||||
|
evt.cancelBubble = true;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user