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+"/widget/WidgetBase.js");
|
10
|
|
11
|
/**
|
12
|
* Widget to draw an Area Of Interest box of a model. The box can be drawn with
|
13
|
* the paint() method and is registered as a listener of the context AOI property.
|
14
|
* This object works entirely in pixel/line coordinate space and knows nothing
|
15
|
* about geography. This widget uses DHTML methods to draw the box.
|
16
|
* @constructor
|
17
|
* @base MapContainerBase
|
18
|
* @param widgetNode The node for this object from the Config file.
|
19
|
* @param model The model that contains this object.
|
20
|
*/
|
21
|
function AoiBoxDHTML(widgetNode, model) {
|
22
|
WidgetBase.apply(this,new Array(widgetNode, model));
|
23
|
|
24
|
this.lineWidth = widgetNode.selectSingleNode("mb:lineWidth").firstChild.nodeValue; // Zoombox line width; pass in as param?
|
25
|
this.lineColor = widgetNode.selectSingleNode("mb:lineColor").firstChild.nodeValue; // color of zoombox lines; pass in as param?
|
26
|
this.crossSize = parseInt(widgetNode.selectSingleNode("mb:crossSize").firstChild.nodeValue);
|
27
|
|
28
|
/** draw out the box.
|
29
|
* if the box width or height is less than the cross size property, then the
|
30
|
* drawCross method is called, otherwise call drawBox.
|
31
|
* @param objRef a pointer to this widget object
|
32
|
*/
|
33
|
this.paint = function(objRef) {
|
34
|
var aoiBox = objRef.model.getParam("aoi");
|
35
|
if (aoiBox) {
|
36
|
var ul = objRef.model.extent.getPL(aoiBox[0]);
|
37
|
var lr = objRef.model.extent.getPL(aoiBox[1]);
|
38
|
//check if ul=lr, then draw cross, else drawbox
|
39
|
if ( (Math.abs( ul[0]-lr[0] ) < objRef.crossSize) &&
|
40
|
(Math.abs( ul[1]-lr[1] ) < objRef.crossSize) ) {
|
41
|
objRef.drawCross( new Array( (ul[0]+lr[0])/2, (ul[1]+lr[1])/2) );
|
42
|
} else {
|
43
|
objRef.drawBox(ul, lr);
|
44
|
}
|
45
|
}
|
46
|
}
|
47
|
model.addListener("aoi",this.paint, this);
|
48
|
|
49
|
MapContainerBase.apply(this,new Array(widgetNode, model));
|
50
|
|
51
|
/** Hide or show the box.
|
52
|
* @param vis boolean true for visible; false for hidden
|
53
|
* @return none
|
54
|
*/
|
55
|
this.setVis = function(vis) {
|
56
|
var visibility = "hidden";
|
57
|
if (vis) visibility = "visible";
|
58
|
this.Top.style.visibility = visibility;
|
59
|
this.Left.style.visibility = visibility;
|
60
|
this.Right.style.visibility = visibility;
|
61
|
this.Bottom.style.visibility = visibility;
|
62
|
}
|
63
|
|
64
|
/** Listener to turn the box off
|
65
|
* @param objRef reference to this object
|
66
|
* @return none
|
67
|
*/
|
68
|
this.clear = function(objRef) {
|
69
|
objRef.setVis(false);
|
70
|
}
|
71
|
this.containerModel.addListener("bbox",this.clear, this);
|
72
|
|
73
|
|
74
|
/** Draw a box.
|
75
|
* @param ul Upper Left position as an (x,y) array in screen coords.
|
76
|
* @param lr Lower Right position as an (x,y) array in screen coords.
|
77
|
*/
|
78
|
this.drawBox = function(ul, lr) {
|
79
|
this.Top.style.left = ul[0] +'px';
|
80
|
this.Top.style.top = ul[1] +'px';
|
81
|
this.Top.style.width = lr[0]-ul[0] +'px';
|
82
|
this.Top.style.height = this.lineWidth +'px';
|
83
|
|
84
|
this.Left.style.left = ul[0] +'px';
|
85
|
this.Left.style.top = ul[1] +'px';
|
86
|
this.Left.style.width = this.lineWidth +'px';
|
87
|
this.Left.style.height = lr[1]-ul[1] +'px';
|
88
|
|
89
|
this.Right.style.left = lr[0]-this.lineWidth +'px';
|
90
|
this.Right.style.top = ul[1] +'px';
|
91
|
this.Right.style.width = this.lineWidth +'px';
|
92
|
this.Right.style.height = lr[1]-ul[1] +'px';
|
93
|
|
94
|
this.Bottom.style.left = ul[0] +'px';
|
95
|
this.Bottom.style.top = lr[1]-this.lineWidth +'px';
|
96
|
this.Bottom.style.width = lr[0]-ul[0] +'px';
|
97
|
this.Bottom.style.height = this.lineWidth +'px';
|
98
|
|
99
|
this.setVis(true);
|
100
|
}
|
101
|
|
102
|
/** Draw a cross.
|
103
|
* @param center The center of the cross as an (x,y) array in screen coordinates.
|
104
|
*/
|
105
|
this.drawCross = function(center) {
|
106
|
this.Top.style.left = Math.floor( center[0] - this.crossSize/2 ) +'px';
|
107
|
this.Top.style.top = Math.floor( center[1] - this.lineWidth/2 ) +'px';
|
108
|
this.Top.style.width = this.crossSize +'px';
|
109
|
this.Top.style.height = this.lineWidth +'px';
|
110
|
this.Top.style.visibility = "visible";
|
111
|
|
112
|
this.Left.style.left = Math.floor( center[0] - this.lineWidth/2 ) +'px';
|
113
|
this.Left.style.top = Math.floor( center[1] - this.crossSize/2 ) +'px';
|
114
|
this.Left.style.width = this.lineWidth +'px';
|
115
|
this.Left.style.height = this.crossSize +'px';
|
116
|
this.Left.style.visibility = "visible";
|
117
|
|
118
|
this.Right.style.visibility = "hidden";
|
119
|
this.Bottom.style.visibility = "hidden";
|
120
|
}
|
121
|
|
122
|
/** Insert a <div> element into the parentNode html to hold the lines.
|
123
|
* @return The new <div> node.
|
124
|
*/
|
125
|
this.getImageDiv = function( ) {
|
126
|
var newDiv = document.createElement("div");
|
127
|
newDiv.innerHTML = "<img src='"+config.skinDir+"/images/Spacer.gif' width='1px' height='1px'/>";
|
128
|
newDiv.style.position = "absolute";
|
129
|
newDiv.style.backgroundColor = this.lineColor;
|
130
|
newDiv.style.visibility = "hidden";
|
131
|
newDiv.style.zIndex = 300;
|
132
|
this.node.appendChild( newDiv );
|
133
|
return newDiv;
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* Called when the parent widget is painted to create the aoi box
|
138
|
* @param objRef This object.
|
139
|
*/
|
140
|
this.loadAoiBox = function(objRef) {
|
141
|
objRef.Top = objRef.getImageDiv( );
|
142
|
objRef.Bottom = objRef.getImageDiv( );
|
143
|
objRef.Left = objRef.getImageDiv( );
|
144
|
objRef.Right = objRef.getImageDiv( );
|
145
|
objRef.paint(objRef);
|
146
|
}
|
147
|
this.loadAoiBox(this);
|
148
|
|
149
|
}
|