I am having trouble with the Annotation Javascript library, it doesn't

After installing annotorious from the GitHub repository and following the code provided in the official documentation, I encountered an issue where the annotations were not displaying on the image as expected. Below is the HTML code that I used:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="annotorious.min.css">
      </head>
      
      <body>
        <div id="content">
          <img id="hallstatt" src="640px-Hallstatt.jpg">
        </div>
        <script>
          (function() {
            var anno = Annotorious.init({
              image: 'hallstatt' // image element or ID
            });
      
            anno.loadAnnotations('annotations.w3c.json');
      
            // Add event handlers using .on  
            anno.on('createAnnotation', function(annotation) {
              // Do something
            });
          })()
        </script>
      
        <script type="text/javascript" src="annotorious.min.js"></script>
        <script type="text/javascript" src="annotorious.umd.js.map"></script>
        <script type="text/javascript" src="recogito-polyfills.js"></script>
      </body>
</html>

I have verified that all necessary files are located in the same directory, as shown below:

Directory of C:\Users\YCH\Desktop\test_annotation

03/11/2023  12:42    <DIR>          .
03/11/2023  12:42    <DIR>          ..
03/11/2023  12:41             7 368 640px-Hallstatt.jpg
03/11/2023  14:18            10 311 annotorious.min.css
03/11/2023  12:52           286 326 annotorious.min.js
03/11/2023  12:36         1 055 483 annotorious.umd.js.map
03/11/2023  14:16               937 index.html
03/11/2023  12:36           161 729 recogito-polyfills.js

To troubleshoot, I tested the CSS by changing the body color and the JavaScript by using console.log, but even after configuring both with the HTML file, the annotations still did not appear on the image.

Answer №1

It seems like you may be trying to run your demo page by directly opening the HTML file in your browser.

Once your code hits the line that calls loadAnnotations, it will try to fetch a JSON file. However, most browsers won't allow this due to cross-origin security policies when loading from a local file. You'll need to host the page online or use a development server instead. (More details below.)

If you check your browser console, there's likely an error related to the loadAnnotations call. By commenting that out, you should be able to get the annotation feature to function properly.

To successfully load annotations from a JSON file, consider serving your working directory with a development server such as http-server.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting the default value in a Reactive form on the fly: A step-by-step guide

When creating a table using looping, I need to set the default value of my Reactive Form to `Repeat` if the loop value matches a particular character, otherwise I want it to be empty. Here is my code: typescript rDefault:string = ""; create(){ ...

Updating class with jQuery based on dynamically changing content

I am using countdown.js to create a custom countdown timer. My goal is to replicate the countdown timer seen on the homepage, but with the ability to change the target date (which I have already accomplished). Here is an example of what I currently have f ...

Error: Attempting to access an undefined property ('useParams') which cannot be read

Hey there, I'm currently facing some challenges with the new react-router-dom v6. As I am still in the learning phase of this latest version, I could really use some assistance. import React from 'react' function Bookingscrren({match}) { ...

Tips for transforming numerical date data into a string format

Is there a method to convert the numeric month in a table into a string format? <table style="width: 100%;"> <tr> <th>Date</th> <th>Total</th> </tr> <tr> <td id="date ...

Separate compound words without hyphens at the boundaries of each word

I am currently incorporating the use of Bootstrap for my project. Let's assume that I have text displayed in this way: "Stackoverflow" Is there a method to automatically ensure that it breaks like below if the text exceeds the container: "Stack ...

The troubleshooting of debugging javascript remotely on IntelliJ with the JetBrains Chrome extension is proving to be unsuccessful

I've been attempting to set up a debugger for some JavaScript files that I'm working on in IntelliJ (version 2020.1.4). Following the guidelines provided here Debug with JetBrains Chrome extension, I believe I have successfully completed all the ...

Navigating with Vue Router on Internet Information Services (IIS)

I am encountering difficulties understanding why my routes are failing when I refresh my VueJS application hosted on IIS. Everything works fine during normal browsing, but once I press F5 or update view information through a button, a 403 error is thrown. ...

Switching buttons with AngularJS

I am currently working on a Github search app using the Github API in Angular. My goal is to make it so that when the user clicks the "Add to Favorite" button, the button disappears and the "Remove Favorite" button is displayed instead. I attempted to achi ...

Static CSS box positioned above dynamic scaling box

Let's Think About It <div id="foo"> Lorem ipsum </div> <div id="bar"> sit amet </div> Is there a way to maintain the size of foo as it is while allowing bar to fill the remaining space on the page when the window size cha ...

Incorporating external .js files from a different server using node.js

Is it possible to include .js files from another server into a node.js program? I cannot simply use require('./local_file.js') to fetch files over the Internet like this: require('http://www.server.com/path/file.js'); I attempted usin ...

Identify when a request is being executed using AJAX by checking the URL

My current code includes multiple ajax requests from various JavaScript files. I am looking for a way to identify specific ajax requests and interrupt their execution in order to prioritize a newer one. Is it possible to detect and stop ajax requests based ...

The Javascript query is returning an [object Object] data type

I am facing an issue with a JavaScript file that is querying a SharePoint list. Specifically, the Priority drop down in the query result is displaying as [object OBJECT]. I suspect it has something to do with the var query string where I have added the &ap ...

The HTML Canvas seems to be malfunctioning for some unknown reason

As a beginner in programming, I am struggling to understand why the code below is not working. The first three lines of the script are necessary for another part of the webpage, but I don't see how that would affect the rest of the code: <!DOCTY ...

Angular Directive - introducing a fresh approach to two-way binding and enable "pass-by-value" functionality

In a previous question, I inquired about the possibility of incorporating an attribute on a directive to allow for values to be passed in various formats, such as: <my-directive att> //Evaluates to true <my-directive att="true"> ...

Exploring the Efficiency Enhancements in the next/image Optimization Process within Next.js

I've been delving into Next.js and using the next/image component for image rendering. While leveraging it to enhance image loading in my project, I've become intrigued by the intricate workings behind the scenes. I'm particularly interested ...

Using CodeIgniter to dynamically load colors from a database into a CSS color selector

My views are populated by an array that holds all the necessary information... This array also includes user profile data, with a link key and color value specified... Is there a way to pass this information into the CSS color selector so that each user& ...

How about making a TicTacToe game with JavaScript?

While developing a TicTacToe game, I encountered a syntax error towards the end of my code. Despite not completing the game yet, it is perplexing that the error is appearing after the last line, which seemingly doesn't contain any issues. Any insights ...

Choose Your Date of Birth from the Drop-Down Menu with ng-options

I've been working on creating a dropdown for Date of Birth using ng-options. I've managed to set it up for day and month, but I'm encountering an issue with the year dropdown. The problem is that the years are displayed in reverse order, sta ...

Creating a webpage that supports multiple languages using either JavaScript or jQuery

I am currently developing a web application that will have support for multiple languages. To achieve this, I have created a table in my database with translations. However, I am unsure of how to populate the web application with these translations. My ide ...

Implement a FOR loop in conjunction with an AJAX request

My goal is to send an AJAX request with multiple form fields and use an array for validations. I would like to also pass these values via AJAX: Although I haven't used a for loop in JavaScript before, it looks familiar. The current approach of the l ...