Commit 3508e165 authored by hertzhaft's avatar hertzhaft

add dragShape event

parent 7771c420
...@@ -760,6 +760,11 @@ ...@@ -760,6 +760,11 @@
gridCopies : 10 gridCopies : 10
}; };
var _debug_shape = function (msg, shape) {
// console.debug('measure: ' + msg, shape.geometry.type, shape.geometry.coordinates);
};
var actions = { var actions = {
measurebar : function(data) { measurebar : function(data) {
var $measureBar = data.$measureBar; var $measureBar = data.$measureBar;
...@@ -774,13 +779,13 @@ ...@@ -774,13 +779,13 @@
var shape = newShape(data); var shape = newShape(data);
$(data).trigger('createShape', shape); $(data).trigger('createShape', shape);
digilib.actions.addShape(data, shape, shapeCompleted); digilib.actions.addShape(data, shape, shapeCompleted);
console.debug('measure: action drawshape', shape); _debug_shape('action drawshape', shape);
} }
}; };
// callback for vector.drawshape // callback for vector.drawshape
var shapeCompleted = function(data, shape) { var shapeCompleted = function(data, shape) {
console.debug('measure: shapeCompleted', shape); _debug_shape('shapeCompleted', shape);
data.measureWidgets.startb.removeClass('dl-drawing'); data.measureWidgets.startb.removeClass('dl-drawing');
if (shape == null || shape.geometry.coordinates == null) { if (shape == null || shape.geometry.coordinates == null) {
return false; // do nothing if no line was produced return false; // do nothing if no line was produced
...@@ -793,14 +798,21 @@ ...@@ -793,14 +798,21 @@
var onCreateShape = function(event, shape) { var onCreateShape = function(event, shape) {
var data = this; var data = this;
data.measureWidgets.startb.addClass('dl-drawing'); 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 // event handler for changeShape
var onChangeShape = function(event, shape) { var onChangeShape = function(event, shape) {
var data = this; var data = this;
updateInfo(data, shape); updateInfo(data, shape);
console.debug('measure: onChangeShape', data, shape); _debug_shape('onChangeShape', shape);
}; };
// event handler for renderShape // event handler for renderShape
...@@ -808,11 +820,12 @@ ...@@ -808,11 +820,12 @@
// event handler for updating shape info // event handler for updating shape info
var info = function(event) { var info = function(event) {
updateInfo(data, shape); updateInfo(data, shape);
_debug_shape('onClick', shape);
}; };
var data = this; var data = this;
var $elem = shape.$elem; var $elem = shape.$elem;
$elem.on('click.measure', info); $elem.on('click.measure', info);
console.debug('measure: onRenderShape', data, shape); _debug_shape('onRenderShape', shape);
}; };
// round to 4 decimal places after point // round to 4 decimal places after point
...@@ -1105,6 +1118,7 @@ ...@@ -1105,6 +1118,7 @@
$data.on('createShape', onCreateShape); $data.on('createShape', onCreateShape);
$data.on('renderShape', onRenderShape); $data.on('renderShape', onRenderShape);
$data.on('changeShape', onChangeShape); $data.on('changeShape', onChangeShape);
$data.on('dragShape', onDragShape);
}; };
// plugin object with name and init // plugin object with name and init
......
...@@ -531,11 +531,11 @@ ...@@ -531,11 +531,11 @@
pt2 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[1])); pt2 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[1]));
} }
$document.on("mousemove.dlVertexDrag", dragMove); $document.on("mousemove.dlVertexDrag", dragMove);
$document.on("mouseup.dlVertexDrag", dragEnd); $document.on("mouseup.dlVertexDrag", dragEnd);
$document.on("dblclick.dlVertexDrag", dragEnd); $document.on("dblclick.dlVertexDrag", dragEnd);
return false; return false;
}; };
var dragMove = function (evt) { var dragMove = function (evt) {
pt = geom.position(evt); pt = geom.position(evt);
pt.clipTo(imgRect); pt.clipTo(imgRect);
...@@ -555,7 +555,7 @@ ...@@ -555,7 +555,7 @@
rect = geom.rectangle(pt1, pt); rect = geom.rectangle(pt1, pt);
} }
$shape.attr({'x': rect.x, 'y': rect.y, $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') { } else if (shapeType === 'Polygon' || shapeType === 'LineString') {
var points = $shape.attr('points'); var points = $shape.attr('points');
var ps = points.split(' '); var ps = points.split(' ');
...@@ -563,6 +563,13 @@ ...@@ -563,6 +563,13 @@
points = ps.join(' '); points = ps.join(' ');
$shape.attr('points', points); $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; return false;
}; };
...@@ -596,7 +603,7 @@ ...@@ -596,7 +603,7 @@
// return drag start handler // return drag start handler
return dragStart; return dragStart;
}; };
/** /**
* define a shape by click and drag. * define a shape by click and drag.
* *
...@@ -656,7 +663,7 @@ ...@@ -656,7 +663,7 @@
coords.push(coords[vtxidx].slice()); coords.push(coords[vtxidx].slice());
vtxidx += 1; vtxidx += 1;
// draw shape // draw shape
renderShape(data, shape, layer); renderShape(data, shape, layer);
// execute vertex drag handler on next vertex // execute vertex drag handler on next vertex
getVertexDragHandler(data, shape, vtxidx, vertexDragDone)(evt); getVertexDragHandler(data, shape, vtxidx, vertexDragDone)(evt);
return false; return false;
...@@ -672,7 +679,7 @@ ...@@ -672,7 +679,7 @@
} }
if (rerender) { if (rerender) {
unrenderShape(data, shape); unrenderShape(data, shape);
renderShape(data, shape, layer); renderShape(data, shape, layer);
} }
} else { } else {
console.error("unknown event type!"); console.error("unknown event type!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment