Project

General

Profile

1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
Dependancies: Context
4
$Id: ZoomToAoi.js 3821 2008-02-01 13:58:30Z ahocevar $
5
*/
6

    
7
// Ensure this object's dependancies are loaded.
8
mapbuilder.loadScript(baseDir+"/tool/ToolBase.js");
9

    
10
/**
11
 * Controller for the locator map widget.  
12
 * Specify the context that this widget follows by setting the targetModel 
13
 * property in config.
14
 * This will display the AOI of the target model using the AoiBox tool. 
15
 * This will also process mouse events (click and dragbox) to recenter the 
16
 * target model and includes coordinate projection transformations if required.
17
 * Checking for extent limits is not yet implemented.
18
 * 
19
 * WARNING: it is recommended to use the OverviewMap widget. However since the behavior
20
 * is slightly different from this widget, this one is still available.
21
 * See also MAP-300
22
 * @deprecated
23
 * @constructor
24
 * @base ToolBase
25
 * @author Adair
26
 * @param toolNode      The tool node from the config document for this tool
27
 * @param model  Reference to the widget object that creates this tool
28
 */
29
function ZoomToAoi(toolNode, model) {
30
  ToolBase.apply(this, new Array(toolNode, model));
31

    
32
  /**
33
   * Target model loadModel change listener.  This resets the projection objects
34
   * if the target model changes.
35
   * @param tool        Pointer to this ZoomToAoi object.
36
   */
37
  this.initProj = function( toolRef ) {
38
    if( toolRef.model.doc && toolRef.targetModel.doc ) {
39
      if ( toolRef.model.getSRS() != toolRef.targetModel.getSRS() ) {
40
          toolRef.model.proj = new OpenLayers.Projection( toolRef.model.getSRS() );
41
          toolRef.targetModel.proj = new OpenLayers.Projection( toolRef.targetModel.getSRS() );
42
      }
43
    }
44
  }
45
  this.setListeners = function( toolRef ) {
46
    toolRef.model.addListener( "loadModel", toolRef.initProj, toolRef );
47
    toolRef.targetModel.addListener( "loadModel", toolRef.initProj, toolRef );
48
    toolRef.initProj( toolRef );
49
  }
50
  this.model.addListener( "loadModel", this.setListeners, this);
51

    
52
  /**
53
   * Target model bbox change listener.  This sets this model's AOI to be the
54
   * same as the target model bounding box.
55
   * @param tool        Pointer to this ZoomToAoi object.
56
   */
57
  this.showTargetAoi = function( tool ) {
58
    if( tool.targetModel.doc ) {
59
      var bbox = tool.targetModel.getBoundingBox();  
60
      var ul = new Array(bbox[0],bbox[3]);
61
      var lr = new Array(bbox[2],bbox[1]);
62
      if ( tool.model.getSRS() != tool.targetModel.getSRS() ) {
63
        var ptUL=new OpenLayers.Geometry.Point(ul[0],ul[1]);
64
        var ptLR=new OpenLayers.Geometry.Point(lr[0],lr[1]);
65
        ptUL.transform(tool.targetModel.proj,tool.model.proj);
66
        ptLR.transform(tool.targetModel.proj,tool.model.proj);
67
        ul = new Array(ptUL.x,ptUL.y);
68
        lr = new Array(ptLR.x,ptLR.y);      
69
        
70
      }
71
      tool.model.setParam("aoi", new Array(ul, lr) );
72
    }
73
  }
74
  
75
  this.firstInit = function(tool) {
76
    tool.model.map.events.register('mouseup',tool, tool.mouseUpHandler);
77
    tool.targetModel.addListener( "loadModel", tool.showTargetAoi, tool );
78
    tool.targetModel.addListener( "bbox", tool.showTargetAoi, tool );
79
    tool.showTargetAoi(tool);
80
  }
81
  this.model.addListener( "loadModel", this.firstInit, this );
82
  
83
  this.clear = function(tool) {
84
    if (tool.model.map && tool.model.map.events) {
85
      tool.model.map.events.unregister('mouseup',tool, tool.mouseUpHandler);
86
    }
87
  }
88
  this.model.addListener("clearModel", this.clear, this);
89
}
90

    
91
/**
92
 * Process a mouse up action.  This will recenter the target model's bbox
93
 * to be equal to this model's AOI.
94
 * @param e OpenLayers event
95
 */
96
ZoomToAoi.prototype.mouseUpHandler = function(e) {
97
  var bbox = this.model.getParam("aoi");
98
  var ul = bbox[0];
99
  var lr = bbox[1];
100
  if ( this.model.getSRS() != this.targetModel.getSRS() ) {
101
    //TBD: convert XY to lat/long first
102
      var ptUL=new OpenLayers.Geometry.Point(ul[0],ul[1]);
103
      var ptLR=new OpenLayers.Geometry.Point(lr[0],lr[1]);
104
      ptUL.transform(this.model.proj,this.targetModel.proj);
105
      ptLR.transform(this.model.proj,this.targetModel.proj);
106
      ul = new Array(ptUL.x,ptUL.y);
107
      lr = new Array(ptLR.x,ptLR.y);    
108
  }
109
  if ( ( ul[0]==lr[0] ) && ( ul[1]==lr[1] ) ) {
110
    this.targetModel.map.setCenter(new OpenLayers.LonLat(ul[0],ul[1]));
111
  } else {
112
    this.targetModel.map.zoomToExtent(new OpenLayers.Bounds(ul[0], lr[1], lr[0], ul[1]));
113
  }
114
}
(15-15/15)