changeset 1337:1e9e86dbaa1e

add dragShape event
author hertzhaft
date Sun, 01 Feb 2015 13:07:36 +0100
parents 907aecf6435f
children 3da1ca0a33d9
files webapp/src/main/webapp/jquery/jquery.digilib.measure.js webapp/src/main/webapp/jquery/jquery.digilib.vector.js
diffstat 2 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.js	Sat Jan 31 23:33:07 2015 +0100
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.js	Sun Feb 01 13:07:36 2015 +0100
@@ -760,6 +760,11 @@
         gridCopies : 10
         };
 
+
+    var _debug_shape = function (msg, shape) {
+        // console.debug('measure: ' + msg, shape.geometry.type, shape.geometry.coordinates);
+        };
+
     var actions = {
         measurebar : function(data) {
             var $measureBar = data.$measureBar;
@@ -774,13 +779,13 @@
             var shape = newShape(data);
             $(data).trigger('createShape', shape);
             digilib.actions.addShape(data, shape, shapeCompleted);
-            console.debug('measure: action drawshape', shape);
+            _debug_shape('action drawshape', shape);
             }
         };
 
     // callback for vector.drawshape
     var shapeCompleted = function(data, shape) {
-        console.debug('measure: shapeCompleted', shape);
+        _debug_shape('shapeCompleted', shape);
         data.measureWidgets.startb.removeClass('dl-drawing');
         if (shape == null || shape.geometry.coordinates == null) {
             return false; // do nothing if no line was produced
@@ -793,14 +798,21 @@
     var onCreateShape = function(event, shape) {
         var data = this;
         data.measureWidgets.startb.addClass('dl-drawing');
-        console.debug('measure: onCreateShape', shape);
+        _debug_shape('onCreateShape', shape);
+    };
+
+    // event handler for dragShape
+    var onDragShape = function(event, shape) {
+        var data = this;
+        updateInfo(data, shape);
+        _debug_shape('onDragShape', shape);
     };
 
     // event handler for changeShape
     var onChangeShape = function(event, shape) {
         var data = this;
         updateInfo(data, shape);
-        console.debug('measure: onChangeShape', data, shape);
+        _debug_shape('onChangeShape', shape);
     };
 
     // event handler for renderShape
@@ -808,11 +820,12 @@
         // event handler for updating shape info
         var info = function(event) {
             updateInfo(data, shape);
+            _debug_shape('onClick', shape);
             };
         var data = this;
         var $elem = shape.$elem;
         $elem.on('click.measure', info);
-        console.debug('measure: onRenderShape', data, shape);
+        _debug_shape('onRenderShape', shape);
         };
 
     // round to 4 decimal places after point
@@ -1105,6 +1118,7 @@
         $data.on('createShape', onCreateShape);
         $data.on('renderShape', onRenderShape);
         $data.on('changeShape', onChangeShape);
+        $data.on('dragShape', onDragShape);
         };
 
     // plugin object with name and init
--- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js	Sat Jan 31 23:33:07 2015 +0100
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js	Sun Feb 01 13:07:36 2015 +0100
@@ -531,11 +531,11 @@
                 pt2 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[1]));
             }
             $document.on("mousemove.dlVertexDrag", dragMove);
-            $document.on("mouseup.dlVertexDrag", dragEnd);            
-            $document.on("dblclick.dlVertexDrag", dragEnd);            
+            $document.on("mouseup.dlVertexDrag", dragEnd);
+            $document.on("dblclick.dlVertexDrag", dragEnd);
             return false;
         };
-        
+
         var dragMove = function (evt) {
             pt = geom.position(evt);
             pt.clipTo(imgRect);
@@ -555,7 +555,7 @@
                     rect = geom.rectangle(pt1, pt);
                 }
                 $shape.attr({'x': rect.x, 'y': rect.y,
-                    'width': rect.width, 'height': rect.height});               
+                    'width': rect.width, 'height': rect.height});
             } else if (shapeType === 'Polygon' || shapeType === 'LineString') {
                 var points = $shape.attr('points');
                 var ps = points.split(' ');
@@ -563,6 +563,13 @@
                 points = ps.join(' ');
                 $shape.attr('points', points);
             }
+            // update shape object and trigger drag event
+            if (shapeType === 'Line' || shapeType === 'Rectangle' ||
+            		shapeType === 'Polygon' || shapeType === 'LineString') {
+                var p = data.imgTrafo.invtransform(pt);
+                shape.geometry.coordinates[vtx] = [p.x, p.y];
+                $(data).trigger('dragShape', shape);
+            }
             return false;
         };
 
@@ -596,7 +603,7 @@
         // return drag start handler
         return dragStart;
     };
-    
+
     /** 
      * define a shape by click and drag.
      *
@@ -656,7 +663,7 @@
 	            		coords.push(coords[vtxidx].slice());
 	            		vtxidx += 1;
 	                    // draw shape
-	                    renderShape(data, shape, layer);            		
+	                    renderShape(data, shape, layer);
 	                    // execute vertex drag handler on next vertex
 	            		getVertexDragHandler(data, shape, vtxidx, vertexDragDone)(evt);
 	            		return false;
@@ -672,7 +679,7 @@
 	            		}
 	            		if (rerender) {
 	            		    unrenderShape(data, shape);
-	            		    renderShape(data, shape, layer);            		            			
+	            		    renderShape(data, shape, layer);
 	            		}
             		} else {
             			console.error("unknown event type!");