directory to deploy when depending on features which use CSS, and make it clear how to override the CSS in OpenLayers, include <link rel> ags in all examples. (Closes #884) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6145 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
135 lines
5.0 KiB
HTML
135 lines
5.0 KiB
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>SelectFeature Control on Layer.Vector</title>
|
|
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
|
|
<style type="text/css">
|
|
#map {
|
|
width: 512px;
|
|
height: 350px;
|
|
border: 1px solid gray;
|
|
}
|
|
#controlToggle li {
|
|
list-style: none;
|
|
}
|
|
</style>
|
|
<script src="../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
var map, drawControls;
|
|
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
|
|
function init(){
|
|
map = new OpenLayers.Map('map');
|
|
var wmsLayer = new OpenLayers.Layer.WMS(
|
|
"OpenLayers WMS",
|
|
"http://labs.metacarta.com/wms/vmap0",
|
|
{layers: 'basic'}
|
|
);
|
|
|
|
var vectors = new OpenLayers.Layer.Vector("Vector Layer");
|
|
map.addLayers([wmsLayer, vectors]);
|
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
|
map.addControl(new OpenLayers.Control.MousePosition());
|
|
|
|
drawControls = {
|
|
point: new OpenLayers.Control.DrawFeature(
|
|
vectors, OpenLayers.Handler.Point
|
|
),
|
|
line: new OpenLayers.Control.DrawFeature(
|
|
vectors, OpenLayers.Handler.Path
|
|
),
|
|
polygon: new OpenLayers.Control.DrawFeature(
|
|
vectors, OpenLayers.Handler.Polygon
|
|
),
|
|
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
|
|
}
|
|
)
|
|
};
|
|
|
|
for(var key in drawControls) {
|
|
map.addControl(drawControls[key]);
|
|
}
|
|
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
|
|
|
|
}
|
|
|
|
function toggleControl(element) {
|
|
for(key in drawControls) {
|
|
var control = drawControls[key];
|
|
if(element.value == key && element.checked) {
|
|
control.activate();
|
|
} else {
|
|
control.deactivate();
|
|
}
|
|
}
|
|
}
|
|
|
|
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()">
|
|
<h1 id="title">OpenLayers Select Feature Example</h1>
|
|
<p id="shortdesc">
|
|
Select a feature on hover or click with the Control.SelectFeature on a
|
|
vector layer.
|
|
</p>
|
|
<div id="map"></div>
|
|
<ul id="controlToggle">
|
|
<li>
|
|
<input type="radio" name="type" value="none" id="noneToggle"
|
|
onclick="toggleControl(this);" checked="checked" />
|
|
<label for="noneToggle">navigate</label>
|
|
</li>
|
|
<li>
|
|
<input type="radio" name="type" value="point" id="pointToggle"
|
|
onclick="toggleControl(this);" />
|
|
<label for="pointToggle">draw point</label>
|
|
</li>
|
|
<li>
|
|
<input type="radio" name="type" value="line" id="lineToggle"
|
|
onclick="toggleControl(this);" />
|
|
<label for="lineToggle">draw line</label>
|
|
</li>
|
|
<li>
|
|
<input type="radio" name="type" value="polygon" id="polygonToggle"
|
|
onclick="toggleControl(this);" />
|
|
<label for="polygonToggle">draw polygon</label>
|
|
</li>
|
|
<li>
|
|
<input type="radio" name="type" value="select" id="selectToggle"
|
|
onclick="toggleControl(this);" />
|
|
<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>
|
|
</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>
|