renaming getLayersByType and getControlsByType to getLayersByClass and getControlsByClass - since controls have a type property, we want to leave room for a real getControlsByType - thanks for the review elem (closes #1153).

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5387 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-12-12 20:17:30 +00:00
parent 00d6f66c06
commit ac1f51a19a
2 changed files with 30 additions and 30 deletions

View File

@@ -527,11 +527,11 @@ OpenLayers.Map = OpenLayers.Class({
}, },
/** /**
* APIMethod: getLayersByType * APIMethod: getLayersByClass
* Get a list of layers of a given type (CLASS_NAME). * Get a list of layers of a given class (CLASS_NAME).
* *
* Parameter: * Parameter:
* match - {String | Object} A layer class name. The type can also be a * match - {String | Object} A layer class name. The match can also be a
* regular expression literal or object. In addition, it can be any * regular expression literal or object. In addition, it can be any
* object with a method named test. For reqular expressions or other, * object with a method named test. For reqular expressions or other,
* if type.test(layer.CLASS_NAME) evaluates to true, the layer will * if type.test(layer.CLASS_NAME) evaluates to true, the layer will
@@ -539,10 +539,10 @@ OpenLayers.Map = OpenLayers.Class({
* found, an empty array is returned. * found, an empty array is returned.
* *
* Returns: * Returns:
* {Array(<OpenLayers.Layer>)} A list of layers matching the given type. * {Array(<OpenLayers.Layer>)} A list of layers matching the given class.
* An empty array is returned if no matches are found. * An empty array is returned if no matches are found.
*/ */
getLayersByType: function(match) { getLayersByClass: function(match) {
return this.getLayersBy("CLASS_NAME", match); return this.getLayersBy("CLASS_NAME", match);
}, },
@@ -568,11 +568,11 @@ OpenLayers.Map = OpenLayers.Class({
}, },
/** /**
* APIMethod: getControlsByType * APIMethod: getControlsByClass
* Get a list of controls of a given type (CLASS_NAME). * Get a list of controls of a given class (CLASS_NAME).
* *
* Parameter: * Parameter:
* match - {String | Object} A control class name. The type can also be a * match - {String | Object} A control class name. The match can also be a
* regular expression literal or object. In addition, it can be any * regular expression literal or object. In addition, it can be any
* object with a method named test. For reqular expressions or other, * object with a method named test. For reqular expressions or other,
* if type.test(control.CLASS_NAME) evaluates to true, the control will * if type.test(control.CLASS_NAME) evaluates to true, the control will
@@ -580,10 +580,10 @@ OpenLayers.Map = OpenLayers.Class({
* found, an empty array is returned. * found, an empty array is returned.
* *
* Returns: * Returns:
* {Array(<OpenLayers.Control>)} A list of controls matching the given type. * {Array(<OpenLayers.Control>)} A list of controls matching the given class.
* An empty array is returned if no matches are found. * An empty array is returned if no matches are found.
*/ */
getControlsByType: function(match) { getControlsByClass: function(match) {
return this.getControlsBy("CLASS_NAME", match); return this.getControlsBy("CLASS_NAME", match);
}, },

View File

@@ -375,12 +375,12 @@
} }
function test_Map_getLayersByType(t) { function test_Map_getLayersByClass(t) {
var map = { var map = {
getBy: OpenLayers.Map.prototype.getBy, getBy: OpenLayers.Map.prototype.getBy,
getLayersBy: OpenLayers.Map.prototype.getLayersBy, getLayersBy: OpenLayers.Map.prototype.getLayersBy,
getLayersByType: OpenLayers.Map.prototype.getLayersByType, getLayersByClass: OpenLayers.Map.prototype.getLayersByClass,
layers: [ layers: [
{CLASS_NAME: "foo", id: Math.random()}, {CLASS_NAME: "foo", id: Math.random()},
{CLASS_NAME: "bar", id: Math.random()}, {CLASS_NAME: "bar", id: Math.random()},
@@ -392,35 +392,35 @@
var cases = [ var cases = [
{ {
got: map.getLayersByType("foo"), got: map.getLayersByClass("foo"),
expected: [map.layers[0], map.layers[4]], expected: [map.layers[0], map.layers[4]],
message: "(string literal) got two layers matching type" message: "(string literal) got two layers matching type"
}, { }, {
got: map.getLayersByType("bar"), got: map.getLayersByClass("bar"),
expected: [map.layers[1]], expected: [map.layers[1]],
message: "(string literal) got one layer matching type" message: "(string literal) got one layer matching type"
}, { }, {
got: map.getLayersByType("barfoo"), got: map.getLayersByClass("barfoo"),
expected: [], expected: [],
message: "(string literal) got empty array for no match" message: "(string literal) got empty array for no match"
}, { }, {
got: map.getLayersByType(/foo/), got: map.getLayersByClass(/foo/),
expected: [map.layers[0], map.layers[2], map.layers[3], map.layers[4]], expected: [map.layers[0], map.layers[2], map.layers[3], map.layers[4]],
message: "(regexp literal) got three layers containing string" message: "(regexp literal) got three layers containing string"
}, { }, {
got: map.getLayersByType(/foo$/), got: map.getLayersByClass(/foo$/),
expected: [map.layers[0], map.layers[4]], expected: [map.layers[0], map.layers[4]],
message: "(regexp literal) got three layers ending with string" message: "(regexp literal) got three layers ending with string"
}, { }, {
got: map.getLayersByType(/\s/), got: map.getLayersByClass(/\s/),
expected: [map.layers[3]], expected: [map.layers[3]],
message: "(regexp literal) got layer containing space" message: "(regexp literal) got layer containing space"
}, { }, {
got: map.getLayersByType(new RegExp("BAR", "i")), got: map.getLayersByClass(new RegExp("BAR", "i")),
expected: [map.layers[1], map.layers[2], map.layers[3]], expected: [map.layers[1], map.layers[2], map.layers[3]],
message: "(regexp object) got layers ignoring case" message: "(regexp object) got layers ignoring case"
}, { }, {
got: map.getLayersByType({test: function(str) {return str.length > 3;}}), got: map.getLayersByClass({test: function(str) {return str.length > 3;}}),
expected: [map.layers[2], map.layers[3]], expected: [map.layers[2], map.layers[3]],
message: "(custom object) got layers with type length greater than 3" message: "(custom object) got layers with type length greater than 3"
} }
@@ -488,12 +488,12 @@
} }
function test_Map_getControlsByType(t) { function test_Map_getControlsByClass(t) {
var map = { var map = {
getBy: OpenLayers.Map.prototype.getBy, getBy: OpenLayers.Map.prototype.getBy,
getControlsBy: OpenLayers.Map.prototype.getControlsBy, getControlsBy: OpenLayers.Map.prototype.getControlsBy,
getControlsByType: OpenLayers.Map.prototype.getControlsByType, getControlsByClass: OpenLayers.Map.prototype.getControlsByClass,
controls: [ controls: [
{CLASS_NAME: "foo", id: Math.random()}, {CLASS_NAME: "foo", id: Math.random()},
{CLASS_NAME: "bar", id: Math.random()}, {CLASS_NAME: "bar", id: Math.random()},
@@ -505,35 +505,35 @@
var cases = [ var cases = [
{ {
got: map.getControlsByType("foo"), got: map.getControlsByClass("foo"),
expected: [map.controls[0], map.controls[4]], expected: [map.controls[0], map.controls[4]],
message: "(string literal) got two controls matching type" message: "(string literal) got two controls matching type"
}, { }, {
got: map.getControlsByType("bar"), got: map.getControlsByClass("bar"),
expected: [map.controls[1]], expected: [map.controls[1]],
message: "(string literal) got one control matching type" message: "(string literal) got one control matching type"
}, { }, {
got: map.getControlsByType("barfoo"), got: map.getControlsByClass("barfoo"),
expected: [], expected: [],
message: "(string literal) got empty array for no match" message: "(string literal) got empty array for no match"
}, { }, {
got: map.getControlsByType(/foo/), got: map.getControlsByClass(/foo/),
expected: [map.controls[0], map.controls[2], map.controls[3], map.controls[4]], expected: [map.controls[0], map.controls[2], map.controls[3], map.controls[4]],
message: "(regexp literal) got three controls containing string" message: "(regexp literal) got three controls containing string"
}, { }, {
got: map.getControlsByType(/foo$/), got: map.getControlsByClass(/foo$/),
expected: [map.controls[0], map.controls[4]], expected: [map.controls[0], map.controls[4]],
message: "(regexp literal) got three controls ending with string" message: "(regexp literal) got three controls ending with string"
}, { }, {
got: map.getControlsByType(/\s/), got: map.getControlsByClass(/\s/),
expected: [map.controls[3]], expected: [map.controls[3]],
message: "(regexp literal) got control containing space" message: "(regexp literal) got control containing space"
}, { }, {
got: map.getControlsByType(new RegExp("BAR", "i")), got: map.getControlsByClass(new RegExp("BAR", "i")),
expected: [map.controls[1], map.controls[2], map.controls[3]], expected: [map.controls[1], map.controls[2], map.controls[3]],
message: "(regexp object) got controls ignoring case" message: "(regexp object) got controls ignoring case"
}, { }, {
got: map.getControlsByType({test: function(str) {return str.length > 3;}}), got: map.getControlsByClass({test: function(str) {return str.length > 3;}}),
expected: [map.controls[2], map.controls[3]], expected: [map.controls[2], map.controls[3]],
message: "(custom object) got controls with type length greater than 3" message: "(custom object) got controls with type length greater than 3"
} }