From b7bf7d5436859934f0e8f04afef030045ad9eace Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Fri, 16 Feb 2007 19:08:01 +0000 Subject: [PATCH] Pull up r2181:r2229 to 2.3 branch. Includes fixes for: #429 fix panning for odd size viewport #478 Double clicking overview map expand/contract button zooms in Safari #484 conflict between _addButton of MouseToolbar and PanZoom #485 null pointer exception on CTRL+F5 in IE for WMS.Untiled #486 add a few sanity checks to overview map #489 requires tag incorrect in OverviewMap.js #498 overviewmap: rectangle has minimum height in IE git-svn-id: http://svn.openlayers.org/branches/openlayers/2.3@2230 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/OverviewMap.js | 45 +++++++++++++++++++-------- lib/OpenLayers/Control/PanZoom.js | 2 +- lib/OpenLayers/Layer.js | 16 ++++++++-- lib/OpenLayers/Layer/WMS/Untiled.js | 23 ++++++++++++-- lib/OpenLayers/Util.js | 2 +- tests/grid_inittiles.html | 32 +++++++++++++++++++ 6 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 tests/grid_inittiles.html diff --git a/lib/OpenLayers/Control/OverviewMap.js b/lib/OpenLayers/Control/OverviewMap.js index be413614e0..5786882ea7 100644 --- a/lib/OpenLayers/Control/OverviewMap.js +++ b/lib/OpenLayers/Control/OverviewMap.js @@ -6,11 +6,11 @@ * @author Tim Schaub */ -// @require: OpenLayers/Control.js - /** -* @class -*/ + * @class + * + * @requires OpenLayers/Control.js + */ OpenLayers.Control.OverviewMap = OpenLayers.Class.create(); OpenLayers.Control.OverviewMap.prototype = @@ -106,6 +106,7 @@ OpenLayers.Control.OverviewMap.prototype = this.extentRectangle = document.createElement('div'); this.extentRectangle.style.position = 'absolute'; this.extentRectangle.style.zIndex = 1000; //HACK + this.extentRectangle.style.overflow = 'hidden'; this.extentRectangle.style.backgroundImage = 'url(' + OpenLayers.Util.getImagesLocation() + '/blank.png)'; @@ -162,6 +163,11 @@ OpenLayers.Control.OverviewMap.prototype = OpenLayers.Event.observe(this.maximizeDiv, 'click', this.maximizeControl.bindAsEventListener(this)); + OpenLayers.Event.observe(this.maximizeDiv, + 'dblclick', + function(e) { + OpenLayers.Event.stop(e); + }); this.div.appendChild(this.maximizeDiv); // minimize button div @@ -177,7 +183,11 @@ OpenLayers.Control.OverviewMap.prototype = OpenLayers.Event.observe(this.minimizeDiv, 'click', this.minimizeControl.bindAsEventListener(this)); - + OpenLayers.Event.observe(this.minimizeDiv, + 'dblclick', + function(e) { + OpenLayers.Event.stop(e); + }); this.div.appendChild(this.minimizeDiv); this.minimizeControl(); @@ -418,12 +428,14 @@ OpenLayers.Control.OverviewMap.prototype = // The base layer for overview map needs to be in the same projection // as the base layer for the main map. This should be made more robust. if(this.map.units != 'degrees') { - if(this.map.getProjection() != this.ovmap.getProjection()) { + if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) { alert('The overview map only works when it is in the same projection as the main map'); } } var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent()); - this.setRectPxBounds(pxBounds); + if (pxBounds) { + this.setRectPxBounds(pxBounds); + } }, /** @@ -479,8 +491,12 @@ OpenLayers.Control.OverviewMap.prototype = lonLatBounds.top); var leftBottomPx = this.getOverviewPxFromLonLat(leftBottomLonLat); var rightTopPx = this.getOverviewPxFromLonLat(rightTopLonLat); - return new OpenLayers.Bounds(leftBottomPx.x, leftBottomPx.y, - rightTopPx.x, rightTopPx.y); + var bounds = null; + if (leftBottomPx && rightTopPx) { + bounds = new OpenLayers.Bounds(leftBottomPx.x, leftBottomPx.y, + rightTopPx.x, rightTopPx.y); + } + return bounds; }, /** @@ -530,10 +546,13 @@ OpenLayers.Control.OverviewMap.prototype = getOverviewPxFromLonLat: function(lonlat) { var res = this.ovmap.getResolution(); var extent = this.ovmap.getExtent(); - return new OpenLayers.Pixel( - Math.round(1/res * (lonlat.lon - extent.left)), - Math.round(1/res * (extent.top - lonlat.lat)) - ); + var px = null; + if (extent) { + px = new OpenLayers.Pixel( + Math.round(1/res * (lonlat.lon - extent.left)), + Math.round(1/res * (extent.top - lonlat.lat))); + } + return px; }, /** @final @type String */ diff --git a/lib/OpenLayers/Control/PanZoom.js b/lib/OpenLayers/Control/PanZoom.js index ad4b795174..b6f9116ef7 100644 --- a/lib/OpenLayers/Control/PanZoom.js +++ b/lib/OpenLayers/Control/PanZoom.js @@ -85,8 +85,8 @@ OpenLayers.Control.PanZoom.prototype = this.div.appendChild(btn); btn.onmousedown = this.buttonDown.bindAsEventListener(btn); + btn.onmouseup = this.doubleClick.bindAsEventListener(btn); btn.ondblclick = this.doubleClick.bindAsEventListener(btn); - btn.onclick = this.doubleClick.bindAsEventListener(btn); btn.action = id; btn.map = this.map; btn.slideFactor = this.slideFactor; diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index b929a58e27..ca90260c68 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -18,6 +18,15 @@ OpenLayers.Layer.prototype = { /** @type DOMElement */ div: null, + /** supported application event types + * + * @type Array */ + EVENT_TYPES: [ + "loadstart", "loadend", "loadcancel"], + + /** @type OpenLayers.Events */ + events: null, + /** This variable is set when the layer is added to the map, via the * accessor function setMap() * @@ -121,6 +130,8 @@ OpenLayers.Layer.prototype = { this.div.style.height = "100%"; this.div.id = this.id; } + + this.events = new OpenLayers.Events(this, this.div, this.EVENT_TYPES); }, /** @@ -135,6 +146,7 @@ OpenLayers.Layer.prototype = { this.name = null; this.div = null; this.options = null; + this.events = null; }, /** @@ -508,8 +520,8 @@ OpenLayers.Layer.prototype = { var center = this.map.getCenter(); var res = this.map.getResolution(); - var delta_x = viewPortPx.x - Math.ceil(size.w / 2); - var delta_y = viewPortPx.y - Math.ceil(size.h / 2); + var delta_x = viewPortPx.x - (size.w / 2); + var delta_y = viewPortPx.y - (size.h / 2); lonlat = new OpenLayers.LonLat(center.lon + delta_x * res , center.lat - delta_y * res); diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index 92efa46ff7..4634ef2ad7 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -30,7 +30,10 @@ OpenLayers.Layer.WMS.Untiled.prototype = /** @type OpenLayers.Tile.Image */ tile: null, - + + /** did the image finish loading before a new draw was initiated? + * @type Boolean */ + doneLoading: false, /** * @constructor @@ -63,8 +66,10 @@ OpenLayers.Layer.WMS.Untiled.prototype = * */ destroy: function() { - this.tile.destroy(); - this.tile = null; + if (this.tile) { + this.tile.destroy(); + this.tile = null; + } OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); }, @@ -108,6 +113,10 @@ OpenLayers.Layer.WMS.Untiled.prototype = * @param {Boolean} dragging */ moveTo:function(bounds, zoomChanged, dragging) { + if (!this.doneLoading) { + this.events.triggerEvent("loadcancel"); + this.doneLoading = true; + } OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this,arguments); if (bounds == null) { @@ -155,10 +164,18 @@ OpenLayers.Layer.WMS.Untiled.prototype = this.tile = null; } + this.events.triggerEvent("loadstart"); + this.doneLoading = false; if (!this.tile) { this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds, url, tileSize); this.tile.draw(); + var onload = function() { + this.doneLoading = true; + this.events.triggerEvent("loadend"); + } + OpenLayers.Event.observe(this.tile.imgDiv, 'load', + onload.bindAsEventListener(this)); } else { this.tile.moveTo(tileBounds, pos); } diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index e58a096869..c275564dce 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -321,7 +321,7 @@ OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL, var div = OpenLayers.Util.createDiv(); var img = OpenLayers.Util.createImage(null, null, null, null, null, null, - false); + null, false); div.appendChild(img); if (delayDisplay) { diff --git a/tests/grid_inittiles.html b/tests/grid_inittiles.html new file mode 100644 index 0000000000..78905d621d --- /dev/null +++ b/tests/grid_inittiles.html @@ -0,0 +1,32 @@ + + + + + + + +

Grid Test

+

Map should display with two centered tiles. If there appear to be a combination of two zoom levels, then this test is failed, and something is broken in OpenLayers.

+
+ +