Removing unused image load error handling code. r=fredj (closes #3420)
This commit is contained in:
@@ -32,17 +32,6 @@
|
|||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenLayers.Util.onImageLoadError = function() {
|
|
||||||
/**
|
|
||||||
* For images that don't exist in the cache, you can display
|
|
||||||
* a default image - one that looks like water for example.
|
|
||||||
* To show nothing at all, leave the following lines commented out.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//this.src = "../img/blank.gif";
|
|
||||||
//this.style.display = "";
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="init()">
|
<body onload="init()">
|
||||||
|
|||||||
@@ -238,20 +238,6 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
panRatio: 1.5,
|
panRatio: 1.5,
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: viewRequestID
|
|
||||||
* {String} Used to store a unique identifier that changes when the map
|
|
||||||
* view changes. viewRequestID should be used when adding data
|
|
||||||
* asynchronously to the map: viewRequestID is incremented when
|
|
||||||
* you initiate your request (right now during changing of
|
|
||||||
* baselayers and changing of zooms). It is stored here in the
|
|
||||||
* map and also in the data that will be coming back
|
|
||||||
* asynchronously. Before displaying this data on request
|
|
||||||
* completion, we check that the viewRequestID of the data is
|
|
||||||
* still the same as that of the map. Fix for #480
|
|
||||||
*/
|
|
||||||
viewRequestID: 0,
|
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1174,10 +1160,6 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
// set new baselayer
|
// set new baselayer
|
||||||
this.baseLayer = newBaseLayer;
|
this.baseLayer = newBaseLayer;
|
||||||
|
|
||||||
// Increment viewRequestID since the baseLayer is
|
|
||||||
// changing. This is used by tiles to check if they should
|
|
||||||
// draw themselves.
|
|
||||||
this.viewRequestID++;
|
|
||||||
if(!this.allOverlays || this.baseLayer.visibility) {
|
if(!this.allOverlays || this.baseLayer.visibility) {
|
||||||
this.baseLayer.setVisibility(true);
|
this.baseLayer.setVisibility(true);
|
||||||
}
|
}
|
||||||
@@ -1819,8 +1801,6 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
if (zoomChanged) {
|
if (zoomChanged) {
|
||||||
this.zoom = zoom;
|
this.zoom = zoom;
|
||||||
this.resolution = res;
|
this.resolution = res;
|
||||||
// zoom level has changed, increment viewRequestID.
|
|
||||||
this.viewRequestID++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bounds = this.getExtent();
|
var bounds = this.getExtent();
|
||||||
|
|||||||
+8
-76
@@ -279,13 +279,14 @@ OpenLayers.Util.createImage = function(id, px, sz, imgURL, position, border,
|
|||||||
OpenLayers.Util.modifyDOMElement(image, id, px, sz, position,
|
OpenLayers.Util.modifyDOMElement(image, id, px, sz, position,
|
||||||
border, null, opacity);
|
border, null, opacity);
|
||||||
|
|
||||||
if(delayDisplay) {
|
if (delayDisplay) {
|
||||||
image.style.display = "none";
|
image.style.display = "none";
|
||||||
OpenLayers.Event.observe(image, "load",
|
function display() {
|
||||||
OpenLayers.Function.bind(OpenLayers.Util.onImageLoad, image));
|
image.style.display = "";
|
||||||
OpenLayers.Event.observe(image, "error",
|
OpenLayers.Event.stopObservingElement(image);
|
||||||
OpenLayers.Function.bind(OpenLayers.Util.onImageLoadError, image));
|
}
|
||||||
|
OpenLayers.Event.observe(image, "load", display);
|
||||||
|
OpenLayers.Event.observe(image, "error", display);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set special properties
|
//set special properties
|
||||||
@@ -294,8 +295,6 @@ OpenLayers.Util.createImage = function(id, px, sz, imgURL, position, border,
|
|||||||
if (imgURL) {
|
if (imgURL) {
|
||||||
image.src = imgURL;
|
image.src = imgURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
};
|
};
|
||||||
@@ -321,33 +320,6 @@ OpenLayers.Util.setOpacity = function(element, opacity) {
|
|||||||
null, null, null, opacity);
|
null, null, null, opacity);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Function: onImageLoad
|
|
||||||
* Bound to image load events. For all images created with <createImage> or
|
|
||||||
* <createAlphaImageDiv>, this function will be bound to the load event.
|
|
||||||
*/
|
|
||||||
OpenLayers.Util.onImageLoad = function() {
|
|
||||||
// The complex check here is to solve issues described in #480.
|
|
||||||
// Every time a map view changes, it increments the 'viewRequestID'
|
|
||||||
// property. As the requests for the images for the new map view are sent
|
|
||||||
// out, they are tagged with this unique viewRequestID.
|
|
||||||
//
|
|
||||||
// If an image has no viewRequestID property set, we display it regardless,
|
|
||||||
// but if it does have a viewRequestID property, we check that it matches
|
|
||||||
// the viewRequestID set on the map.
|
|
||||||
//
|
|
||||||
// If the viewRequestID on the map has changed, that means that the user
|
|
||||||
// has changed the map view since this specific request was sent out, and
|
|
||||||
// therefore this tile does not need to be displayed (so we do not execute
|
|
||||||
// this code that turns its display on).
|
|
||||||
//
|
|
||||||
if (!this.viewRequestID ||
|
|
||||||
(this.map && this.viewRequestID == this.map.viewRequestID)) {
|
|
||||||
this.style.display = "";
|
|
||||||
}
|
|
||||||
OpenLayers.Element.removeClass(this, "olImageLoadError");
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: IMAGE_RELOAD_ATTEMPTS
|
* Property: IMAGE_RELOAD_ATTEMPTS
|
||||||
* {Integer} How many times should we try to reload an image before giving up?
|
* {Integer} How many times should we try to reload an image before giving up?
|
||||||
@@ -355,38 +327,6 @@ OpenLayers.Util.onImageLoad = function() {
|
|||||||
*/
|
*/
|
||||||
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 0;
|
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Function: onImageLoadError
|
|
||||||
*/
|
|
||||||
OpenLayers.Util.onImageLoadError = function() {
|
|
||||||
this._attempts = (this._attempts) ? (this._attempts + 1) : 1;
|
|
||||||
if (this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
|
|
||||||
var urls = this.urls;
|
|
||||||
if (urls && OpenLayers.Util.isArray(urls) && urls.length > 1){
|
|
||||||
var src = this.src.toString();
|
|
||||||
var current_url, k;
|
|
||||||
for (k = 0; current_url = urls[k]; k++){
|
|
||||||
if(src.indexOf(current_url) != -1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var guess = Math.floor(urls.length * Math.random());
|
|
||||||
var new_url = urls[guess];
|
|
||||||
k = 0;
|
|
||||||
while(new_url == current_url && k++ < 4){
|
|
||||||
guess = Math.floor(urls.length * Math.random());
|
|
||||||
new_url = urls[guess];
|
|
||||||
}
|
|
||||||
this.src = src.replace(current_url, new_url);
|
|
||||||
} else {
|
|
||||||
this.src = this.src;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
OpenLayers.Element.addClass(this, "olImageLoadError");
|
|
||||||
}
|
|
||||||
this.style.display = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: alphaHackNeeded
|
* Property: alphaHackNeeded
|
||||||
* {Boolean} true if the png alpha hack is necessary and possible, false otherwise.
|
* {Boolean} true if the png alpha hack is necessary and possible, false otherwise.
|
||||||
@@ -497,17 +437,9 @@ OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL,
|
|||||||
|
|
||||||
var div = OpenLayers.Util.createDiv();
|
var div = OpenLayers.Util.createDiv();
|
||||||
var img = OpenLayers.Util.createImage(null, null, null, null, null, null,
|
var img = OpenLayers.Util.createImage(null, null, null, null, null, null,
|
||||||
null, false);
|
null, delayDisplay);
|
||||||
div.appendChild(img);
|
div.appendChild(img);
|
||||||
|
|
||||||
if (delayDisplay) {
|
|
||||||
img.style.display = "none";
|
|
||||||
OpenLayers.Event.observe(img, "load",
|
|
||||||
OpenLayers.Function.bind(OpenLayers.Util.onImageLoad, div));
|
|
||||||
OpenLayers.Event.observe(img, "error",
|
|
||||||
OpenLayers.Function.bind(OpenLayers.Util.onImageLoadError, div));
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenLayers.Util.modifyAlphaImageDiv(div, id, px, sz, imgURL, position,
|
OpenLayers.Util.modifyAlphaImageDiv(div, id, px, sz, imgURL, position,
|
||||||
border, sizing, opacity);
|
border, sizing, opacity);
|
||||||
|
|
||||||
|
|||||||
@@ -254,21 +254,6 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Util_imageLoadError(t) {
|
|
||||||
t.plan(2);
|
|
||||||
|
|
||||||
var img = OpenLayers.Util.createImage(null, null, null, null, null, null, null, false);
|
|
||||||
|
|
||||||
// mock up image load failure
|
|
||||||
img._attempts = OpenLayers.IMAGE_RELOAD_ATTEMPTS + 1;
|
|
||||||
OpenLayers.Util.onImageLoadError.call(img);
|
|
||||||
t.ok(OpenLayers.Element.hasClass(img, 'olImageLoadError'), 'broken image has class olImageLoadError');
|
|
||||||
|
|
||||||
// mock up image load success
|
|
||||||
OpenLayers.Util.onImageLoad.call(img);
|
|
||||||
t.ok(!OpenLayers.Element.hasClass(img, 'olImageLoadError'), 'good image does not have class olImageLoadError');
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_Util_applyDefaults(t) {
|
function test_Util_applyDefaults(t) {
|
||||||
|
|
||||||
t.plan(12);
|
t.plan(12);
|
||||||
|
|||||||
Reference in New Issue
Block a user