Enables unselecting selected features by clicking outside any feature. This is the default mode of the modify feature control. If you want to use the old mode where a click on a selected feature unselects that feature, set the toggle option to true. If you really want the old mode and not have selected features be unselected when clicking outside any feature, set the clickout option to false. The patch also adds the properties toggleKey and multipleKey to the modify feature control. With these one can temporarily enable the toggle and multiple mode, respectively. See the select-feature.html example to see all this in action. Thanks to pvalsecc and tschaub for the great colloration on this. (closes #1137)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5506 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
</style>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
var map, drawControls, select;
|
||||
var map, drawControls;
|
||||
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
|
||||
function init(){
|
||||
map = new OpenLayers.Map('map');
|
||||
@@ -38,9 +38,14 @@
|
||||
polygon: new OpenLayers.Control.DrawFeature(
|
||||
vectors, OpenLayers.Handler.Polygon
|
||||
),
|
||||
select: new OpenLayers.Control.SelectFeature(vectors),
|
||||
hover: new OpenLayers.Control.SelectFeature(
|
||||
vectors, {hover: true}
|
||||
select: new OpenLayers.Control.SelectFeature(
|
||||
vectors,
|
||||
{
|
||||
clickout: false, toggle: false,
|
||||
multiple: false, hover: false,
|
||||
toggleKey: "ctrlKey", // ctrl key removes from selection
|
||||
multipleKey: "shiftKey" // shift key adds to selection
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
@@ -61,6 +66,18 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
var clickout = document.getElementById("clickout").checked;
|
||||
drawControls.select.clickout = clickout;
|
||||
var hover = document.getElementById("hover").checked;
|
||||
drawControls.select.hover = hover;
|
||||
if(hover && drawControls.select.active) {
|
||||
// turn on/off to clear feature property of handler
|
||||
drawControls.select.deactivate();
|
||||
drawControls.select.activate();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
@@ -94,13 +111,23 @@
|
||||
<li>
|
||||
<input type="radio" name="type" value="select" id="selectToggle"
|
||||
onclick="toggleControl(this);" />
|
||||
<label for="selectToggle">select feature on click</label>
|
||||
<label for="selectToggle">select feature</label>
|
||||
<ul>
|
||||
<li>
|
||||
<input id="clickout" type="checkbox"
|
||||
name="clickout" onchange="update()" />
|
||||
<label for="clickout">click out to unselect features</label>
|
||||
</li>
|
||||
<li>
|
||||
<input id="hover" type="checkbox"
|
||||
name="hover" onchange="update()" />
|
||||
<label for="hover">hover to select features</label>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<input type="radio" name="type" value="hover" id="hoverToggle"
|
||||
onclick="toggleControl(this);" />
|
||||
<label for="hoverToggle">select feature on hover</label>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
<p>Use the shift key to select multiple features. Use the ctrl key to
|
||||
toggle selection on features one at a time. Note: the "clickout" option has no
|
||||
effect when "hover" is selected.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user