1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
6 * @requires OpenLayers/Layer/Vector.js
10 * Class: OpenLayers.Layer.Vector.RootContainer
11 * A special layer type to combine multiple vector layers inside a single
12 * renderer root container. This class is not supposed to be instantiated
13 * from user space, it is a helper class for controls that require event
14 * processing for multiple vector layers.
17 * - <OpenLayers.Layer.Vector>
19 OpenLayers.Layer.Vector.RootContainer = OpenLayers.Class(OpenLayers.Layer.Vector, {
22 * Property: displayInLayerSwitcher
23 * Set to false for this layer type
25 displayInLayerSwitcher: false,
29 * Layers that are attached to this container. Required config option.
34 * Constructor: OpenLayers.Layer.Vector.RootContainer
35 * Create a new root container for multiple vector layer. This constructor
36 * is not supposed to be used from user space, it is only to be used by
37 * controls that need feature selection across multiple vector layers.
40 * name - {String} A name for the layer
41 * options - {Object} Optional object with non-default properties to set on
44 * Required options properties:
45 * layers - {Array(<OpenLayers.Layer.Vector>)} The layers managed by this
49 * {<OpenLayers.Layer.Vector.RootContainer>} A new vector layer root
52 initialize: function(name, options) {
53 OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments);
59 display: function() {},
62 * Method: getFeatureFromEvent
63 * walk through the layers to find the feature returned by the event
66 * evt - {Object} event object with a feature property
69 * {<OpenLayers.Feature.Vector>}
71 getFeatureFromEvent: function(evt) {
72 var layers = this.layers;
74 for(var i=0; i<layers.length; i++) {
75 feature = layers[i].getFeatureFromEvent(evt);
86 * map - {<OpenLayers.Map>}
88 setMap: function(map) {
89 OpenLayers.Layer.Vector.prototype.setMap.apply(this, arguments);
91 map.events.register("changelayer", this, this.handleChangeLayer);
98 * map - {<OpenLayers.Map>}
100 removeMap: function(map) {
101 map.events.unregister("changelayer", this, this.handleChangeLayer);
103 OpenLayers.Layer.Vector.prototype.removeMap.apply(this, arguments);
107 * Method: collectRoots
108 * Collects the root nodes of all layers this control is configured with
109 * and moveswien the nodes to this control's layer
111 collectRoots: function() {
113 // walk through all map layers, because we want to keep the order
114 for(var i=0; i<this.map.layers.length; ++i) {
115 layer = this.map.layers[i];
116 if(OpenLayers.Util.indexOf(this.layers, layer) != -1) {
117 layer.renderer.moveRoot(this.renderer);
124 * Resets the root nodes back into the layers they belong to.
126 resetRoots: function() {
128 for(var i=0; i<this.layers.length; ++i) {
129 layer = this.layers[i];
130 if(this.renderer && layer.renderer.getRenderLayerId() == this.id) {
131 this.renderer.moveRoot(layer.renderer);
137 * Method: handleChangeLayer
138 * Event handler for the map's changelayer event. We need to rebuild
139 * this container's layer dom if order of one of its layers changes.
140 * This handler is added with the setMap method, and removed with the
146 handleChangeLayer: function(evt) {
147 var layer = evt.layer;
148 if(evt.property == "order" &&
149 OpenLayers.Util.indexOf(this.layers, layer) != -1) {
155 CLASS_NAME: "OpenLayers.Layer.Vector.RootContainer"