Project

General

Profile

1
/*
2
Author:       Mike Adair mike.adairATccrs.nrcan.gc.ca
3
License:      LGPL as per: http://www.gnu.org/copyleft/lesser.html
4

    
5
$Id$
6
*/
7

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

    
11
/**
12
 * Tool which implements a click and drag behaviour to set the 
13
 * Area Of Interest on the model from mouse events.
14
 * The tool must be enabled before use by calling tool.enable(true);
15
 * This tool registers mouse event listeners on the parent model.
16
 * This tool processes screen coordinates and stores AOI in the current map
17
 * projection coordinates.
18
 * @constructor
19
 * @base ToolBase
20
 * @param toolNode The node for this tool from the configuration document.
21
 * @param model  The model object that contains this tool
22
 */
23

    
24
function AoiMouseHandler(toolNode, model) {
25
  ToolBase.apply(this, new Array(toolNode, model));
26

    
27
  /**
28
   * Process the mouseup action by stopping the drag.
29
   * @param objRef      Pointer to this object.
30
   * @param targetNode  The HTML node that the event occured on
31
   */
32
  this.mouseUpHandler = function(objRef,targetNode) {
33
    if (objRef.enabled) {
34
      if (objRef.started) objRef.started = false;
35
    }
36
  }
37

    
38
  /**
39
   * Process the mousedown action by setting the anchor point.
40
   * @param objRef      Pointer to this object.
41
   * @param targetNode  The HTML node that the event occured on
42
   */
43
  this.mouseDownHandler = function(objRef,targetNode) {
44
    if (objRef.enabled) {
45
      objRef.started = true;
46
      objRef.anchorPoint = targetNode.evpl;
47
      objRef.dragBox( targetNode.evpl );
48
    }
49
  }
50

    
51
  /**
52
   * Process a the mousemove action as dragging out a box.
53
   * @param objRef      Pointer to this object.
54
   * @param targetNode  The HTML node that the event occured on
55
   */
56
  this.mouseMoveHandler = function(objRef,targetNode) {
57
    if (objRef.enabled) {
58
      if (objRef.started) objRef.dragBox(targetNode.evpl);
59
    }
60
  }
61

    
62
  /**
63
   * Process a the mouseout action when the mouse moves out of the mappane
64
   * @param objRef      Pointer to this object.
65
   * @param targetNode  The HTML node that the event occured on
66
   */
67
  this.mouseOutHandler = function(objRef,targetNode) {
68
    if (objRef.enabled) {
69
      if (objRef.started) objRef.started = false;
70
    }
71
  }
72

    
73
  /**
74
   * Process a the mousemove action as dragging out a box.
75
   * @param objRef      Pointer to this object.
76
   * @param targetNode  The HTML node that the event occured on
77
   */
78
  this.mouseOverHandler = function(objRef,targetNode) {
79
    if (objRef.enabled) {
80
      //if (objRef.started) objRef.dragBox(targetNode.evpl);
81
    }
82
  }
83

    
84
  /** Change the coordinate of one corner of the box.  The anchor point stays fixed. 
85
   * @param evpl    new corner coordinate.
86
   */
87
  this.dragBox = function( evpl ) {	
88
    var ul = new Array();
89
    var lr = new Array();
90
    if (this.anchorPoint[0] > evpl[0]) {
91
      ul[0] = evpl[0];
92
      lr[0] = this.anchorPoint[0];
93
    } else {
94
      ul[0] = this.anchorPoint[0];
95
      lr[0] = evpl[0];
96
    }
97
    if (this.anchorPoint[1] > evpl[1]) {
98
      ul[1] = evpl[1];
99
      lr[1] = this.anchorPoint[1];
100
    } else {
101
      ul[1] = this.anchorPoint[1];
102
      lr[1] = evpl[1];
103
    }
104

    
105
    //set new AOI in context
106
    ul = this.model.extent.getXY( ul );
107
    lr = this.model.extent.getXY( lr );
108
    this.model.setParam("aoi", new Array(ul,lr) );
109
  }
110

    
111
  //register the listeners on the model
112
  this.model.addListener('mousedown',this.mouseDownHandler,this);
113
  this.model.addListener('mousemove',this.mouseMoveHandler,this);
114
  this.model.addListener('mouseup',this.mouseUpHandler,this);
115
  //this.model.addListener('mouseout',this.mouseOutHandler,this);
116
  //this.model.addListener('mouseover',this.mouseOutHandler,this);
117
}
(1-1/12)