# HG changeset patch # User hertzhaft # Date 1353873673 -3600 # Node ID 09691152636e442530a16c0ee30fc6df0866f190 # Parent f3e7b847d44b5973e41c7b22e54fbe6522400bf1 steps towards a svg measuring tool diff -r f3e7b847d44b -r 09691152636e webapp/src/main/webapp/jquery/jquery.digilib.svg.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.svg.js Fri Nov 23 18:02:52 2012 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.svg.js Sun Nov 25 21:01:13 2012 +0100 @@ -26,42 +26,106 @@ (function($) { - // plugin object with digilib data + // the digilib object var digilib = null; + // the normal zoom area + var FULL_AREA = null; // the functions made available by digilib - var fn = null; + var fn = { + // dummy function to avoid errors, gets overwritten by buttons plugin + highlightButtons : function () { + console.debug('svg: dummy function - highlightButtons'); + } + }; // affine geometry plugin var geom = null; + // convenience variable, set in init() + var CSS = ''; - var defaults = {}; + var buttons = { + toolbar : { + onclick : "toolbar", + tooltip : "show toolbar", + icon : "showregions.png" + }, + line : { + onclick : "line", + tooltip : "draw measuring line", + icon : "addregion.png" + } + }; + + var defaults = { + // buttonset of this plugin + svgSet : ['toolbar', 'line'], + // choice of colors offered by toolbar + lineColors : ['white', 'red', 'yellow', 'green', 'blue', 'black'], + // default color + lineColor : 'white', + // color while the line is drawn + drawColor : 'green', + // color of selected objects + selectColor : 'red', + // drawing shapes + shapes : ['line', 'polyline', 'rectangle', 'square', 'circle', 'arch', + 'ratio', 'intercolumnium', 'line grid'], + // default shape + shape : 'line', + // measuring unit (index into list) + unit : 1, + // converted unit (index into list) + converted : 2, + // last measured distance + lastDistance : 0, + // last measured angle + lastAngle : 0, + // maximal denominator for mixed fractions + maxDenominator : 20, + // number of decimal places for convert results + maxDecimals : 3, + // show convert result as mixed fraction? + showMixedFraction : false, + // show angle relative to last line? + showRelativeAngle : false, + // show distance numbers? + showDistanceNumbers : true, + // show ratio of rectangle sides? + showRectangleRatios : false, + // draw line ends as small crosses + drawEndPoints : true, + // draw mid points of lines + drawMidPoints : false, + // draw circle centers + drawCenters : false, + // draw rectangles from the diagonal and one point + drawFromDiagonal : false, + // draw circles from center + drawFromCenter : false, + // snap to endpoints + snapEndPoints : false, + // snap to mid points of lines + snapMidPoints : false, + // snap to circle centers + snapCenters : false, + // snap distance (in screen pixels) + snapDistance : 5, + // keep original object when moving/scaling/rotating + keepOriginal : false, + // number of copies when drawing grids + gridCopies : 10 + }; var actions = { - "test" : function(options) { - var onLoadXML = function (xml) { - settings.xml = xml; - settings.$toolBar = setupToolBar(settings); - $digilib.each(function() { - var $elem = $(this); - $elem.data(pluginName, settings); - }); + toolbar : function(data) { + var $toolbar = data.settings.$toolbar; + if ($toolbar) { + return $toolbar.toggle(); }; - var onLoadScalerImg = function () { - var $svgDiv = $('
'); - $('body').append($svgDiv); - // size SVG div like scaler img - var $scalerImg = $digilib.find('img.pic'); - var scalerImgRect = geom.rectangle($scalerImg); - scalerImgRect.adjustDiv($svgDiv); - console.debug('$svgDiv', scalerImgRect); - var $svg = $svgDiv.svg({ - 'onLoad' : drawInitial - }); - settings.$elem = $digilib; - settings.$svgDiv = $svgDiv; - settings.$svg = $svg; - // set SVG data - $svg.data('digilib', data); - $svg.data(pluginName, settings); + $toolbar = setupToolbar(data); + var onLoadXML = function (xml) { + $xml = $(xml); + data.settings.$xml = $xml; + loadToolbarData(data, $toolbar, $xml); }; // fetch the XML measuring unit list $.ajax({ @@ -70,11 +134,108 @@ dataType : "xml", success : onLoadXML }); - data.$img.load(onLoadScalerImg); + // data.$img.load(onLoadScalerImg); return this; + }, + line : function(data) { + // } }; + // setup a div for accessing the main SVG functionality + var setupToolbar = function(data) { + var html = '\ +
\ + \ + =\ + \ + =\ + '); - for (var i = 0; i < settings.shapes.length; i++) { - var name = settings.shapes[i]; - var $opt = $(''); - $shape.append($opt); - } - // console.debug($xml); - var $xml = $(settings.xml); - // unit selects - var $unit1 = $(''); - - $xml.find("section").each(function() { - var $section = $(this); - var name = $section.attr("name"); - // append section name as option - var $opt = $(''); - $unit1.append($opt); - $unit2.append($opt.clone()); - $section.find("unit").each(function() { - var $unit = $(this); - var name = $unit.attr("name"); - var factor = $unit.attr("factor"); - var $opt = $(''); - $opt.data(pluginName, { - 'name' : name, - 'factor' : factor, - 'add' : $unit.attr("add"), - 'subunits' : $unit.attr("subunits") - }); - $unit1.append($opt); - $unit2.append($opt.clone()); - }); - }); - // settings.units = units; - // other elements - var $la1 = $('pixel'); - var $la2 = $('factor'); - var $la3 = $('='); - var $la4 = $('='); - var $px = $('0.0'); - var $factor = $('0.0'); - var $result1 = $(''); - var $result2 = $(''); - var $angle = $('0.0'); - $('body').append($toolBar); - $toolBar.append($shape); - $toolBar.append($la1); - $toolBar.append($px); - $toolBar.append($la2); - $toolBar.append($factor); - $toolBar.append($la3); - $toolBar.append($result1); - $toolBar.append($unit1); - $toolBar.append($la4); - $toolBar.append($result2); - $toolBar.append($unit2); - $toolBar.append($angle); - return $toolBar; - }; - - var drawInitial = function ($svg) { - console.debug('SVG is ready'); - var $svgDiv = $(this); - var rect = geom.rectangle($svgDiv); - $svg.line(0, 0, rect.width, rect.height, - {stroke: 'white', strokeWidth: 2}); - $svg.line(0, rect.height, rect.width, 0, - {stroke: 'red', strokeWidth: 2}); - }; - - // plugin installation called by digilib on plugin object. - var install = function (plugin) { - digilib = plugin; - console.debug('installing digilibSVG plugin. digilib:', digilib); - fn = digilib.fn; - // import geometry classes - geom = fn.geometry; - // add defaults, actions, buttons - $.extend(true, digilib.defaults, defaults); // make deep copy - $.extend(digilib.actions, actions); - // export functions - // fn.test = test; - }; - - // plugin initialization - var init = function (data) { - console.debug('initialising digilibSVG plugin. data:', data); - var $data = $(data); - $data.bind('setup', handleSetup); - }; - - var handleSetup = function (evt) { - console.debug("digilibSVG: handleSetup"); - var data = this; - var settings = data.settings; - }; - - // plugin object with name and init - // shared objects filled by digilib on registration - var plugin = { - name : 'digilibSVG', - install : install, - init : init, - buttons : {}, - actions : {}, - fn : {}, - plugins : {} - }; - - if ($.fn.digilib == null) { - $.error("jquery.digilibSVG must be loaded after jquery.digilib!"); - } else { - $.fn.digilib('plugin', plugin); - } -})(jQuery); diff -r f3e7b847d44b -r 09691152636e webapp/src/main/webapp/jquery/test-svg.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/src/main/webapp/jquery/test-svg.html Sun Nov 25 21:01:13 2012 +0100 @@ -0,0 +1,77 @@ + + + + + + + Digilib local: svg + + + + + + + + + + + + + + + + + + + + + + +
+

If you see this, Digilib doesn't work. The reason could be: Javascript is not activated; there is a bug in the Javascript code; the image server does not respond.

+ +
+ + +