ericmandel / js9

astronomical image display everywhere
https://js9.si.edu
Other
121 stars 50 forks source link

Preload regions with image #89

Closed ferrigno closed 2 years ago

ferrigno commented 2 years ago

Hello, How can I preload regions together with an image in ds9? I have not managed to make them appear using the LoadRegions function.

ferrigno commented 2 years ago

I clarify that by clicking on a javascript link, I can load regions, but I have not managed to let them appear directly on the page at load.

ericmandel commented 2 years ago

There are two ways to do this:

  1. add a regions property to the opts object passed to onload:

        const s = "circle(512,512,100); box(200,300,40,50)"
        JS9.Load("test.fits",  {scale:"log", xdim:4096, ydim:4096, bin:8, zoom:32, regions:s});

    You should also be able to pass a URL to a regions file in the regions property (using the same origin, of course).

  2. Use the onload property to execute LoadRegions (or whatever other routines you want to call):

          # see tests/js9debug.html:
        JS9.Load("data/fits/casa.fits[events][energy=3000:7000]",
          {colormap: "cool", contrast: 5.9, bias: 0.66, scale: "log, xdim: 8192, ydim: 8192, bin: 4,
            onload: function(im){
              JS9.SetZoom(2);
              JS9.LoadRegions("data/casa/casa.reg", {onload: "SelectRegions(ellipse)"});
           }
        );

    Note that here we are loading regions using the image onload function and then calling the regions onload function to select a particular region ... more flexibility than option 1.

I trust you have seen that JS9 is no longer in active development. See #88.

ferrigno commented 2 years ago

Thank you, with the onload function it works smoothly. I read that you retired, enjoy your free time ! I find js9 very useful, but not used as much as it deserves. I hope somebody will keep at least the maintenance..