From aeff2e62df985fc95d4924022e1e2ed583cb8b75 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 22 May 2009 14:03:17 +0000 Subject: [PATCH] Pullups for OL 2.8 RC3. jQuery lib fix (Closes #1391) getRenderedSize regression (Closes #1906) element.scrolls error with panzoombar (Closes #2054) createUrlObject bug (Closes #2060) google layer in late rendered maps (Closes #2075) IE6/Lang.nb bug (Closes #2093) Layer.TMS/TileCache bugs (Closes #2099) (Closes #2100) Graphic names issues (Closes #2101) git-svn-id: http://svn.openlayers.org/branches/openlayers/2.8@9406 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Events.js | 21 +++++++++- lib/OpenLayers/Lang/nb.js | 3 +- lib/OpenLayers/Layer/Google.js | 12 +++--- lib/OpenLayers/Layer/TMS.js | 4 +- lib/OpenLayers/Layer/TileCache.js | 4 +- lib/OpenLayers/Map.js | 17 ++++---- lib/OpenLayers/Popup.js | 2 +- lib/OpenLayers/Renderer/SVG.js | 29 ++++++++------ lib/OpenLayers/Util.js | 58 +++++++++++++++++++++++---- tests/Layer/TMS.html | 10 +++-- tests/Layer/TileCache.html | 3 +- tests/Map.html | 20 +++++++-- tests/Util.html | 9 +++++ tests/manual/rendered-dimensions.html | 27 ++++++++++++- 14 files changed, 168 insertions(+), 51 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index ab806f23f1..bb0d954bf2 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -435,6 +435,14 @@ OpenLayers.Events = OpenLayers.Class({ */ includeXY: false, + /** + * Method: clearMouseListener + * A version of that is bound to this instance so that + * it can be used with and + * . + */ + clearMouseListener: null, + /** * Constructor: OpenLayers.Events * Construct an OpenLayers.Events object. @@ -458,6 +466,11 @@ OpenLayers.Events = OpenLayers.Class({ this.eventHandler = OpenLayers.Function.bindAsEventListener( this.handleBrowserEvent, this ); + + // to be used with observe and stopObserving + this.clearMouseListener = OpenLayers.Function.bind( + this.clearMouseCache, this + ); // if eventTypes is specified, create a listeners list for each // custom application event. @@ -481,6 +494,11 @@ OpenLayers.Events = OpenLayers.Class({ destroy: function () { if (this.element) { OpenLayers.Event.stopObservingElement(this.element); + if(this.element.hasScrollEvent) { + OpenLayers.Event.stopObserving( + window, "scroll", this.clearMouseListener + ); + } } this.element = null; @@ -773,8 +791,7 @@ OpenLayers.Events = OpenLayers.Class({ if (!this.includeXY) { this.clearMouseCache(); } else if (!this.element.hasScrollEvent) { - OpenLayers.Event.observe(window, 'scroll', - OpenLayers.Function.bind(this.clearMouseCache, this)); + OpenLayers.Event.observe(window, "scroll", this.clearMouseListener); this.element.hasScrollEvent = true; } diff --git a/lib/OpenLayers/Lang/nb.js b/lib/OpenLayers/Lang/nb.js index 1470567d3b..7c82469367 100644 --- a/lib/OpenLayers/Lang/nb.js +++ b/lib/OpenLayers/Lang/nb.js @@ -93,8 +93,7 @@ OpenLayers.Lang["nb"] = { "Denne innstillingen er foreldet, den var ment for å støtte " + "visning av kartdata over kommersielle bakgrunnskart, men det " + "bør nå gjøres med støtten for Spherical Mercator. Mer informasjon " + - "finnes på " + - "http://trac.openlayers.org/wiki/SphericalMercator.", + "finnes på http://trac.openlayers.org/wiki/SphericalMercator.", // console message 'methodDeprecated': diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 48d516cb89..f48c3f42ae 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -212,14 +212,14 @@ OpenLayers.Layer.Google = OpenLayers.Class( * evt - {Event} */ onMapResize: function() { - if(this.visibility) { + // workaround for resizing of invisible or not yet fully loaded layers + // where GMap2.checkResize() does not work. We need to load all tiles + // for the old div size, then checkResize(), and then call + // layer.moveTo() to trigger GMap.setCenter() (which will finish + // the GMap initialization). + if(this.visibility && this.mapObject.isLoaded()) { this.mapObject.checkResize(); } else { - // workaround for resizing of invisible layers where - // GMap2.checkResize() does not work. We need to load all tiles - // for the old div size, then checkResize(), and then call - // layer.moveTo() to trigger GMap.setCenter() (which will finish - // the GMap initialization). if(!this._resized) { var layer = this; var handle = GEvent.addListener(this.mapObject, "tilesloaded", function() { diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js index 08d5fca038..6a916e54e1 100644 --- a/lib/OpenLayers/Layer/TMS.js +++ b/lib/OpenLayers/Layer/TMS.js @@ -105,7 +105,9 @@ OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var res = this.map.getResolution(); var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h)); - var z = this.serverResolutions != null ? this.serverResolutions.indexOf(res) : this.map.getZoom(); + var z = this.serverResolutions != null ? + OpenLayers.Util.indexOf(this.serverResolutions, res) : + this.map.getZoom(); var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; var url = this.url; if (url instanceof Array) { diff --git a/lib/OpenLayers/Layer/TileCache.js b/lib/OpenLayers/Layer/TileCache.js index 7058c5da03..ddf6a7c714 100644 --- a/lib/OpenLayers/Layer/TileCache.js +++ b/lib/OpenLayers/Layer/TileCache.js @@ -105,7 +105,9 @@ OpenLayers.Layer.TileCache = OpenLayers.Class(OpenLayers.Layer.Grid, { var size = this.tileSize; var tileX = Math.round((bounds.left - bbox.left) / (res * size.w)); var tileY = Math.round((bounds.bottom - bbox.bottom) / (res * size.h)); - var tileZ = this.serverResolutions != null ? this.serverResolutions.indexOf(res) : this.map.getZoom(); + var tileZ = this.serverResolutions != null ? + OpenLayers.Util.indexOf(this.serverResolutions, res) : + this.map.getZoom(); /** * Zero-pad a positive integer. * number - {Int} diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 8019124b82..e8ae064108 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1661,13 +1661,16 @@ OpenLayers.Map = OpenLayers.Class({ var bounds = this.getExtent(); //send the move call to the baselayer and all the overlays - this.baseLayer.moveTo(bounds, zoomChanged, dragging); - if(dragging) { - this.baseLayer.events.triggerEvent("move"); - } else { - this.baseLayer.events.triggerEvent("moveend", - {"zoomChanged": zoomChanged} - ); + + if(this.baseLayer.visibility) { + this.baseLayer.moveTo(bounds, zoomChanged, dragging); + if(dragging) { + this.baseLayer.events.triggerEvent("move"); + } else { + this.baseLayer.events.triggerEvent("moveend", + {"zoomChanged": zoomChanged} + ); + } } bounds = this.baseLayer.getExtent(); diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index 99816fe8dc..76df7a4fc6 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -506,7 +506,7 @@ OpenLayers.Popup = OpenLayers.Class({ // contents into a fake contentDiv (for the CSS) and then measuring it var preparedHTML = "
" + this.contentDiv.innerHTML + - "
"; + "
"; var containerElement = (this.map) ? this.map.layerContainerDiv : document.body; diff --git a/lib/OpenLayers/Renderer/SVG.js b/lib/OpenLayers/Renderer/SVG.js index f3630f8c47..640447ebbf 100644 --- a/lib/OpenLayers/Renderer/SVG.js +++ b/lib/OpenLayers/Renderer/SVG.js @@ -291,23 +291,28 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { var href = "#" + id; pos = this.getPosition(node); widthFactor = this.symbolSize[id] / size; - // Only set the href if it is different from the current one. - // This is a workaround for strange rendering behavior in FF3. - if (node.getAttributeNS(this.xlinkns, "href") != href) { - node.setAttributeNS(this.xlinkns, "href", href); - } else if (size != parseFloat(node.getAttributeNS(null, "width"))) { - // hide the element (and force a reflow so it really gets - // hidden. This workaround is needed for Safari. - node.style.visibility = "hidden"; - this.container.scrollLeft = this.container.scrollLeft; + + // remove the node from the dom before we modify it. This + // prevents various rendering issues in Safari and FF + var parent = node.parentNode; + var nextSibling = node.nextSibling; + if(parent) { + parent.removeChild(node); } + + node.setAttributeNS(this.xlinkns, "href", href); node.setAttributeNS(null, "width", size); node.setAttributeNS(null, "height", size); node.setAttributeNS(null, "x", pos.x - offset); node.setAttributeNS(null, "y", pos.y - offset); - // set the visibility back to normal (after the Safari - // workaround above) - node.style.visibility = ""; + + // now that the node has all its new properties, insert it + // back into the dom where it was + if(nextSibling) { + parent.insertBefore(node, nextSibling); + } else if(parent) { + parent.appendChild(node); + } } else { node.setAttributeNS(null, "r", style.pointRadius); } diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index d31c1dc6fb..3a3ef27493 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -32,10 +32,10 @@ OpenLayers.Util.getElement = function() { }; /** - * Maintain $() from prototype + * Maintain existing definition of $. */ -if ($ == null) { - var $ = OpenLayers.Util.getElement; +if(typeof window.$ === "undefined") { + window.$ = OpenLayers.Util.getElement; } /** @@ -1346,7 +1346,21 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) { OpenLayers.Util.createUrlObject = function(url, options) { options = options || {}; - var urlObject = {}; + // deal with relative urls first + if(!(/^\w+:\/\//).test(url)) { + var loc = window.location; + var port = loc.port ? ":" + loc.port : ""; + var fullUrl = loc.protocol + "//" + loc.host + port; + if(url.indexOf("/") === 0) { + // full pathname + url = fullUrl + url; + } else { + // relative to current path + var parts = loc.pathname.split("/"); + parts.pop(); + url = fullUrl + parts.join("/") + "/" + url; + } + } if (options.ignoreCase) { url = url.toLowerCase(); @@ -1355,13 +1369,15 @@ OpenLayers.Util.createUrlObject = function(url, options) { var a = document.createElement('a'); a.href = url; + var urlObject = {}; + //host (without port) // if we don't have a host (which is the case with URLs starting with "/" // in IE), take the window location's host to match other browsers that // fill in the window's location host automatically urlObject.host = a.host || window.location.host; var port = a.port; - if (port.length <= 0) { + if (port.length > 0) { var newHostLength = urlObject.host.length - (port.length); urlObject.host = urlObject.host.substring(0, newHostLength); } @@ -1540,9 +1556,7 @@ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size, options) { // create temp container div with restricted size var container = document.createElement("div"); - container.style.overflow= ""; - container.style.position = "absolute"; - container.style.left = "-9999px"; + container.style.visibility = "hidden"; var containerElement = (options && options.containerElement) ? options.containerElement : document.body; @@ -1567,12 +1581,40 @@ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size, options) { var content = document.createElement("div"); content.innerHTML = contentHTML; + // we need overflow visible when calculating the size + content.style.overflow = "visible"; + if (content.childNodes) { + for (var i=0, l=content.childNodes.length; i -
+
diff --git a/tests/Layer/TileCache.html b/tests/Layer/TileCache.html index 216979e741..d24a44acc9 100644 --- a/tests/Layer/TileCache.html +++ b/tests/Layer/TileCache.html @@ -159,7 +159,8 @@ layer.serverResolutions = [14,13,12,11,10]; tileurl = layer.getURL(new OpenLayers.Bounds(0,0,0,0)); level = parseInt(tileurl.split('/')[2]); - t.eq(layer.serverResolutions.indexOf(map.getResolution()), level, "Tile zoom level is correct with serverResolutions"); + var gotLevel = OpenLayers.Util.indexOf(layer.serverResolutions, map.getResolution()); + t.eq(gotLevel, level, "Tile zoom level is correct with serverResolutions"); map.destroy(); } diff --git a/tests/Map.html b/tests/Map.html index b5273c245e..807907a6e2 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1212,24 +1212,27 @@ function test_allOverlays(t) { - t.plan(14); - + t.plan(16); + var map = new OpenLayers.Map({ div: "map", allOverlays: true }); - var a = new OpenLayers.Layer.Vector("a"); + var a = new OpenLayers.Layer.Vector("a", {visibility: true}); + var b = new OpenLayers.Layer.Image( "b", "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", new OpenLayers.Bounds(-180, -88.759, 180, 88.759), new OpenLayers.Size(580, 288) ); + var c = new OpenLayers.Layer.WMS( "c", "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); + var d = new OpenLayers.Layer.Vector("d"); map.addLayers([a, b, c, d]); @@ -1243,6 +1246,14 @@ map.zoomToMaxExtent(); t.eq(moveCount, 1, "map.moveTo moves the base layer only once"); t.eq(map.getCenter().toString(), "lon=0,lat=0", "a map with all overlays can have a center"); + + a.setVisibility(false); + var moveend = 0; + a.events.on({"moveend": function() { moveend++; }}); + map.zoomToMaxExtent(); + t.eq(moveCount, 1, "map.moveTo does not move the base layer if it is invisible"); + t.eq(moveend, 0, "map.moveTo does not trigger \"moveend\" in the layer if the layer is invisible"); + a.setVisibility(true); // a, b, c, d t.eq(map.baseLayer.name, "a", "base layer set to first layer added"); @@ -1281,7 +1292,8 @@ b.setVisibility(false); map.setLayerIndex(b, 0); t.eq(b.visibility, false, "changing layer order doesn't change visibility"); - + + map.destroy(); } diff --git a/tests/Util.html b/tests/Util.html index 9d0982933c..4ad9a59d6a 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -1,10 +1,19 @@ +