This commit solves the following problem with the select feature control: if

you create two select feature controls on the same vector layer, one with
hover:false that handles geometry type A only, and the other with hover:true
that handles geometry type B only, then if you click on a geometry of type A
and moves out of that geometry, the second control will unselect it. r=tschaub
(closes #1221)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5975 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2008-02-03 17:20:39 +00:00
parent 3acc19ae3d
commit f9950ec389
2 changed files with 151 additions and 1 deletions

View File

@@ -211,6 +211,7 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
// in feature for the first time
this.triggerCallback(type, 'in', [this.feature]);
}
this.lastFeature = this.feature;
stopEvtPropag = true;
} else {
// not in to a feature
@@ -219,7 +220,6 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
this.triggerCallback(type, 'out', [this.lastFeature]);
}
}
this.lastFeature = this.feature;
} else {
if(previouslyIn || (click && this.lastFeature)) {
this.triggerCallback(type, 'out', [this.lastFeature]);

View File

@@ -0,0 +1,150 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Select Feature Test</title>
<style type="text/css">
body {
font-size: 0.8em;
}
p {
padding-top: 1em;
}
#map {
margin: 1em;
width: 512px;
height: 512px;
}
</style>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, selectControl1, selectControl2;
function init() {
map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}
);
var vectorLayer = new OpenLayers.Layer.Vector("Vector Layer");
var pointFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-50, -45)
);
var polygonFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-50,-50),
new OpenLayers.Geometry.Point(-40,-50),
new OpenLayers.Geometry.Point(-40,-40),
new OpenLayers.Geometry.Point(-50,-50)
])
])
);
vectorLayer.addFeatures([pointFeature, polygonFeature]);
map.addLayers([wmsLayer, vectorLayer]);
selectControl1 = new OpenLayers.Control.SelectFeature(
vectorLayer, {geometryTypes: ['OpenLayers.Geometry.Point']}
);
selectControl2 = new OpenLayers.Control.SelectFeature(
vectorLayer, {
geometryTypes: ['OpenLayers.Geometry.Polygon'],
hover: true
});
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(selectControl1);
map.addControl(selectControl2);
selectControl1.activate();
selectControl2.activate();
map.setCenter(new OpenLayers.LonLat(-45, -45), 4);
}
</script>
</head>
<body onload="init()">
<h1 id="title">Select Feature Test</h1>
<div id="map"></div>
<p>
The map includes two select feature controls. The first one operates on
geometries of type OpenLayers.Geometry.Point only and works on clicks. The
second one operates on geometries of type OpenLayers.Geometry.Polygon and
works on mouseover's. If you select the point geometry by clicking on it,
it shouldn't be unselected when the mouse moves out if it.
</p>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Select Feature Test</title>
<style type="text/css">
body {
font-size: 0.8em;
}
p {
padding-top: 1em;
}
#map {
margin: 1em;
width: 512px;
height: 512px;
}
</style>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, selectControl1, selectControl2;
function init() {
map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}
);
var vectorLayer = new OpenLayers.Layer.Vector("Vector Layer");
var pointFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-50, -45)
);
var polygonFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(-50,-50),
new OpenLayers.Geometry.Point(-40,-50),
new OpenLayers.Geometry.Point(-40,-40),
new OpenLayers.Geometry.Point(-50,-50)
])
])
);
vectorLayer.addFeatures([pointFeature, polygonFeature]);
map.addLayers([wmsLayer, vectorLayer]);
selectControl1 = new OpenLayers.Control.SelectFeature(
vectorLayer, {geometryTypes: ['OpenLayers.Geometry.Point']}
);
selectControl2 = new OpenLayers.Control.SelectFeature(
vectorLayer, {
geometryTypes: ['OpenLayers.Geometry.Polygon'],
hover: true
});
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(selectControl1);
map.addControl(selectControl2);
selectControl1.activate();
selectControl2.activate();
map.setCenter(new OpenLayers.LonLat(-45, -45), 4);
}
</script>
</head>
<body onload="init()">
<h1 id="title">Select Feature Test</h1>
<div id="map"></div>
<p>
The map includes two select feature controls. The first one operates on
geometries of type OpenLayers.Geometry.Point only and works on clicks. The
second one operates on geometries of type OpenLayers.Geometry.Polygon and
works on mouseover's. If you select the point geometry by clicking on it,
it shouldn't be unselected when the mouse moves out if it.
</p>
</body>
</html>