changeset 1582:14a6d8a8a307

vector plugin: make a shape editable
author hertzhaft
date Wed, 30 Nov 2016 23:21:09 +0100
parents 02446ff6948b
children a07a557b6e39
files webapp/src/main/webapp/jquery/jquery.digilib.vector.js
diffstat 1 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js	Sun Nov 13 18:52:47 2016 +0100
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js	Wed Nov 30 23:21:09 2016 +0100
@@ -217,8 +217,9 @@
             svgElement: svgElement,
             svgAttr: svgAttr,
             createScreenCoords: createScreenCoords,
-            editShapeBegin: addEditHandles,
-            editShapeEnd: removeEditHandles,
+            startEditShape: startEditShape,
+            undoEditShape: undoEditShape,
+            finishEditShape: finishEditShape,
             redrawShape: redrawShape
             });
     };
@@ -602,6 +603,40 @@
     	};
 
     /**
+     * make shape editable, add handles and events
+     * 
+     * @param data
+     * @param shape
+     */
+    var startEditShape = function (data, shape) {
+        shape.properties.editable = true;
+        shape.savecoords = shape.geometry.coordinates.slice(0); // clone coords
+        redrawShape(data, shape);
+        };
+
+    /**
+     * end editing shape
+     * 
+     * @param data
+     * @param shape
+     */
+    var finishEditShape = function (data, shape) {
+        shape.properties.editable = false;
+        redrawShape(data, shape);
+        };
+
+    /**
+     * restore edited shape to previous state
+     * 
+     * @param data
+     * @param shape
+     */
+    var undoEditShape = function (data, shape) {
+        shape.geometry.coordinates = shape.savecoords;
+        finishEditShape(data, shape);
+    	 };
+
+    /**
      * calculate screen positions from coordinates for a shape.
      * 
      * @param data