From 8f45e0572eeb970dd1a798e6780279fd46d12185 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 18 Aug 2008 12:53:06 +0000 Subject: [PATCH] "disable z-indexing of elements in the Elements renderer by default". r=elemoine (closes #1679) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7781 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Vector.js | 13 +++-- lib/OpenLayers/Renderer.js | 4 +- lib/OpenLayers/Renderer/Elements.js | 87 +++++++++++++++++------------ 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index 52fadd687a..392b1a28ab 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -154,12 +154,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { renderer: null, /** - * APIProperty: yOrdering - * {String} Whether or not externalGraphic y-ordering is enabled on this - * layer. Default is false. + * APIProperty: rendererOptions + * {Object} Options for the renderer. See {} for + * supported options. */ - yOrdering: false, - + rendererOptions: null, + /** * APIProperty: geometryType * {String} geometryType allows you to limit the types of geometries this @@ -265,7 +265,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { for (var i=0, len=this.renderers.length; i} + * options - {Object} options for this renderer. See sublcasses for + * supported options. */ - initialize: function(containerID) { + initialize: function(containerID, options) { this.container = OpenLayers.Util.getElement(containerID); }, diff --git a/lib/OpenLayers/Renderer/Elements.js b/lib/OpenLayers/Renderer/Elements.js index f40120cc2e..8604a27c60 100644 --- a/lib/OpenLayers/Renderer/Elements.js +++ b/lib/OpenLayers/Renderer/Elements.js @@ -70,9 +70,18 @@ OpenLayers.ElementsIndexer = OpenLayers.Class({ * * Parameters: * newNode - {DOMElement} The new node to be inserted. - * root - {DOMElement} The root node from which to insert the new node. + * + * Returns + * {DOMElement} the node before which we should insert our newNode, or + * null if newNode can just be appended. */ - insert: function(newNode, root) { + insert: function(newNode) { + // If the node is known to the indexer, remove it so we can + // recalculate where it should go. + if (this.exists(newNode)) { + this.remove(newNode); + } + var nodeId = newNode.id; this.determineZIndex(newNode); @@ -84,10 +93,8 @@ OpenLayers.ElementsIndexer = OpenLayers.Class({ while (rightIndex - leftIndex > 1) { middle = parseInt((leftIndex + rightIndex) / 2); - var nextId = this.order[middle]; - var nextNode = OpenLayers.Util.getElement(nextId); - - var placement = this.compare(this, newNode, nextNode); + var placement = this.compare(this, newNode, + OpenLayers.Util.getElement(this.order[middle])); if (placement > 0) { leftIndex = middle; @@ -100,15 +107,11 @@ OpenLayers.ElementsIndexer = OpenLayers.Class({ this.indices[nodeId] = this.getZIndex(newNode); // If the new node should be before another in the index - // order, insert the new node before the next; else, lets just - // append the new one on the end, making it the highest in the index order. + // order, return the node before which we have to insert the new one; + // else, return null to indicate that the new node can be appended. var nextIndex = rightIndex + 1; - if (nextIndex < this.order.length) { - var nextNode = OpenLayers.Util.getElement(this.order[nextIndex]); - root.insertBefore(newNode, nextNode); - } else { - root.appendChild(newNode); - } + return nextIndex < this.order.length ? + OpenLayers.Util.getElement(this.order[nextIndex]) : null; }, /** @@ -343,7 +346,8 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { /** * Property: Indexer * {} An instance of OpenLayers.ElementsIndexer - * created upon initialization. + * created upon initialization if the zIndexing or yOrdering options + * passed to this renderer's constructor are set to true. */ indexer: null, @@ -370,9 +374,12 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { * * Parameters: * containerID - {String} - * yOrdering - {Boolean} Whether or not y-ordering is enabled. + * options - {Object} options for this renderer. Supported options are: + * * yOrdering - {Boolean} Whether to use y-ordering + * * zIndexing - {Boolean} Whether to use z-indexing. Will be ignored + * if yOrdering is set to true. */ - initialize: function(containerID, yOrdering) { + initialize: function(containerID, options) { OpenLayers.Renderer.prototype.initialize.apply(this, arguments); this.rendererRoot = this.createRenderRoot(); @@ -381,7 +388,9 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { this.rendererRoot.appendChild(this.root); this.container.appendChild(this.rendererRoot); - this.indexer = new OpenLayers.ElementsIndexer(yOrdering); + if(options && (options.zIndexing || options.yOrdering)) { + this.indexer = new OpenLayers.ElementsIndexer(options.yOrdering); + } }, /** @@ -408,7 +417,9 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { this.root.removeChild(this.root.firstChild); } } - this.indexer.clear(); + if (this.indexer) { + this.indexer.clear(); + } }, /** @@ -497,18 +508,18 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { newNode._style = style; newNode = this.drawGeometryNode(newNode, geometry, style); - // If the node is known to the indexer, remove it so we can - // recalculate where it should go. - if (this.indexer.exists(newNode)) { - this.indexer.remove(newNode); + // Insert the node into the indexer so it can show us where to + // place it. Note that this operation is O(log(n)). If there's a + // performance problem (when dragging, for instance) this is + // likely where it would be. + var insert = this.indexer ? this.indexer.insert(newNode) : null; + + if(insert) { + this.root.insertBefore(newNode, insert); + } else { + this.root.appendChild(newNode); } - // Insert the node into the indexer so it can show us where to place it. - // Note that this operation is O(log(n)). If there's a performance - // problem (when dragging, for instance) this is likely where it - // would be. - this.indexer.insert(newNode, this.root); - this.postDraw(newNode); }, @@ -741,14 +752,16 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, { } element.parentNode.removeChild(element); - this.indexer.remove(element); - - var backgroundId = geometry.id + this.BACKGROUND_ID_SUFFIX; - var bElem = OpenLayers.Util.getElement(backgroundId); - if (bElem && bElem.parentNode) { - // No need to destroy the geometry since the element and the background - // node share the same geometry. - bElem.parentNode.removeChild(bElem); + if (this.indexer) { + this.indexer.remove(element); + + var backgroundId = geometry.id + this.BACKGROUND_ID_SUFFIX; + var bElem = OpenLayers.Util.getElement(backgroundId); + if (bElem && bElem.parentNode) { + // No need to destroy the geometry since the element and the background + // node share the same geometry. + bElem.parentNode.removeChild(bElem); + } } } }