Esempio n. 1
0
        public virtual void RequestImage()
        {
            if (Dataset.WcsImage != null)
            {
                texReady       = true;
                Downloading    = false;
                errored        = false;
                ReadyToRender  = true;
                RequestPending = false;
                TileCache.RemoveFromQueue(this.Key, true);
                return;
            }

            if (!Downloading && !ReadyToRender)
            {
                Downloading = true;
                texture     = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)texture;

                texture.AddEventListener("load", delegate(ElementEvent e)
                {
                    texReady       = true;
                    Downloading    = false;
                    errored        = false;
                    ReadyToRender  = texReady && (DemReady || !demTile);
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                    MakeTexture();
                }, false);

                texture.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!texture.HasAttribute("proxyattempt"))
                    {
                        texture.Src = Util.GetProxiedUrl(URL);
                        texture.SetAttribute("proxyattempt", true);
                    }
                    else
                    {
                        Downloading    = false;
                        ReadyToRender  = false;
                        errored        = true;
                        RequestPending = false;
                        TileCache.RemoveFromQueue(this.Key, true);
                    }
                }, false);

                xdomimg.crossOrigin = "anonymous";
                texture.Src         = this.URL.Replace("cdn.", "www.");
                //texture.Src = "dss.png";

                // TODO add event listener for failed!
            }
        }
Esempio n. 2
0
        public void Load(string url)
        {
            URL = url;
            if (!Downloading)
            {
                Downloading  = true;
                ImageElement = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)ImageElement;

                ImageElement.AddEventListener("load", delegate(ElementEvent e)
                {
                    Ready       = true;
                    Downloading = false;
                    Errored     = false;
                    MakeTexture();
                }, false);

                ImageElement.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!ImageElement.HasAttribute("proxyattempt"))
                    {
                        ImageElement.SetAttribute("proxyattempt", true);
                        string new_url = URLHelpers.singleton.activateProxy(URL);

                        if (new_url != null)    // null => don't bother: we know that the proxy won't help
                        {
                            ImageElement.Src = new_url;
                            return;
                        }
                    }

                    Downloading = false;
                    Ready       = false;
                    Errored     = true;
                }, false);

                xdomimg.crossOrigin = "anonymous";
                ImageElement.Src    = URL;
            }
        }
Esempio n. 3
0
        public void Load(string url)
        {
            URL = url;
            if (!Downloading)
            {
                Downloading  = true;
                ImageElement = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)ImageElement;

                ImageElement.AddEventListener("load", delegate(ElementEvent e)
                {
                    Ready       = true;
                    Downloading = false;
                    Errored     = false;
                    MakeTexture();
                }, false);

                ImageElement.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!ImageElement.HasAttribute("proxyattempt"))
                    {
                        ImageElement.Src = Util.GetProxiedUrl(URL);
                        ImageElement.SetAttribute("proxyattempt", true);
                    }
                    else
                    {
                        Downloading = false;
                        Ready       = false;
                        Errored     = true;
                    }
                }, false);

                xdomimg.crossOrigin = "anonymous";
                //              texture.Src = this.URL.Replace("cdn.", "www.");

                ImageElement.Src = URL;
            }
        }
Esempio n. 4
0
        public virtual void RequestImage()
        {
            if (Dataset.WcsImage != null)
            {
                texReady       = true;
                Downloading    = false;
                errored        = false;
                ReadyToRender  = true;
                RequestPending = false;
                TileCache.RemoveFromQueue(this.Key, true);
                return;
            }

            if (!Downloading && !ReadyToRender)
            {
                Downloading = true;
                texture     = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)texture;

                texture.AddEventListener("load", delegate(ElementEvent e)
                {
                    texReady       = true;
                    Downloading    = false;
                    errored        = false;
                    ReadyToRender  = texReady && (DemReady || !demTile);
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                    MakeTexture();
                }, false);

                texture.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!texture.HasAttribute("proxyattempt"))
                    {
                        texture.SetAttribute("proxyattempt", true);

                        // NOTE: `this.URL` is dynamically generated using
                        // URLHelpers.rewrite(). Say that we request tiles from
                        // example.com, which requires CORS proxying. Say also
                        // that this callback is called for a request to a tile
                        // that should in fact be available. If a different
                        // request fails before this callback is called,
                        // activateProxy() will be called on the example.com
                        // domain, making it so that `this.URL` in the following
                        // call goes through the proxy, making it so that
                        // `new_url` is null, making it so that this tile is
                        // erroneously marked as failed when it should not be.
                        // The solution: make sure to check proxy activation
                        // with the *original* request URL, `texture.Src`, not
                        // the one that may have been updated, `this.URL`.
                        string new_url = URLHelpers.singleton.activateProxy(texture.Src);

                        if (new_url != null)
                        {  // null => don't bother: we know that the proxy won't help
                            texture.Src = new_url;
                            return;
                        }
                    }

                    Downloading    = false;
                    ReadyToRender  = false;
                    errored        = true;
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                }, false);

                xdomimg.crossOrigin = "anonymous";
                texture.Src         = this.URL;
            }
        }
Esempio n. 5
0
        public virtual void RequestImage()
        {
            if (dataset.Extension.ToLowerCase().IndexOf("fits") > -1)
            {
                if (!Downloading && !ReadyToRender)
                {
                    Downloading = true;
                    if (RenderContext.UseGlVersion2)
                    {
                        fitsImage = new FitsImageTile(dataset, URL, delegate(WcsImage wcsImage)
                        {
                            Downloading = false;
                            errored     = fitsImage.errored;
                            TileCache.RemoveFromQueue(this.Key, true);
                            if (!fitsImage.errored)
                            {
                                // For a non-HiPS tiled FITS, this is our
                                // mechanism for notifying the layer creator
                                // that the initial FITS data have loaded and
                                // the FitsProperties can be trusted.
                                if (Level == 0)
                                {
                                    dataset.FitsProperties.FireMainImageLoaded(fitsImage);
                                    fitsImage.ApplyDisplaySettings();
                                }
                                texReady       = true;
                                ReadyToRender  = texReady && (DemReady || !demTile);
                                RequestPending = false;
                                MakeTexture();
                            }
                        });
                    }
                    else
                    {
                        fitsImage = FitsImageJs.CreateTiledFits(dataset, URL, delegate(WcsImage wcsImage)
                        {
                            if (Level == 0)
                            {
                                dataset.FitsProperties.FireMainImageLoaded(fitsImage);
                            }
                            texReady       = true;
                            Downloading    = false;
                            errored        = fitsImage.errored;
                            ReadyToRender  = texReady && (DemReady || !demTile);
                            RequestPending = false;
                            TileCache.RemoveFromQueue(this.Key, true);
                            texture2d = wcsImage.GetBitmap().GetTexture();
                        });
                    }
                }
            }
            else
            {
                if (Dataset.WcsImage != null)
                {
                    texReady       = true;
                    Downloading    = false;
                    errored        = false;
                    ReadyToRender  = true;
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                    return;
                }

                if (!Downloading && !ReadyToRender)
                {
                    Downloading = true;
                    texture     = (ImageElement)Document.CreateElement("img");
                    CrossDomainImage xdomimg = (CrossDomainImage)(object)texture;

                    texture.AddEventListener("load", delegate(ElementEvent e)
                    {
                        texReady       = true;
                        Downloading    = false;
                        errored        = false;
                        ReadyToRender  = texReady && (DemReady || !demTile);
                        RequestPending = false;
                        TileCache.RemoveFromQueue(this.Key, true);
                        MakeTexture();
                    }, false);

                    texture.AddEventListener("error", delegate(ElementEvent e)
                    {
                        if (!texture.HasAttribute("proxyattempt"))
                        {
                            texture.SetAttribute("proxyattempt", true);

                            // NOTE: `this.URL` is dynamically generated using
                            // URLHelpers.rewrite(). Say that we request tiles from
                            // example.com, which requires CORS proxying. Say also
                            // that this callback is called for a request to a tile
                            // that should in fact be available. If a different
                            // request fails before this callback is called,
                            // activateProxy() will be called on the example.com
                            // domain, making it so that `this.URL` in the following
                            // call goes through the proxy, making it so that
                            // `new_url` is null, making it so that this tile is
                            // erroneously marked as failed when it should not be.
                            // The solution: make sure to check proxy activation
                            // with the *original* request URL, `texture.Src`, not
                            // the one that may have been updated, `this.URL`.
                            string new_url = URLHelpers.singleton.activateProxy(texture.Src);

                            if (new_url != null)
                            {  // null => don't bother: we know that the proxy won't help
                                texture.Src = new_url;
                                return;
                            }
                        }

                        Downloading    = false;
                        ReadyToRender  = false;
                        errored        = true;
                        RequestPending = false;
                        TileCache.RemoveFromQueue(this.Key, true);
                    }, false);

                    xdomimg.crossOrigin = "anonymous";
                    texture.Src         = this.URL;
                }
            }
        }