Introduction

The IIIF viewer Mirador has a search feature that can highlight search results for manifests that support the IIIF Search API. However, there are cases where you want to highlight arbitrary regions even for manifests that do not support the Search API.

This article introduces a method for achieving highlight display based on annotation information from external data sources, using Mirador’s internal API.

Demo

Use Cases

  • Highlighting text regions extracted by a custom OCR system
  • Displaying regions of objects detected by machine learning
  • Visualizing annotations stored in an external database
  • Displaying search results for IIIF servers that do not support the Search API

Implementation

Basic Mechanism

Mirador uses Redux internally, and search results can be registered through the receiveSearch action. By passing JSON in IIIF Search API format to this action, you can display highlights from arbitrary data sources.

Required Information

The following three pieces of information are needed to display highlights:

  1. Canvas URI - The URI of the page where the highlight will be displayed
  2. Coordinates (xywh) - The position and size of the highlight region (x, y, width, height)
  3. Text - The text associated with the highlight (displayed in the search panel)

Sample Code

The following is a sample that highlights the opening passage “いつれの御時にか…” from The Tale of Genji in the National Diet Library Digital Collections.

<<<<!hh/b//Dte<<<<ho<<<bhOmammts/eddss/otCldeeitb#sayiccc}c}f}lc}sdmT>tttyomtd>vrro;o)ueo)cylYlaalldiy>iinmch]nislw}w}w};nc}c}vcc)i}tniccci};r>>Paeeyrlippsaai,Msdeai]i,o,co;o)ioo;fsfooofiEncn>>aedtttnng{}it:lnnimct,naaasretn'''w}r}ncp;ennic)vhtnnnhuapghaM{d>=>ivh,regddaahdlllikniIs@@@i,e)soowcssd(o;ii(sss(indth=amio"scfalxtam'cuo:nnuollldsaoItcitt'ts''mr}o)tnseottsn'scseguhtttmgsd>t"rermrmroesiyedimtawivmwoooepbnIodyh@oo@@oe,n,tirm=esweaewhniahuHmjs=aa-icnsIgwxoriegs'fab:wwwBalFsn'pittuitts'c:aet.pss>atianaelsgsmmnlbilae"drvr=ftdhhtrarde:wesnFCMaceaet:enyardyio@hdnisaternrvrriuhtaaiisg>"tvogia"iU:t::daT:isIa{ulareddSae':plc'pvutacdtotnaascsdcac.gblannfgch>=iriedhgrsodh[ntdiloxOC:derxc:e:e:earyraA:noitrtheohshshsitiiehrl"enwotl':''roe'{dI:llsipoHacta{'s'tcpsnc:roecaCawCIRttcgeffstiiUwC:ert=:h3VrmjodNsemenfirh'n':h:c:iee:vt'enhtor-odeoArheetAbgTpur-pt[0i-eaw:cac:intagcR:vsiao:'ais'.W=Cemc1msrdit=ssdehFos0vs{'t9ev:'-ovrz:rlhheac'ghnn:hsoerdio.ph'p+pedbAtt&d(t-rt;{i:hp5wi,1cniefeosls's:shivo:{iInaiinvmcaA,ao.eedms&e)s8toe/ts,ee''ofgea:tleiAphIAclgaa'gdrgsdiponcnndddi=d;(""mpww/t:6rwl,nianlrP,gPotdn:ihs:'ch=chpoeamitisi=er=!m>aieup/9eifgt:sfuahIntnLglIAsnl+htawwnpoises=damm=icHddrns/4=rgi.ieaentsp+oahidnctiM''tIeianonepm)dsaaroidt"p:d,'hgcot,l,ese:tytgn::g'i,,cdronWnWaafiotnntangih>k/l9M,t.anrsl(/aesh+opCh#rh.niiirtarrraiirdthn:<g/.7i'mnPue:v=/tr.ttaotxa(sWon=ncclaeVtffuoelg/.dn,r,avoe,iisi'lsain.ydatinddhhsdtieeeerni:1dcld2anas,{e{ieo,e./tnttwodonWoMo'(eoue.ss;Vtg0io.l0disiwiannmhiteehrdrdiwiw,s;rrwmtti=h00vmn.5ofItefrLgaioinx=.AeonIrIeVneas.e"t;%>/dg1redir.citpgnntt'ac.wddadai;rn[iww;mlo'.s,o,ihsh(h'gA,dtgIo)d,re.icseiS}i..,vtno't,(l,'s+diedwocwsfoFrdahrgjiU:c,'hi,TCots{rhetene,tmeaoperaa,igehonS=[.Arosfthpid./wl'npghxim)tirc.rticc=lgojae,fvihttgp;aOdetsesghodehrppraa/l'hatb]cit..ine<t@/i(rssi,lnej.eoogmnfv/:4a/{-Iegii(ecinreagiit.pirdah+go)cov)etngci10iii,rthn;tne;.S{i&.et0./igc,itW.tSst}f&c-l00ifhhhn.ikeeua;eawev-i/ti/idxnenabtsmni>hai3'g1neydytrsetavd;lf4,h/dxwoscc(Unatp/3lce,hw(=hr)rish}h37iox,(s=(i;lfI,a46gn)'t=b]ed.38'htwae;s,i176,te=it'(tn56/sx>nes(.ci/8c)td.e)jotd6a.(ocasnii/n{j{wor=ofasmvs-mc>niltaao1ph)g-/nsn'a'{.smi/',n{hcif2,iiare2{oglas'nhedt,Wl=o.ii1rjng..sdh0moot"inws>n's).,);j.sf"i>n<d/(script>

Code Explanation

1. Configuration Parameters

c}o;nmch]saai,tnng{}ivh,cfalxtoesiyensIgwxftdhhtiU:t::grsl':''=:h3t[0{'t9hp5ts,t:6p/9s/4:d,./l9./.7.dn,'ld2,.l0n.5dg1lo'..,gjop./japp/ia/piii/iifi/i3f4/3374638766/8c6a/nmvaansi/f2e2s't,.json',
  • manifestUrl: The URL of the IIIF manifest
  • canvasId: The URI of the canvas where highlights will be displayed
  • highlights: An array of highlight information. Multiple highlights can be added

2. Building the IIIF Search API Format Response

c}o;n''r}s@@e)tcts'mr}o)oyo@oe,n,snputts'c:eteryio@hae'cpvutacrx:eearyracts'tcpsnh''::iee:vR:so:'aechn:hss':io:{iIphAga'gdotnh:'chntnlAsnl+spoinctie:tgn::g'/ahopCh#=/tttaotxiisain.y{io.tnttwinmiteehfLaoinx=.ipnntt'is('gA,ot(,'s+/'h,Ta,iehpgxiihtg/l'hsi,legiahgrthc,th./ix1ny/dwcehox,n)te=x>t.(j{son',

The key point is the on property, which specifies the highlight region in the format canvasURI#xywh=x,y,width,height.

3. Detecting Manifest Load Completion

lc}eo)tniccci};sfooofhtnnnhuai(sss(indguhtttmgsdhniahuHlsgsmmnlbiiuhtaaiisggblannfgchhsitiiehrltcgeffstiiArheetAbgdit=ssdehdbAtt&d(teedms&e)sddi=d;(=er=!m=damm=im)dsaarfiotnntaarrraiirdlaeVtffuosdtieeeereoue.ss;V;rrwmttiVneas.ei;rn[iwe.icsewsfoFretene,rosft.rticcsesghot..inogmnfreagietng.S{i&.st}f&cua;eabtsmnsetavc(Unar)risi;lfIb]ede;s,(t(.c)josn=of>ni)g{.{highlights);

Since Mirador uses Redux, you can monitor state changes with store.subscribe(). Highlights are added when the manifest’s isFetching becomes false and json is present.

This ensures that highlights are added after the manifest has loaded, which is more reliable than using setTimeout.

4. Registering with Mirador

c}vc)vo)io;incp;en'scsesoowsweaewtnsetianaetirnrvrraet.sdcac.dniseohshsdtotawCIRtA:nor-odeoc:rc1msrt'eh'p+peis'.A,ao.oerdcnndnaiitisirgsises=chponephtanWaaM''tirti,,c=nccrhdhha(Mo'(daiw,sodrIerdada.Ad,racocdtrhdi.ACorconetm)cip;eoainnv)ie;oSneWairncdho(w('window-1',{

The receiveSearch action is used to register the constructed response with Mirador.

Application Examples

Multiple Highlights

h]ig{{{hlxxxiyyygwwwhhhht:::s:'''158[000000,,,269000000,,,321005000,,,432005000''',,,ttteeexxxttt:::'''123'''}}},,,

Fetching Data from an API

a}casodyccr}ndnooe)使sHcnntxt)tissuye;gfttrwxhhunhtilnrd::giceadhgtstaaalhipatnnitooanngsnn=.ooh(sa..tmleanctsiownoera=aoox=aditrtdHatad,aoiwtiwrgarinaVhieoaiiltsntteipsewgfo.slehenm,orttsaa,scepdFh.(Hcr(jaioo`sngnm/onhfAanoliPp(igIi)=g.(/;>hccataan(snnn{FvvoraatossamIItAddiP,)oIn(h{sci?ogcnhaflniivgga.hsct=as$n){v;eanscIodd)e;URIComponent(canvasId)}`);

Dynamic Generation from URL Parameters

The viewer.html in this repository receives highlight information from URL parameters and dynamically generates the viewer.

cccccooooonnnnnssssstttttpmcxtaaayernnwxaivhtmfases==sI=tdppUaanr=rrelaawpmm=assUr..RpaggLameeSrsttea.((amg''rsextc.tyehg(wxPe'htatc''r(a))a'n;mmvsaa(nswi''if)Hne;idsgothw'l.)il;gohcta't;ion.search);

How to Obtain Coordinates

To obtain the coordinates (xywh) for highlight regions, the following methods are available:

  1. IIIF Image API Region Specification - Measure coordinates with image editing software
  2. OCR Engine Output - Coordinate information included in OCR results from Tesseract, etc.
  3. Annotation Tools - Use IIIF-compatible annotation creation tools
  4. Machine Learning Model Output - Bounding boxes from object detection models

Summary

By utilizing Mirador’s receiveSearch action, arbitrary regions can be highlighted even for manifests that do not support the IIIF Search API. This method:

  • Is data source independent - Can use data obtained from APIs, files, databases, etc.
  • Uses the same UI as Search API - Leverages Mirador’s standard search result display functionality
  • Supports multiple highlights - Multiple regions can be registered at once via arrays
  • Provides reliable timing control - Detects manifest load completion via store.subscribe()

File Structure

miradRLCmdoEIOiorACNrc-DETashMNRdiviESInig.EBrdehmU-ewldTcxeiIu.rgNsh.hGttht.omt/mmlmd-lhighlight.md#######MGMIiiTtrHaudborPages