"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
This commit is contained in:
ahocevar
2008-08-18 12:53:06 +00:00
parent 73eb0d5745
commit 8f45e0572e
3 changed files with 60 additions and 44 deletions

View File

@@ -154,12 +154,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
renderer: null, renderer: null,
/** /**
* APIProperty: yOrdering * APIProperty: rendererOptions
* {String} Whether or not externalGraphic y-ordering is enabled on this * {Object} Options for the renderer. See {<OpenLayers.Renderer>} for
* layer. Default is false. * supported options.
*/ */
yOrdering: false, rendererOptions: null,
/** /**
* APIProperty: geometryType * APIProperty: geometryType
* {String} geometryType allows you to limit the types of geometries this * {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<this.renderers.length; i++) { for (var i=0, len=this.renderers.length; i<this.renderers.length; i++) {
var rendererClass = OpenLayers.Renderer[this.renderers[i]]; var rendererClass = OpenLayers.Renderer[this.renderers[i]];
if (rendererClass && rendererClass.prototype.supported()) { if (rendererClass && rendererClass.prototype.supported()) {
this.renderer = new rendererClass(this.div, this.yOrdering); this.renderer = new rendererClass(this.div,
this.rendererOptions);
break; break;
} }
} }

View File

@@ -56,8 +56,10 @@ OpenLayers.Renderer = OpenLayers.Class({
* *
* Parameters: * Parameters:
* containerID - {<String>} * containerID - {<String>}
* options - {Object} options for this renderer. See sublcasses for
* supported options.
*/ */
initialize: function(containerID) { initialize: function(containerID, options) {
this.container = OpenLayers.Util.getElement(containerID); this.container = OpenLayers.Util.getElement(containerID);
}, },

View File

@@ -70,9 +70,18 @@ OpenLayers.ElementsIndexer = OpenLayers.Class({
* *
* Parameters: * Parameters:
* newNode - {DOMElement} The new node to be inserted. * 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; var nodeId = newNode.id;
this.determineZIndex(newNode); this.determineZIndex(newNode);
@@ -84,10 +93,8 @@ OpenLayers.ElementsIndexer = OpenLayers.Class({
while (rightIndex - leftIndex > 1) { while (rightIndex - leftIndex > 1) {
middle = parseInt((leftIndex + rightIndex) / 2); middle = parseInt((leftIndex + rightIndex) / 2);
var nextId = this.order[middle]; var placement = this.compare(this, newNode,
var nextNode = OpenLayers.Util.getElement(nextId); OpenLayers.Util.getElement(this.order[middle]));
var placement = this.compare(this, newNode, nextNode);
if (placement > 0) { if (placement > 0) {
leftIndex = middle; leftIndex = middle;
@@ -100,15 +107,11 @@ OpenLayers.ElementsIndexer = OpenLayers.Class({
this.indices[nodeId] = this.getZIndex(newNode); this.indices[nodeId] = this.getZIndex(newNode);
// If the new node should be before another in the index // If the new node should be before another in the index
// order, insert the new node before the next; else, lets just // order, return the node before which we have to insert the new one;
// append the new one on the end, making it the highest in the index order. // else, return null to indicate that the new node can be appended.
var nextIndex = rightIndex + 1; var nextIndex = rightIndex + 1;
if (nextIndex < this.order.length) { return nextIndex < this.order.length ?
var nextNode = OpenLayers.Util.getElement(this.order[nextIndex]); OpenLayers.Util.getElement(this.order[nextIndex]) : null;
root.insertBefore(newNode, nextNode);
} else {
root.appendChild(newNode);
}
}, },
/** /**
@@ -343,7 +346,8 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
/** /**
* Property: Indexer * Property: Indexer
* {<OpenLayers.ElementIndexer>} An instance of OpenLayers.ElementsIndexer * {<OpenLayers.ElementIndexer>} 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, indexer: null,
@@ -370,9 +374,12 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
* *
* Parameters: * Parameters:
* containerID - {String} * 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); OpenLayers.Renderer.prototype.initialize.apply(this, arguments);
this.rendererRoot = this.createRenderRoot(); this.rendererRoot = this.createRenderRoot();
@@ -381,7 +388,9 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
this.rendererRoot.appendChild(this.root); this.rendererRoot.appendChild(this.root);
this.container.appendChild(this.rendererRoot); 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.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._style = style;
newNode = this.drawGeometryNode(newNode, geometry, style); newNode = this.drawGeometryNode(newNode, geometry, style);
// If the node is known to the indexer, remove it so we can // Insert the node into the indexer so it can show us where to
// recalculate where it should go. // place it. Note that this operation is O(log(n)). If there's a
if (this.indexer.exists(newNode)) { // performance problem (when dragging, for instance) this is
this.indexer.remove(newNode); // 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); this.postDraw(newNode);
}, },
@@ -741,14 +752,16 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
} }
element.parentNode.removeChild(element); element.parentNode.removeChild(element);
this.indexer.remove(element); if (this.indexer) {
this.indexer.remove(element);
var backgroundId = geometry.id + this.BACKGROUND_ID_SUFFIX;
var bElem = OpenLayers.Util.getElement(backgroundId); var backgroundId = geometry.id + this.BACKGROUND_ID_SUFFIX;
if (bElem && bElem.parentNode) { var bElem = OpenLayers.Util.getElement(backgroundId);
// No need to destroy the geometry since the element and the background if (bElem && bElem.parentNode) {
// node share the same geometry. // No need to destroy the geometry since the element and the background
bElem.parentNode.removeChild(bElem); // node share the same geometry.
bElem.parentNode.removeChild(bElem);
}
} }
} }
} }