src/imageloader.js
function(){
        var self = this;
        var selfAbort = this.abort;

        this.image = new Image();

        this.image.onload = function(){
            self.finish(true);
        };
        this.image.onabort = this.image.onerror = function() {
            self.errorMsg = "Image load aborted";
            self.finish(false);
        };

        this.jobId = window.setTimeout(function(){
            self.errorMsg = "Image load exceeded timeout (" + self.timeout + " ms)";
            self.finish(false);
        }, this.timeout);

        // Load the tile with an AJAX request if the loadWithAjax option is
        // set. Otherwise load the image by setting the source proprety of the image object.
        if (this.loadWithAjax) {
            this.request = $.makeAjaxRequest({
                url: this.src,
                withCredentials: this.ajaxWithCredentials,
                headers: this.ajaxHeaders,
                responseType: "arraybuffer",
                success: function(request) {
                    var blb;
                    // Make the raw data into a blob.
                    // BlobBuilder fallback adapted from
                    // http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility
                    try {
                        blb = new window.Blob([request.response]);
                    } catch (e) {
                        var BlobBuilder = (
                            window.BlobBuilder ||
                            window.WebKitBlobBuilder ||
                            window.MozBlobBuilder ||
                            window.MSBlobBuilder
                        );
                        if (e.name === 'TypeError' && BlobBuilder) {
                            var bb = new BlobBuilder();
                            bb.append(request.response);
                            blb = bb.getBlob();
                        }
                    }
                    // If the blob is empty for some reason consider the image load a failure.
                    if (blb.size === 0) {
                        self.errorMsg = "Empty image response.";
                        self.finish(false);
                    }
                    // Create a URL for the blob data and make it the source of the image object.
                    // This will still trigger Image.onload to indicate a successful tile load.
                    var url = (window.URL || window.webkitURL).createObjectURL(blb);
                    self.image.src = url;
                },
                error: function(request) {
                    self.errorMsg = "Image load aborted - XHR error";
                    self.finish(false);
                }
            });

            // Provide a function to properly abort the request.
            this.abort = function() {
                self.request.abort();

                // Call the existing abort function if available
                if (typeof selfAbort === "function") {
                    selfAbort();
                }
            };
        } else {
            if (this.crossOriginPolicy !== false) {
                this.image.crossOrigin = this.crossOriginPolicy;
            }

            this.image.src = this.src;
        }
    }
function(){
        var self = this;
        var selfAbort = this.abort;

        this.image = new Image();

        this.image.onload = function(){
            self.finish(true);
        };
        this.image.onabort = this.image.onerror = function() {
            self.errorMsg = "Image load aborted";
            self.finish(false);
        };

        this.jobId = window.setTimeout(function(){
            self.errorMsg = "Image load exceeded timeout (" + self.timeout + " ms)";
            self.finish(false);
        }, this.timeout);

        // Load the tile with an AJAX request if the loadWithAjax option is
        // set. Otherwise load the image by setting the source proprety of the image object.
        if (this.loadWithAjax) {
            this.request = $.makeAjaxRequest({
                url: this.src,
                withCredentials: this.ajaxWithCredentials,
                headers: this.ajaxHeaders,
                responseType: "arraybuffer",
                success: function(request) {
                    var blb;
                    // Make the raw data into a blob.
                    // BlobBuilder fallback adapted from
                    // http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility
                    try {
                        blb = new window.Blob([request.response]);
                    } catch (e) {
                        var BlobBuilder = (
                            window.BlobBuilder ||
                            window.WebKitBlobBuilder ||
                            window.MozBlobBuilder ||
                            window.MSBlobBuilder
                        );
                        if (e.name === 'TypeError' && BlobBuilder) {
                            var bb = new BlobBuilder();
                            bb.append(request.response);
                            blb = bb.getBlob();
                        }
                    }
                    // If the blob is empty for some reason consider the image load a failure.
                    if (blb.size === 0) {
                        self.errorMsg = "Empty image response.";
                        self.finish(false);
                    }
                    // Create a URL for the blob data and make it the source of the image object.
                    // This will still trigger Image.onload to indicate a successful tile load.
                    var url = (window.URL || window.webkitURL).createObjectURL(blb);
                    self.image.src = url;
                },
                error: function(request) {
                    self.errorMsg = "Image load aborted - XHR error";
                    self.finish(false);
                }
            });

            // Provide a function to properly abort the request.
            this.abort = function() {
                self.request.abort();

                // Call the existing abort function if available
                if (typeof selfAbort === "function") {
                    selfAbort();
                }
            };
        } else {
            if (this.crossOriginPolicy !== false) {
                this.image.crossOrigin = this.crossOriginPolicy;
            }

            this.image.src = this.src;
        }
    }
function ( ) { var self = this ; var selfAbort = this . abort ; this . image = new Image ( ) ; this . image . onload = function ( ) { self . finish ( true ) ; } ; this . image . onabort = this . image . onerror = function ( ) { self . errorMsg = "Image load aborted" ; self . finish ( false ) ; } ; this . jobId = window . setTimeout ( function ( ) { self . errorMsg = "Image load exceeded timeout (" + self . timeout + " ms)" ; self . finish ( false ) ; } , this . timeout ) ; // Load the tile with an AJAX request if the loadWithAjax option is // set. Otherwise load the image by setting the source proprety of the image object. if ( this . loadWithAjax ) { this . request = $ . makeAjaxRequest ( { url : this . src , withCredentials : this . ajaxWithCredentials , headers : this . ajaxHeaders , responseType : "arraybuffer" , success : function ( request ) { var blb ; // Make the raw data into a blob. // BlobBuilder fallback adapted from // http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility try { blb = new window . Blob ( [ request . response ] ) ; } catch ( e ) { var BlobBuilder = ( window . BlobBuilder || window . WebKitBlobBuilder || window . MozBlobBuilder || window . MSBlobBuilder ) ; if ( e . name === 'TypeError' && BlobBuilder ) { var bb = new BlobBuilder ( ) ; bb . append ( request . response ) ; blb = bb . getBlob ( ) ; } } // If the blob is empty for some reason consider the image load a failure. if ( blb . size === 0 ) { self . errorMsg = "Empty image response." ; self . finish ( false ) ; } // Create a URL for the blob data and make it the source of the image object. // This will still trigger Image.onload to indicate a successful tile load. var url = ( window . URL || window . webkitURL ) . createObjectURL ( blb ) ; self . image . src = url ; } , error : function ( request ) { self . errorMsg = "Image load aborted - XHR error" ; self . finish ( false ) ; } } ) ; // Provide a function to properly abort the request. this . abort = function ( ) { self . request . abort ( ) ; // Call the existing abort function if available if ( typeof selfAbort === "function" ) { selfAbort ( ) ; } } ; } else { if ( this . crossOriginPolicy !== false ) { this . image . crossOrigin = this . crossOriginPolicy ; } this . image . src = this . src ; } }
Starts the image job.
@method
Starts the image job .