# HG changeset patch # User hertzhaft # Date 1462096983 -7200 # Node ID b3d81e4581a74137c66be87727b344a841c41916 # Parent 8c7f1ef5a67fd15c164b5629f5e040d3da23a95f create regions from plain JSON data diff -r 8c7f1ef5a67f -r b3d81e4581a7 webapp/src/main/webapp/jquery/jquery.digilib.regions.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.regions.js Thu Apr 28 19:40:47 2016 +0200 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.regions.js Sun May 01 12:03:03 2016 +0200 @@ -143,8 +143,10 @@ 'userRegionSet' : ['defineregion', 'removeregion', 'removeallregions'], // url param for regions 'rg' : null, - // array with region data + // precalculated array with region data, used by createRegionsFromJS 'regions' : null, + // JSON array with region data (x,y,w,h,title,index), used by createRegionsFromJSON + 'regionsJSON' : null, // function for extracting the sort string (for the region search window) 'regionSortString' : null, // region attributes to copy from HTML @@ -491,6 +493,18 @@ }); }; + // create regions from a JSON array of items (x,y,w,h,title,index) + var createRegionsFromJSON = function (data, items) { + var ww = data.settings.regionWidth; + $.each(items, function (index, item) { + addRegionDiv(data, { + rect: geom.rectangle(item.x, item.y, item.w || ww, item.h || ww), + attributes: {'class' : CSS+"regionJSON "+CSS+"overlay", title: item.title }, + index: item.index || index+1 + }); + }); + }; + // create regions from URL parameters var createRegionsFromURL = function (data) { var userRegions = unpackRegions(data); @@ -593,6 +607,7 @@ }; // show a region on top of the scaler image + // TODO: faster rendering for large numbers of regions? var renderRegion = function (data, $regionDiv, anim) { if (!data.imgTrafo) return; var zoomArea = data.zoomArea; @@ -725,6 +740,10 @@ if (settings.regions) { createRegionsFromJS(data, settings.regions); } + // regions with content are given in a JSON array + if (settings.regionsJSON) { + createRegionsFromJSON(data, settings.regionsJSON); + } // regions with content are given in HTML divs if (settings.processHtmlRegions) { createRegionsFromHTML(data);