[OpenLayers-Commits] r12044 - in sandbox/tschaub/editing: examples
lib/OpenLayers/Control
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Sun Jun 5 19:46:33 EDT 2011
Author: tschaub
Date: 2011-06-05 16:46:32 -0700 (Sun, 05 Jun 2011)
New Revision: 12044
Added:
sandbox/tschaub/editing/examples/draw-undo-redo.html
sandbox/tschaub/editing/examples/draw-undo-redo.js
Modified:
sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
Log:
Add undo/redo example.
Added: sandbox/tschaub/editing/examples/draw-undo-redo.html
===================================================================
--- sandbox/tschaub/editing/examples/draw-undo-redo.html (rev 0)
+++ sandbox/tschaub/editing/examples/draw-undo-redo.html 2011-06-05 23:46:32 UTC (rev 12044)
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>OpenLayers Undo/Redo Drawing Methods</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0;">
+ <meta name="apple-mobile-web-app-capable" content="yes">
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
+ <link rel="stylesheet" href="style.css" type="text/css">
+ <script src="../lib/OpenLayers.js"></script>
+ </head>
+ <body>
+ <h1 id="title">Undo/Redo Drawing</h1>
+ <p id="shortdesc">
+ Demonstrates the use of undo & redo methods while drawing.
+ </p>
+ <div id="map" class="smallmap"></div>
+
+ <div id="docs">
+ <p>
+ Use <code>Ctrl-Z</code> or<code> ⌘-Z</code> to undo while drawing.
+ Use <code>Ctrl-Y</code> or<code> ⌘-Y</code> to redo what you have
+ undone. Use <code>Esc</code> to cancel the current sketch.
+ <p>
+ The <code>control.undo</code> method works first on any current
+ sketch, removing the most recently added point. To fully erase
+ a sketch, cancel drawing. After removing all but two points
+ from the current sketch (in the case of a line) the undo method
+ will begin removing previously drawn features.
+ </p><p>
+ The <code>control.redo</code> method adds back items that were
+ removed from an undo.
+ </p><p>
+ View the <a href="draw-undo-redo.js" target="_blank">draw-undo-redo.js</a>
+ source to see how this is done.
+ </p>
+ </div>
+
+ <script src="draw-undo-redo.js"></script>
+ </body>
+</html>
Added: sandbox/tschaub/editing/examples/draw-undo-redo.js
===================================================================
--- sandbox/tschaub/editing/examples/draw-undo-redo.js (rev 0)
+++ sandbox/tschaub/editing/examples/draw-undo-redo.js 2011-06-05 23:46:32 UTC (rev 12044)
@@ -0,0 +1,52 @@
+var map = new OpenLayers.Map({
+ div: "map",
+ layers: [
+ new OpenLayers.Layer.WMS(
+ "Global Imagery",
+ "http://maps.opengeo.org/geowebcache/service/wms",
+ {layers: "bluemarble"},
+ {tileOrigin: new OpenLayers.LonLat(-180, -90)}
+ ),
+ new OpenLayers.Layer.Vector()
+ ],
+ center: new OpenLayers.LonLat(0, 0),
+ zoom: 1
+});
+
+var draw = new OpenLayers.Control.DrawFeature(
+ map.layers[1], OpenLayers.Handler.Path
+);
+map.addControl(draw);
+draw.activate();
+
+OpenLayers.Event.observe(document, "keypress", function(evt) {
+ var code = evt.charCode || evt.keyCode;
+ if (code === 90) {
+ // z
+ if ("metaKey" in evt) {
+ if (evt.metaKey) {
+ draw.undo();
+ evt.preventDefault();
+ }
+ } else if (evt.ctrlKey) {
+ draw.undo();
+ evt.preventDefault();
+ }
+ }
+ if (code === 89) {
+ // y
+ if ("metaKey" in evt) {
+ if (evt.metaKey) {
+ draw.redo();
+ evt.preventDefault();
+ }
+ } else if (evt.ctrlKey) {
+ draw.redo();
+ evt.preventDefault();
+ }
+ }
+ if (code === 27) {
+ // esc
+ draw.cancel();
+ }
+});
\ No newline at end of file
Modified: sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js 2011-06-05 23:27:04 UTC (rev 12043)
+++ sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js 2011-06-05 23:46:32 UTC (rev 12044)
@@ -82,6 +82,7 @@
this.layer.events.triggerEvent(
"sketchmodified", {vertex: vertex, feature: feature}
);
+ delete this.redoStack;
},
create: function(vertex, feature) {
this.layer.events.triggerEvent(
More information about the Commits
mailing list