[OpenLayers-Commits] r7316 - in sandbox/topp/almanac/lib: . OpenLayers/Control
commits at openlayers.org
commits at openlayers.org
Thu Jun 5 22:12:30 EDT 2008
Author: sbenthall
Date: 2008-06-05 22:12:30 -0400 (Thu, 05 Jun 2008)
New Revision: 7316
Added:
sandbox/topp/almanac/lib/OpenLayers/Control/ToolSwitch.js
Modified:
sandbox/topp/almanac/lib/OpenLayers.js
Log:
ToolSwitch control
Added: sandbox/topp/almanac/lib/OpenLayers/Control/ToolSwitch.js
===================================================================
--- sandbox/topp/almanac/lib/OpenLayers/Control/ToolSwitch.js (rev 0)
+++ sandbox/topp/almanac/lib/OpenLayers/Control/ToolSwitch.js 2008-06-06 02:12:30 UTC (rev 7316)
@@ -0,0 +1,107 @@
+
+/**
+ * @requires OpenLayers/Control.js
+ */
+
+/**
+ * Class: OpenLayers.Control.ToolSwitch
+ *
+ * Inherits from:
+ * - <OpenLayers.Control>
+ */
+OpenLayers.Control.ToolSwitch = new OpenLayers.Class(OpenLayers.Control, {
+
+ /**
+ * Property: layer
+ * {<OpenLayers.Layer>}
+ */
+ layer: null,
+
+ /**
+ * Property: tools
+ * {Object} A hash where keys are strings and values are controls.
+ */
+
+ tools: null,
+
+ /**
+ * Property: defaultTool
+ * {String} The name of the default tool.
+ */
+
+ defaultTool : null,
+
+ /**
+ * Constructor: OpenLayers.Control.ToolSwitch
+ * Create a new control that switches between other "tool" controls.
+ *
+ * Parameters:
+ * layer - {OpenLayers.Layer}
+ * tools - {Object} A hash where keys are strings and values are controls.
+ * options - {Object}
+ */
+ initialize: function(layer, tools, options) {
+ OpenLayers.Control.prototype.initialize.apply(this, [options]);
+
+ this.layer = layer;
+
+ this.tools = tools;
+ },
+
+ activate: function(){
+ OpenLayers.Control.prototype.activate.apply(this, arguments);
+ if(this.defaultTool){
+ this.switchTool(this.defaultTool);
+ }
+ },
+
+ deactivate: function(){
+ this.switchTool(null);
+ OpenLayers.Control.prototype.deactivate.apply(this, arguments);
+ },
+
+ destroy: function(){
+ this.layer = null;
+ this.tools = null;
+
+ OpenLayers.Control.prototype.destroy.apply(this, arguments);
+ },
+
+ switchTool: function(name) {
+ if(!this.active){
+ return;
+ }
+
+ for(var key in this.tools) {
+ var tool = this.tools[key];
+ if(name == key) {
+ tool.activate();
+ } else {
+ tool.deactivate();
+ }
+ }
+ },
+
+ /**
+ * Method: setMap
+ * Set the map property for the control and all controls it owns.
+ *
+ * Parameters:
+ * map - {<OpenLayers.Map>} The control's map.
+ */
+ setMap: function(map) {
+ for(var key in this.tools){
+ this.tools[key].setMap(map);
+ }
+ OpenLayers.Control.prototype.setMap.apply(this, arguments);
+ },
+
+ onToolActivateBehavior: function(tool, scope, behavior){
+ this.tools[tool].events.on({
+ "activate" : behavior,
+ scope : scope
+ })
+ },
+
+ CLASS_NAME: "OpenLayers.Control.ToolSwitch"
+});
Modified: sandbox/topp/almanac/lib/OpenLayers.js
===================================================================
--- sandbox/topp/almanac/lib/OpenLayers.js 2008-06-06 02:12:13 UTC (rev 7315)
+++ sandbox/topp/almanac/lib/OpenLayers.js 2008-06-06 02:12:30 UTC (rev 7316)
@@ -162,6 +162,7 @@
"OpenLayers/Control/ModifyFeature.js",
"OpenLayers/Control/Panel.js",
"OpenLayers/Control/Radio.js",
+ "OpenLayers/Control/ToolSwitch.js",
"OpenLayers/Control/SelectFeature.js",
"OpenLayers/Control/NavigationHistory.js",
"OpenLayers/Control/Geocoder.js",
More information about the Commits
mailing list