Project

General

Profile

1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
$Id: SetAoi.js 3052 2007-08-01 21:25:21Z ahocevar $
4
*/
5

    
6
// Ensure this object's dependancies are loaded.
7
mapbuilder.loadScript(baseDir+"/widget/ButtonBase.js");
8
mapbuilder.loadScript(baseDir+"/util/openlayers/OpenLayers.js");
9

    
10
/**
11
 * Set AOI button.
12
 * @base ButtonBase
13
 * @author Andreas Hocevar andreas.hocevarATgmail.com
14
 * @param widgetNode      The tool node from the Config XML file.
15
 * @param model  The ButtonBar widget.
16
 */
17
function SetAoi(widgetNode, model) {
18
   ButtonBase.apply(this, new Array(widgetNode, model));
19

    
20
  this.cursor = 'crosshair';
21

    
22
  /**
23
   * Interactive ZoomOut control.
24
   * @param objRef reference to this object.
25
   * @return {OpenLayers.Control} class of the OL control.
26
   */
27
  this.createControl = function(objRef) {
28
    var Control = OpenLayers.Class( OpenLayers.Control, {
29
      CLASS_NAME: 'mbControl.SetAoi',
30
      type: OpenLayers.Control.TYPE_TOOL,
31

    
32
      draw: function() {
33
        this.handler = new OpenLayers.Handler.Box( this,
34
              {done: this.aoiBox}, {keyMask: this.keyMask} );
35
      },
36

    
37
      aoiBox: function (position) {
38
        if (position instanceof OpenLayers.Bounds) {
39
          var minXY = this.map.getLonLatFromPixel(
40
               new OpenLayers.Pixel(position.left, position.bottom));
41
          var maxXY = this.map.getLonLatFromPixel(
42
               new OpenLayers.Pixel(position.right, position.top));
43
          var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
44
               maxXY.lon, maxXY.lat);
45
          var bboxOL = bounds.toBBOX().split(',');
46
          var ul = new Array(bboxOL[0],bboxOL[3]);
47
          var lr = new Array(bboxOL[2],bboxOL[1]);
48
          objRef.targetContext.setParam("aoi", new Array(ul, lr));
49
          objRef.drawAoiBox(objRef);
50
        }
51
      }
52
    });
53
 
54
    // adds a listener to the context to clear the AOI box when AOI changes
55
    this.targetContext.addListener('aoi', this.clearAoiBox, this);
56

    
57
    return Control;
58
  }
59

    
60
  /**
61
   * Draws a bounding box around the current AOI.
62
   * @param objRef reference to this widget
63
   */
64
  this.drawAoiBox = function(objRef) {
65
    var ext = objRef.targetContext.getParam('aoi');
66
    var bounds = new OpenLayers.Bounds(ext[0][0], ext[1][1], ext[1][0], ext[0][1]);
67
    objRef.targetContext.aoiBoxLayer = new OpenLayers.Layer.Boxes('Boxes');
68
    objRef.targetContext.map.addLayer(objRef.targetContext.aoiBoxLayer);
69
    var box = new OpenLayers.Marker.Box(bounds);
70
    objRef.targetContext.aoiBoxLayer.addMarker(box);
71
  }
72
  
73
  /**
74
   * Clears the AOI box.
75
   * @param objRef reference to this widget
76
   */
77
  this.clearAoiBox = function(objRef) {
78
    if (objRef.targetContext.aoiBoxLayer) {
79
      objRef.targetContext.aoiBoxLayer.destroy();
80
    }  
81
  }
82
}
(115-115/145)