Commit 3508e165 authored by hertzhaft's avatar hertzhaft

add dragShape event

parent 7771c420
......@@ -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
......
......@@ -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!");
......
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