Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Adding markers in openseadragon viewer even if state variable is false

I am adding markers on openseadragon viewer. This is the function I am using for this

if (cellLabeler) {
if (!viewer) return;
console.log("calling celllabel", cellLabeler);

viewer.addHandler("canvas-click", function (event) {
  const viewerPoint = viewer.viewport.pointFromPixel(event.position);
  console.log("Clicking coordinates:", viewerPoint.x, viewerPoint.y);

  var img = document.createElement("img");
  img.src = { logo };
  viewer.addOverlay(img, viewerPoint);
});}

Celllabeler is a state variable I am using for toggling modes for adding markers. There is a button which toggles celllabeler state variable. It works when celllabeler is true, but it also works if I toggle it to false after labelling. Is this an issue with addHandler event that I am using?

EDIT: Code currently looks like this:

if (viewer){
console.log("calling celllabel", cellLabeler);

viewer.addHandler("canvas-click", function (event) {
  if (cellLabeler) {
    if (!viewer) return;
    const viewerPoint = viewer.viewport.pointFromPixel(event.position);
    console.log("Clicking coordinates:", viewerPoint.x, viewerPoint.y);

    var img = document.createElement("img");
    img.src = "https://dummyimage.com/10x10/000/11ff00";
    viewer.addOverlay(img, viewerPoint);
  }
});

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Once you have done the addHandler, it'll always run regardless of the cellLabeler state. What you need to do is put the if (cellLabeler) inside the addHandler.

EDIT: here's an example of what I'm talking about:

// Set up label mode buttons

var cellLabeler = false;

document.getElementById('start-labeling').addEventListener('click', function() {
  cellLabeler = true;
});

document.getElementById('stop-labeling').addEventListener('click', function() {
  cellLabeler = false;
});

// Set up OpenSeadragon

var viewer = OpenSeadragon( ... );

viewer.addHandler("canvas-click", function (event) {
  if (cellLabeler) {
    const viewerPoint = viewer.viewport.pointFromPixel(event.position);
    console.log("Clicking coordinates:", viewerPoint.x, viewerPoint.y);

    var img = document.createElement("img");
    img.src = "https://dummyimage.com/10x10/000/11ff00";
    viewer.addOverlay(img, viewerPoint);
  }
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!