Mercurial > hg > digilib
changeset 1310:425ce8f971aa rc_create_polys
less rendering calls.
Task-Url: https://it-dev.mpiwg-berlin.mpg.de/tracs/digilib/ticket/41
author | robcast |
---|---|
date | Thu, 22 Jan 2015 16:12:03 +0100 |
parents | 75db880828a1 |
children | 85906c9cd08b |
files | webapp/src/main/webapp/jquery/digilib-ann.html webapp/src/main/webapp/jquery/jquery.digilib.annotator.js webapp/src/main/webapp/jquery/jquery.digilib.vector.js |
diffstat | 3 files changed, 30 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/digilib-ann.html Thu Jan 22 12:59:59 2015 +0100 +++ b/webapp/src/main/webapp/jquery/digilib-ann.html Thu Jan 22 16:12:03 2015 +0100 @@ -43,7 +43,8 @@ // URL of authentication token server 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token/getLoginToken', // list of Annotator plugins - 'annotatorPlugins' : ['Auth', 'Permissions', 'Store', 'Markdown', 'DigilibIntegrator'] + 'annotatorPlugins' : ['Auth', 'Permissions', 'Markdown', 'DigilibIntegrator', 'Store'] + //'annotatorPlugins' : ['Auth', 'Permissions', 'Markdown', 'DigilibIntegrator', 'Store'] //'annotatorPlugins' : ['Store', 'Markdown', 'DigilibIntegrator'] }; var $div = $('div#digilib');
--- a/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Thu Jan 22 12:59:59 2015 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.annotator.js Thu Jan 22 16:12:03 2015 +0100 @@ -289,7 +289,7 @@ * Render all annotations on the image */ var renderAnnotations = function (data) { - if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null) + if (data.annotations == null || data.annotator == null) return; var annotations = data.annotations; var cssPrefix = data.settings.cssPrefix; @@ -301,13 +301,25 @@ for (var i = 0; i < annotations.length; ++i) { shapes.push(createVectorShape(data, annotations[i])); } + annotationLayer.shapes = shapes; // render vector layer - annotationLayer.shapes = shapes; - annotationLayer.renderFn(data, annotationLayer); + if (data.$img != null && data.imgTrafo != null) { + annotationLayer.renderFn(data, annotationLayer); + } + }; + + /** + * Layer render function for vector plugin. + */ + var layerRenderFn = function (data, layer) { + // default shape render fn creates SVG elements + fn.vectorDefaultRenderFn(data, layer); // attach annotations to shapes + var annotations = data.annotations; for (var i = 0; i < annotations.length; ++i) { - attachAnnotation(data, annotations[i], annotationLayer); + attachAnnotation(data, annotations[i], layer); } + layer.dirty = false; }; /** @@ -317,7 +329,7 @@ * @returns vector shape object */ var createVectorShape = function (data, annot) { - if (annot == null || annot.annotation == null || data.$img == null || data.imgTrafo == null) + if (annot == null || annot.annotation == null) return; if (!data.settings.isAnnotationsVisible) return; var cssPrefix = data.settings.cssPrefix; @@ -440,6 +452,7 @@ }; // add to list data.annotations.push(ann); + annotationLayer.dirty = true; }; }; @@ -449,6 +462,7 @@ var getAnnotationDeleted = function(data) { return function (annotation) { // remove annotation mark + console.debug("delete annotation."); var annots = data.annotations; for (var i = 0; i < annots.length; ++i) { var annot = annots[i]; @@ -663,14 +677,14 @@ // create annotation shapes layer annotationLayer = { 'projection': 'screen', - 'renderFn': fn.vectorDefaultRenderFn, + 'renderFn': layerRenderFn, 'shapes': [] }; digilib.actions.addVectorLayer(data, annotationLayer); // install event handler - $data.bind('setup', handleSetup); - $data.bind('update', handleUpdate); - $data.on('annotationClick', handleAnnotationClick); + $data.on('setup', handleSetup); + $data.on('update', handleUpdate); + //$data.on('annotationClick', handleAnnotationClick); }; /** @@ -720,6 +734,7 @@ data.annotator = annotator; annotator.subscribe("annotationsLoaded", function () { console.debug("annotations loaded!"); + renderAnnotations(data); }); // save annotation token in cookie var auth = annotator.plugins.Auth; @@ -738,7 +753,9 @@ console.debug("annotations: handleUpdate"); var data = this; // TODO: do not render too often - renderAnnotations(data); + if (annotationLayer.dirty) { + renderAnnotations(data); + } }; // plugin object with name and init
--- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Thu Jan 22 12:59:59 2015 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Thu Jan 22 16:12:03 2015 +0100 @@ -248,7 +248,7 @@ var renderLayers = function(data) { if (data.imgRect == null) return; - for ( var i in data.vectorLayers) { + for (var i in data.vectorLayers) { var layer = data.vectorLayers[i]; if (layer.projection === 'screen') { // screen layers have render function