# HG changeset patch # User robcast # Date 1390305099 -3600 # Node ID cc1decb4c941d36a6e3cd5839ac457c7096592b6 # Parent 1c26847a2378a1a5010d0546a2ef1f530849278a loading additional (relative coordinate) SVG layers works now. removing more old (svg-related) stuff. diff -r 1c26847a2378 -r cc1decb4c941 webapp/src/main/webapp/jquery/digilib-vector.html --- a/webapp/src/main/webapp/jquery/digilib-vector.html Mon Jan 20 18:38:54 2014 +0100 +++ b/webapp/src/main/webapp/jquery/digilib-vector.html Tue Jan 21 12:51:39 2014 +0100 @@ -54,7 +54,11 @@ }, 'id' : 'myBestRect' }]); - $div.digilib("addVectorLayer", {'projection': 'relative', 'svg': $('#test-squares')[0]}); + $('#test-squares')[0].addEventListener('load', function (evt) { + var layer = {'projection': 'relative', '$elem': $(this), 'svgElem': this.contentDocument.documentElement} + $div.digilib("addVectorLayer", layer); + return false; + }); }); @@ -64,8 +68,8 @@

digilib doesn't work! Please switch on Javascript or notify the server administrator!

+
- diff -r 1c26847a2378 -r cc1decb4c941 webapp/src/main/webapp/jquery/jquery.digilib.vector.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Mon Jan 20 18:38:54 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Tue Jan 21 12:51:39 2014 +0100 @@ -145,20 +145,34 @@ /** * add vector layer. * - * Layer is an object with "projection" and "svg" members. + * Layer is an object with a "projection" member. * projection can be "relative": relative (0..1) coordinates, * "screen": on-screen coordinates (requires re-scaling). - * svg is an (unattached) SVG dom object. + * A SVG layer is specified by the jQuery-HTML element "$elem" and the SVG-element "svgElem". + * + * layer : { + * projection : relative, + * $elem : $(...), + * svgElem : ... + * } * * @param date * @param layer */ addVectorLayer : function (data, layer) { - data.vectorLayers.push(layer); - var $svg = $(layer.svg); - layer.$svg = $svg; - data.$elem.append($svg); - renderLayers(data); + if (layer.projection === 'relative') { + var svg = layer.svgElem; + // set defaults for SVG in relative coordinates + svg.setAttributeNS(null, 'viewBox', '0 0 1 1'); + svg.setAttributeNS(null, 'preserveAspectRatio', 'none'); + var $elem = layer.$elem; + // set defaults for HTML element + $elem.css({'position':'absolute', 'z-index': 9, 'pointer-events':'none'}); + $elem.addClass(data.settings.cssPrefix+'overlay'); + // add layer + data.vectorLayers.push(layer); + renderLayers(data); + } } }; @@ -173,7 +187,6 @@ // add defaults, actions, buttons to the main digilib object $.extend(digilib.defaults, defaults); $.extend(digilib.actions, actions); - //$.extend(digilib.buttons, buttons); }; /** @@ -215,10 +228,17 @@ // assume that the shapes layer is first renderShapes(data); } else if (layer.projection === 'relative') { - // adjust svg element size and position (doesn't work with .adjustDiv()) - layer.$svg.css(data.imgRect.getAsCss()); - // set current viewBox (jQuery lowercases attributes) - layer.$svg[0].setAttribute('viewBox', data.zoomArea.getAsSvg()); + var svg = layer.svgElem; + if (svg != null) { + // set current viewBox (jQuery lowercases attributes) + svg.setAttribute('viewBox', data.zoomArea.getAsSvg()); + } + var $elem = layer.$elem; + if ($elem != null) { + // adjust layer element size and position (doesn't work with .adjustDiv()) + $elem.css(data.imgRect.getAsCss()); + $elem.show(); + } } } }; diff -r 1c26847a2378 -r cc1decb4c941 webapp/src/main/webapp/jquery/svg_old/jquery-test-svg.html --- a/webapp/src/main/webapp/jquery/svg_old/jquery-test-svg.html Mon Jan 20 18:38:54 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ - - - - jquery.digilib.svg.js test - - - - - - - - - - - - - - - - - - - - - - - - -
-

digilib doesn't work! Please switch on Javascript or notify the server administrator!

- -
- - test - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - diff -r 1c26847a2378 -r cc1decb4c941 webapp/src/main/webapp/jquery/svg_old/jquery.digilib.svg.css --- a/webapp/src/main/webapp/jquery/svg_old/jquery.digilib.svg.css Mon Jan 20 18:38:54 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -/* - * CSS style file for jQuery digilib - * - * Martin Raspe, Robert Casties, 26.3.2012 - */ - -#dl_svgdiv { - width: 700px; - height: 200px; - position: absolute; - top: 10px; -} diff -r 1c26847a2378 -r cc1decb4c941 webapp/src/main/webapp/jquery/svg_old/jquery.digilib.svg.js --- a/webapp/src/main/webapp/jquery/svg_old/jquery.digilib.svg.js Mon Jan 20 18:38:54 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,290 +0,0 @@ -/* - * #%L - * digilib SVG plugin - * %% - * Copyright (C) 2012 - 2013 Bibliotheca Hertziana, MPIWG Berlin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - * Authors: Martin Raspe, Robert Casties, 26.3.2012 - */ -/** - * digilib SVG plugin (display a SVG on top if scaler image and zoom/rotate/mirror etc.) -**/ - -/* jslint browser: true, debug: true, forin: true -*/ - -(function($) { - - // the digilib object - var digilib = null; - // the normal zoom area - var FULL_AREA = null; - // the functions made available by digilib - 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 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 = { - toolbar : function(data) { - var $toolbar = data.settings.$toolbar; - if ($toolbar) { - return $toolbar.toggle(); - }; - $toolbar = setupToolbar(data); - var onLoadXML = function (xml) { - $xml = $(xml); - data.settings.$xml = $xml; - loadToolbarData(data, $toolbar, $xml); - }; - // fetch the XML measuring unit list - $.ajax({ - type : "GET", - url : "svg/archimedes.xml", - dataType : "xml", - success : onLoadXML - }); - // data.$img.load(onLoadScalerImg); - return this; - }, - line : function(data) { - // - } - }; - - // setup a div for accessing the main SVG functionality - var setupToolbar = function(data) { - var html = '\ -
\ - \ - =\ - \ - =\ -