| 451 | | |
|---|
| 452 | | |
|---|
| 453 | | /** |
|---|
| 454 | | * APIMethod: getBy |
|---|
| 455 | | * Get a list of objects given a property and a match item. |
|---|
| 456 | | * |
|---|
| 457 | | * Parameters: |
|---|
| 458 | | * array - {String} A property on the map whose value is an array. |
|---|
| 459 | | * property - {String} A property on each item of the given array. |
|---|
| 460 | | * match - {String | Object} A string to match. Can also be a regular |
|---|
| 461 | | * expression literal or object. In addition, it can be any object |
|---|
| 462 | | * with a method named test. For reqular expressions or other, if |
|---|
| 463 | | * match.test(map[array][i][property]) evaluates to true, the item will |
|---|
| 464 | | * be included in the array returned. If no items are found, an empty |
|---|
| 465 | | * array is returned. |
|---|
| 466 | | * |
|---|
| 467 | | * Returns: |
|---|
| 468 | | * {Array} An array of items where the given property matches the given |
|---|
| 469 | | * criteria. |
|---|
| 470 | | */ |
|---|
| 471 | | getBy: function(array, property, match) { |
|---|
| 472 | | var found = []; |
|---|
| 473 | | var item; |
|---|
| 474 | | var list = this[array]; |
|---|
| 475 | | var test = (typeof match.test == "function"); |
|---|
| 476 | | if(list instanceof Array) { |
|---|
| 477 | | for(var i=0; i<list.length; ++i) { |
|---|
| 478 | | item = list[i]; |
|---|
| 479 | | if(item[property] == match || |
|---|
| 480 | | (test && match.test(item[property]))) { |
|---|
| 481 | | found.push(item); |
|---|
| 482 | | } |
|---|
| 483 | | } |
|---|
| 484 | | } |
|---|
| 485 | | return found; |
|---|
| 486 | | }, |
|---|
| 487 | | |
|---|
| 488 | | /** |
|---|
| 489 | | * APIMethod: getLayersBy |
|---|
| 490 | | * Get a list of layers with properties matching the given criteria. |
|---|
| 491 | | * |
|---|
| 492 | | * Parameter: |
|---|
| 493 | | * property - {String} A layer property to be matched. |
|---|
| 494 | | * match - {String | Object} A string to match. Can also be a regular |
|---|
| 495 | | * expression literal or object. In addition, it can be any object |
|---|
| 496 | | * with a method named test. For reqular expressions or other, if |
|---|
| 497 | | * match.test(layer[property]) evaluates to true, the layer will be |
|---|
| 498 | | * included in the array returned. If no layers are found, an empty |
|---|
| 499 | | * array is returned. |
|---|
| 500 | | * |
|---|
| 501 | | * Returns: |
|---|
| 502 | | * {Array(<OpenLayers.Layer>)} A list of layers matching the given criteria. |
|---|
| 503 | | * An empty array is returned if no matches are found. |
|---|
| 504 | | */ |
|---|
| 505 | | getLayersBy: function(property, match) { |
|---|
| 506 | | return this.getBy("layers", property, match); |
|---|
| 507 | | }, |
|---|
| 508 | | |
|---|
| 509 | | /** |
|---|
| 510 | | * APIMethod: getLayersByName |
|---|
| 511 | | * Get a list of layers with names matching the given name. |
|---|
| 512 | | * |
|---|
| 513 | | * Parameter: |
|---|
| 514 | | * match - {String | Object} A layer name. The name can also be a regular |
|---|
| 515 | | * expression literal or object. In addition, it can be any object |
|---|
| 516 | | * with a method named test. For reqular expressions or other, if |
|---|
| 517 | | * name.test(layer.name) evaluates to true, the layer will be included |
|---|
| 518 | | * in the list of layers returned. If no layers are found, an empty |
|---|
| 519 | | * array is returned. |
|---|
| 520 | | * |
|---|
| 521 | | * Returns: |
|---|
| 522 | | * {Array(<OpenLayers.Layer>)} A list of layers matching the given name. |
|---|
| 523 | | * An empty array is returned if no matches are found. |
|---|
| 524 | | */ |
|---|
| 525 | | getLayersByName: function(match) { |
|---|
| 526 | | return this.getLayersBy("name", match); |
|---|
| 527 | | }, |
|---|
| 528 | | |
|---|
| 529 | | /** |
|---|
| 530 | | * APIMethod: getLayersByType |
|---|
| 531 | | * Get a list of layers of a given type (CLASS_NAME). |
|---|
| 532 | | * |
|---|
| 533 | | * Parameter: |
|---|
| 534 | | * match - {String | Object} A layer class name. The type can also be a |
|---|
| 535 | | * regular expression literal or object. In addition, it can be any |
|---|
| 536 | | * object with a method named test. For reqular expressions or other, |
|---|
| 537 | | * if type.test(layer.CLASS_NAME) evaluates to true, the layer will |
|---|
| 538 | | * be included in the list of layers returned. If no layers are |
|---|
| 539 | | * found, an empty array is returned. |
|---|
| 540 | | * |
|---|
| 541 | | * Returns: |
|---|
| 542 | | * {Array(<OpenLayers.Layer>)} A list of layers matching the given type. |
|---|
| 543 | | * An empty array is returned if no matches are found. |
|---|
| 544 | | */ |
|---|
| 545 | | getLayersByType: function(match) { |
|---|
| 546 | | return this.getLayersBy("CLASS_NAME", match); |
|---|
| 547 | | }, |
|---|
| 548 | | |
|---|
| 549 | | /** |
|---|
| 550 | | * APIMethod: getControlsBy |
|---|
| 551 | | * Get a list of controls with properties matching the given criteria. |
|---|
| 552 | | * |
|---|
| 553 | | * Parameter: |
|---|
| 554 | | * property - {String} A control property to be matched. |
|---|
| 555 | | * match - {String | Object} A string to match. Can also be a regular |
|---|
| 556 | | * expression literal or object. In addition, it can be any object |
|---|
| 557 | | * with a method named test. For reqular expressions or other, if |
|---|
| 558 | | * match.test(layer[property]) evaluates to true, the layer will be |
|---|
| 559 | | * included in the array returned. If no layers are found, an empty |
|---|
| 560 | | * array is returned. |
|---|
| 561 | | * |
|---|
| 562 | | * Returns: |
|---|
| 563 | | * {Array(<OpenLayers.Control>)} A list of controls matching the given |
|---|
| 564 | | * criteria. An empty array is returned if no matches are found. |
|---|
| 565 | | */ |
|---|
| 566 | | getControlsBy: function(property, match) { |
|---|
| 567 | | return this.getBy("controls", property, match); |
|---|
| 568 | | }, |
|---|
| 569 | | |
|---|
| 570 | | /** |
|---|
| 571 | | * APIMethod: getControlsByType |
|---|
| 572 | | * Get a list of controls of a given type (CLASS_NAME). |
|---|
| 573 | | * |
|---|
| 574 | | * Parameter: |
|---|
| 575 | | * match - {String | Object} A control class name. The type can also be a |
|---|
| 576 | | * regular expression literal or object. In addition, it can be any |
|---|
| 577 | | * object with a method named test. For reqular expressions or other, |
|---|
| 578 | | * if type.test(control.CLASS_NAME) evaluates to true, the control will |
|---|
| 579 | | * be included in the list of controls returned. If no controls are |
|---|
| 580 | | * found, an empty array is returned. |
|---|
| 581 | | * |
|---|
| 582 | | * Returns: |
|---|
| 583 | | * {Array(<OpenLayers.Control>)} A list of controls matching the given type. |
|---|
| 584 | | * An empty array is returned if no matches are found. |
|---|
| 585 | | */ |
|---|
| 586 | | getControlsByType: function(match) { |
|---|
| 587 | | return this.getControlsBy("CLASS_NAME", match); |
|---|
| 588 | | }, |
|---|