Mercurial > hg > digilib
changeset 1252:d059d9a8a401
measuring with rectified distances
author | hertzhaft |
---|---|
date | Fri, 17 Jan 2014 12:45:56 +0100 |
parents | 0bcc1cd62fc6 |
children | 4d1a50cd41c1 |
files | webapp/src/main/webapp/jquery/jquery.digilib.geometry.js webapp/src/main/webapp/jquery/jquery.digilib.js webapp/src/main/webapp/jquery/jquery.digilib.measure.css webapp/src/main/webapp/jquery/jquery.digilib.measure.js |
diffstat | 4 files changed, 60 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Fri Jan 17 10:33:51 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Fri Jan 17 12:45:56 2014 +0100 @@ -84,6 +84,11 @@ x : pos.left, y : pos.top }; + } else if ($.isArray(x)) { + that = { + x : x[0], + y : x[1] + }; } else { if (x.x != null) { // position object @@ -105,7 +110,8 @@ x : parseFloat(x), y : parseFloat(y) }; - } + }; + that.equals = function(other) { return (this.x === other.x && this.y === other.y); };
--- a/webapp/src/main/webapp/jquery/jquery.digilib.js Fri Jan 17 10:33:51 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.js Fri Jan 17 12:45:56 2014 +0100 @@ -1025,6 +1025,18 @@ }; /** + * returns the (unzoomed) aspect ratio of the current scaler image + */ + var getImgAspectRatio = function (data) { + var za = data.zoomArea; + var scalerSize = data.imgRect.getSize(); + scalerSize.width /= za.width; + scalerSize.height /= za.height; + var aspect = scalerSize.getAspect(); + return aspect; + }; + + /** * creates HTML structure for digilib in elem */ var setupScalerDiv = function (data) { @@ -1608,6 +1620,10 @@ dist['o_size'] = opd / data.imgInfo.dpi_x * 0.0254; } } + var ar = getImgAspectRatio(data); + p1.x *= ar; + p2.x *= ar; + dist['rectified'] = p1.distance(p2); } return dist; }; @@ -1789,6 +1805,7 @@ isFullArea : isFullArea, isNumber : isNumber, getFullscreenRect : getFullscreenRect, + getImgAspectRatio : getImgAspectRatio, getDistance : getDistance, getBorderWidth : getBorderWidth, cropFloat : cropFloat,
--- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.css Fri Jan 17 10:33:51 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.css Fri Jan 17 12:45:56 2014 +0100 @@ -10,6 +10,7 @@ background-color: silver; padding: 5px; position: absolute; + z-index: 20; } option.dl-units {
--- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Fri Jan 17 10:33:51 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Fri Jan 17 12:45:56 2014 +0100 @@ -771,13 +771,39 @@ }, drawshape : function(data) { var shape = currentShape(data); - digilib.actions.addShape(data, shape, onCompleteShape); + digilib.actions.addShape(data, shape, onCompleteShape); + console.debug('action: drawshape', shape); - } + } + + }; + + // callback for vector.drawshape var onCompleteShape = function(data, shape) { - console.debug('onCompleteShape', shape); + console.debug('onCompleteShape', shape); + if (shape == null) { + return false; // do nothing if no line was produced + }; + var dist = rectifiedDist(data, shape); + setMeasuredDist(data, dist); + return false; + }; + + // calculate a rectified distance from a shape with digilib coords + var rectifiedDist = function(data, shape) { + var coords = shape.geometry.coordinates; + var p0 = geom.position(coords[0]); + var p1 = geom.position(coords[1]); + var dist = fn.getDistance(data, p0, p1); + return dist.rectified; + }; + + var setMeasuredDist = function(data, dist) { + var $view = data.$toolbar.find('#measure-pixel'); + var str = fn.cropFloatStr(dist); + $view.text(str); }; var currentShape = function(data) { @@ -790,7 +816,8 @@ 'properties' : { 'stroke' : stroke } - }; + }; + return item; }; @@ -902,8 +929,10 @@ // event handler var handleUpdate = function (evt) { - console.debug("measure: handleUpdate"); - // var data = this; + var data = this; + var ar = fn.getImgAspectRatio(data); + data.settings.imgAspectRatio = ar; + console.debug("measure: handleUpdate. aspectratio:", ar); // var settings = data.settings; };