function loadToMap (vectors) {
  vectors.forEach(data => {
    var {coordinates, notFeature: { notGeometry: {notType} }, _id, transcription_fragment, translation_fragment, parent, children, OCD} = data

    var tempGeoJSON = { 'type': 'Feature', 'properties': {}, 'geometry': {} }
    var oldData = tempGeoJSON
    oldData.geometry.type = notType
    oldData.geometry.coordinates = [coordinates]
    oldData.properties.transcription_fragment = transcription_fragment
    oldData.properties.translation_fragment = translation_fragment
    oldData.properties.parent = parent
    oldData.properties.children = children
    oldData.properties.OCD = OCD

    L.geoJson(oldData,
      { style: {
        color: Polyanno.colours.default.vector
      },
        onEachFeature: function (feature, layer) {
          layer._leaflet_id = _id,
            allDrawnItems.addLayer(layer),
            layer.bindPopup(popupVectorMenu)
        }
      }).addTo(polyanno_map)
  })
}

function loadToPolyanno (vectors, annotations, transcriptions, translations, editors) {
  // - console.log(vectors, annotations, transcriptions, translations, editors)

  vectors.forEach(vector => {
    Object.setPrototypeOf(vector, Polyanno.vector.prototype)
    // - console.log(vector)
    Polyanno.vectors.add(vector)
  })

  annotations.forEach(annotation => {
    Object.setPrototypeOf(annotation, Polyanno.annotation.prototype)
    // - console.log(annotation)
    Polyanno.annotations.add(annotation)
  })

  transcriptions.forEach(transcription => {
    Object.setPrototypeOf(transcription, Polyanno.transcription.prototype)
    // - console.log(transcription)
    Polyanno.transcriptions.add(transcription)
  })

  translations.forEach(translation => {
    Object.setPrototypeOf(translation, Polyanno.translation.prototype)
    // - console.log(translation)
    Polyanno.transcriptions.add(translation)
  })

  editors.forEach(editor => {
    Object.setPrototypeOf(editor, Polyanno.editor.prototype)
    // - console.log(editor)
    Polyanno.transcriptions.add(editor)
  })
}

const load = function () {
  const imageId = idExtractor(imageSelected)
  $.get(`/document/${imageId}`, function (data) {
    console.log(data)
    if ((typeof data) !== 'string') {
    // const data = JSON.stringify(object)
      const vectors = JSON.parse(data.vectors)
      const annotations = JSON.parse(data.annotations)
      const transcriptions = JSON.parse(data.transcriptions)
      const translations = JSON.parse(data.translations)
      const editors = JSON.parse(data.editors)

      loadToMap(vectors)
      loadToPolyanno(vectors, annotations, transcriptions, translations, editors)
      console.log(vectors, annotations, transcriptions, translations, editors)
    } else {
      console.log(data)
    }
  })
}

$(document).bind('seadragonExtension.onCurrentViewUri', function (event, obj) {
  let uri = obj.fullUri
  uri = uri.split('/').slice(0, -4)
  uri.push('info.json')
  uri = uri.join('/')

  imageSelected = uri

  console.log(imageSelected)

  const html =
  `<div class="row" id="polyanno-top-bar"><\/div>
  <div class="row" id="polyanno-page-body"><\/div>
  <script src="/javascripts/modules/dragondrop.js"><\/script>
  <script src="/javascripts/modules/alltheunicode.js"><\/script>
  <script src="/javascripts/modules/polyanno.js"><\/script>
  <script src="/javascripts/modules/PolyannoSetup.js"><\/script>
  <script src="/dist/PolyannoEd.bundle.js"><\/script>`

  //  console.log(html)
  $('#polyannoDiv').html(html)
  load()
})

const idExtractor = function (uri) {
  return uri.split('/').find(data => data.includes('UoE'))
}

$('#savePolyanno').on('click', function () {
  const recordUndefined = function (k, v) { if (v === undefined) { return null } return v }

  const imageId = idExtractor(imageSelected)

  const annotations = JSON.stringify(Polyanno.annotations.getAll(), recordUndefined)
  const vectors = JSON.stringify(Polyanno.vectors.getAll(), recordUndefined)
  const translations = JSON.stringify(Polyanno.translations.getAll(), recordUndefined)
  const transcriptions = JSON.stringify(Polyanno.transcriptions.getAll(), recordUndefined)
  const editors = JSON.stringify(JSON.decycle(Polyanno.editors.getAll(), true))

  $.post('/save',
         {imageId: imageId, vectors: vectors, annotations: annotations, translations: translations, transcriptions: transcriptions, editors: editors},
          function (data) {
            // location.reload()
            console.log(data)
          }
    )
})

$('document').ready(load())

@@ -2968,61 +2968,8 @@
 ')%0A%0A
-  imageSelected = uri%0A%0A  console.log(imageSelected)%0A%0A
   co
@@ -3086,319 +3086,605 @@
 %3E%0A  
-%3Cscript src=%22/javascripts/modules/dragondrop.js%22%3E%3C%5C/script%3E%0A  %3Cscript src=%22/javascripts/modules/alltheunicode.js%22%3E%3C%5C/script%3E%0A  %3Cscript src=%22/javascripts/modules/polyanno.js%22%3E%3C%5C/script%3E%0A  %3Cscript src=%22/javascripts/modules/PolyannoSetup.js%22%3E%3C%5C/script%3E%0A  %3Cscript src=%22/dist/PolyannoEd.bundle.js%22%3E%3C%5C/script%3E%60
+%0A  %60%0A  $('#polyannoDiv').html(html)%0A%0A  const jsFiles = %5B'dragondrop', 'alltheunicode', 'polyanno'%5D%0A%0A  jsFiles.forEach(jsFile =%3E %7B%0A    $.getScript(%60/javascripts/modules/$%7BjsFile%7D.js%60)%0A      .done(function (script, textStatus) %7B%0A        console.log(textStatus)%0A      %7D)%0A      .fail(function (jqxhr, settings, exception) %7B%0A        $('div.log').text('Triggered ajaxError handler.')%0A      %7D)%0A  %7D)%0A%0A  imageSelected = uri%0A%0A  // console.log(imageSelected)%0A%0A  // const theImage = getTargetJSON(imageSelected)%0A  // imageSelectedFormats = theImage.formats%0A  // imageSelectedMetadata = theImage.metadata
 %0A%0A  //
- 
  con
@@ -3696,44 +3696,112 @@
 log(
-html)%0A  $('#polyannoDiv').html(html)
+theImage)%0A%0A  polyanno_setup(%7B%0A    'highlighting': true,%0A    'minimising': true,%0A    'voting': true%0A  %7D)%0A
 %0A  l
@@ -4715,41 +4715,8 @@
 ) %7B%0A
-            // location.reload()%0A
     
@@ -4766,33 +4766,4 @@
 %0A%7D)%0A
-%0A$('document').ready(load())%0A

change the way jquery call js file to getScript