| 1 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 2 |
<head> |
|---|
| 3 |
<title>Draw Feature Example</title> |
|---|
| 4 |
|
|---|
| 5 |
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" /> |
|---|
| 6 |
<link rel="stylesheet" href="style.css" type="text/css" /> |
|---|
| 7 |
<style type="text/css"> |
|---|
| 8 |
#controlToggle li { |
|---|
| 9 |
list-style: none; |
|---|
| 10 |
} |
|---|
| 11 |
p { |
|---|
| 12 |
width: 512px; |
|---|
| 13 |
} |
|---|
| 14 |
</style> |
|---|
| 15 |
<script src="../lib/OpenLayers.js"></script> |
|---|
| 16 |
<script type="text/javascript"> |
|---|
| 17 |
var map, drawControls; |
|---|
| 18 |
OpenLayers.Util.onImageLoadErrorColor = "transparent"; |
|---|
| 19 |
function init(){ |
|---|
| 20 |
map = new OpenLayers.Map('map'); |
|---|
| 21 |
|
|---|
| 22 |
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", |
|---|
| 23 |
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}); |
|---|
| 24 |
|
|---|
| 25 |
var pointLayer = new OpenLayers.Layer.Vector("Point Layer"); |
|---|
| 26 |
var lineLayer = new OpenLayers.Layer.Vector("Line Layer"); |
|---|
| 27 |
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer"); |
|---|
| 28 |
|
|---|
| 29 |
map.addLayers([wmsLayer, pointLayer, lineLayer, polygonLayer]); |
|---|
| 30 |
map.addControl(new OpenLayers.Control.LayerSwitcher()); |
|---|
| 31 |
map.addControl(new OpenLayers.Control.MousePosition()); |
|---|
| 32 |
|
|---|
| 33 |
var options = {handlerOptions: {freehand: true}}; |
|---|
| 34 |
drawControls = { |
|---|
| 35 |
point: new OpenLayers.Control.DrawFeature(pointLayer, |
|---|
| 36 |
OpenLayers.Handler.Point), |
|---|
| 37 |
line: new OpenLayers.Control.DrawFeature(lineLayer, |
|---|
| 38 |
OpenLayers.Handler.Path, options), |
|---|
| 39 |
polygon: new OpenLayers.Control.DrawFeature(polygonLayer, |
|---|
| 40 |
OpenLayers.Handler.Polygon, options) |
|---|
| 41 |
}; |
|---|
| 42 |
|
|---|
| 43 |
for(var key in drawControls) { |
|---|
| 44 |
map.addControl(drawControls[key]); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
map.setCenter(new OpenLayers.LonLat(0, 0), 3); |
|---|
| 48 |
|
|---|
| 49 |
document.getElementById('noneToggle').checked = true; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
function toggleControl(element) { |
|---|
| 53 |
for(key in drawControls) { |
|---|
| 54 |
var control = drawControls[key]; |
|---|
| 55 |
if(element.value == key && element.checked) { |
|---|
| 56 |
control.activate(); |
|---|
| 57 |
} else { |
|---|
| 58 |
control.deactivate(); |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
</script> |
|---|
| 63 |
</head> |
|---|
| 64 |
<body onload="init()"> |
|---|
| 65 |
<h1 id="title">OpenLayers Draw Feature Example</h1> |
|---|
| 66 |
|
|---|
| 67 |
<div id="tags"></div> |
|---|
| 68 |
|
|---|
| 69 |
<p id="shortdesc"> |
|---|
| 70 |
Demonstrate on-screen digitizing tools for point, line, and polygon creation. |
|---|
| 71 |
</p> |
|---|
| 72 |
|
|---|
| 73 |
<div id="map" class="smallmap"></div> |
|---|
| 74 |
|
|---|
| 75 |
<ul id="controlToggle"> |
|---|
| 76 |
<li> |
|---|
| 77 |
<input type="radio" name="type" value="none" id="noneToggle" |
|---|
| 78 |
onclick="toggleControl(this);" checked="checked" /> |
|---|
| 79 |
<label for="noneToggle">navigate</label> |
|---|
| 80 |
</li> |
|---|
| 81 |
<li> |
|---|
| 82 |
<input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" /> |
|---|
| 83 |
<label for="pointToggle">draw point</label> |
|---|
| 84 |
</li> |
|---|
| 85 |
<li> |
|---|
| 86 |
<input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" /> |
|---|
| 87 |
<label for="lineToggle">draw line</label> |
|---|
| 88 |
</li> |
|---|
| 89 |
<li> |
|---|
| 90 |
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" /> |
|---|
| 91 |
<label for="polygonToggle">draw polygon</label> |
|---|
| 92 |
</li> |
|---|
| 93 |
</ul> |
|---|
| 94 |
|
|---|
| 95 |
<div id="docs"> |
|---|
| 96 |
<p>Feature digitizing is in freehand mode by default. In freehand mode, the mouse is treated as a pen. |
|---|
| 97 |
Drawing begins on mouse down, continues with every mouse move, and ends with mouse up.</p> |
|---|
| 98 |
<p>To turn freehand mode off, hold down the shift key while digitizing. With freehand mode off, one |
|---|
| 99 |
vertex is added with each click and double-clicks finish drawing. Freehand mode can be toggled on and off |
|---|
| 100 |
at any time while drawing.</p> |
|---|
| 101 |
</div> |
|---|
| 102 |
</body> |
|---|
| 103 |
</html> |
|---|