1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <title>Modify Feature</title>
4 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
5 <link rel="stylesheet" href="style.css" type="text/css" />
6 <style type="text/css">
17 <script src="../lib/Firebug/firebug.js"></script>
18 <script src="../lib/OpenLayers.js"></script>
19 <script type="text/javascript">
20 var map, vectors, controls;
22 map = new OpenLayers.Map('map');
23 var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
24 "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
25 OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
26 vectors = new OpenLayers.Layer.Vector("Vector Layer");
28 map.addLayers([wms, vectors]);
29 map.addControl(new OpenLayers.Control.LayerSwitcher());
30 map.addControl(new OpenLayers.Control.MousePosition());
32 function report(event) {
33 OpenLayers.Console.log(event.type, event.feature ? event.feature.id : event.components);
36 "beforefeaturemodified": report,
37 "featuremodified": report,
38 "afterfeaturemodified": report,
39 "vertexmodified": report,
40 "sketchmodified": report,
41 "sketchstarted": report,
42 "sketchcomplete": report
45 point: new OpenLayers.Control.DrawFeature(vectors,
46 OpenLayers.Handler.Point),
47 line: new OpenLayers.Control.DrawFeature(vectors,
48 OpenLayers.Handler.Path),
49 polygon: new OpenLayers.Control.DrawFeature(vectors,
50 OpenLayers.Handler.Polygon),
51 regular: new OpenLayers.Control.DrawFeature(vectors,
52 OpenLayers.Handler.RegularPolygon,
53 {handlerOptions: {sides: 5}}),
54 modify: new OpenLayers.Control.ModifyFeature(vectors)
57 for(var key in controls) {
58 map.addControl(controls[key]);
61 map.setCenter(new OpenLayers.LonLat(0, 0), 3);
62 document.getElementById('noneToggle').checked = true;
66 // reset modification mode
67 controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
68 var rotate = document.getElementById("rotate").checked;
70 controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE;
72 var resize = document.getElementById("resize").checked;
74 controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE;
75 var keepAspectRatio = document.getElementById("keepAspectRatio").checked;
76 if (keepAspectRatio) {
77 controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
80 var drag = document.getElementById("drag").checked;
82 controls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG;
85 controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
87 var sides = parseInt(document.getElementById("sides").value);
88 sides = Math.max(3, isNaN(sides) ? 0 : sides);
89 controls.regular.handler.sides = sides;
90 var irregular = document.getElementById("irregular").checked;
91 controls.regular.handler.irregular = irregular;
94 function toggleControl(element) {
95 for(key in controls) {
96 var control = controls[key];
97 if(element.value == key && element.checked) {
100 control.deactivate();
107 <body onload="init()">
108 <h1 id="title">OpenLayers Modify Feature Example</h1>
109 <div id="shortdesc">A demonstration of the ModifyFeature control for editing vector features.</div>
110 <div id="map" class="smallmap"></div>
112 <ul id="controlToggle">
114 <input type="radio" name="type" value="none" id="noneToggle"
115 onclick="toggleControl(this);" checked="checked" />
116 <label for="noneToggle">navigate</label>
119 <input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" />
120 <label for="pointToggle">draw point</label>
123 <input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" />
124 <label for="lineToggle">draw line</label>
127 <input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
128 <label for="polygonToggle">draw polygon</label>
131 <input type="radio" name="type" value="regular" id="regularToggle" onclick="toggleControl(this);" />
132 <label for="regularToggle">draw regular polygon</label>
133 <label for="sides"> - sides</label>
134 <input id="sides" type="text" size="2" maxlength="2"
135 name="sides" value="5" onchange="update()" />
138 <input id="irregular" type="checkbox"
139 name="irregular" onchange="update()" />
140 <label for="irregular">irregular</label>
145 <input type="radio" name="type" value="modify" id="modifyToggle"
146 onclick="toggleControl(this);" />
147 <label for="modifyToggle">modify feature</label>
150 <input id="rotate" type="checkbox"
151 name="rotate" onchange="update()" />
152 <label for="rotate">allow rotation</label>
155 <input id="resize" type="checkbox"
156 name="resize" onchange="update()" />
157 <label for="resize">allow resizing</label>
158 (<input id="keepAspectRatio" type="checkbox"
159 name="keepAspectRatio" onchange="update()" checked="checked" />
160 <label for="keepAspectRatio">keep aspect ratio</label>)
163 <input id="drag" type="checkbox"
164 name="drag" onchange="update()" />
165 <label for="drag">allow dragging</label>