1
|
/*
|
2
|
Author: Cameron Shorter cameronATshorter.net
|
3
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
4
|
|
5
|
$Id$
|
6
|
*/
|
7
|
// Ensure this object's dependancies are loaded.
|
8
|
mapbuilder.loadScript(baseDir+"/widget/MapContainerBase.js");
|
9
|
mapbuilder.loadScript(baseDir+"/util/wz_jsgraphics/wz_jsgraphics.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 the Walter-Zorn graphics library to draw.
|
16
|
* @constructor
|
17
|
* @base MapContainerBase
|
18
|
* @param widgetNode The widget's XML object node from the configuration document.
|
19
|
* @param model The model object that this widget belongs to.
|
20
|
*/
|
21
|
function AoiBoxWZ(widgetNode, model) {
|
22
|
WidgetBase.apply(this,new Array(widgetNode, model));
|
23
|
|
24
|
this.lineWidth = widgetNode.selectSingleNode("mb:lineWidth").firstChild.nodeValue;
|
25
|
this.lineColor = widgetNode.selectSingleNode("mb:lineColor").firstChild.nodeValue;
|
26
|
this.crossSize = widgetNode.selectSingleNode("mb:crossSize").firstChild.nodeValue;
|
27
|
|
28
|
/**
|
29
|
* Render the widget.
|
30
|
* If the box width or height is less than the cross size, then draw a cross,
|
31
|
* otherwise draw a box.
|
32
|
* @param objRef Pointer to this object.
|
33
|
*/
|
34
|
this.paint = function(objRef) {
|
35
|
|
36
|
//create the output node the first time this is called
|
37
|
var outputNode = document.getElementById( objRef.outputNodeId );
|
38
|
if (!outputNode) {
|
39
|
outputNode = document.createElement("DIV");
|
40
|
outputNode.setAttribute("id",objRef.outputNodeId);
|
41
|
outputNode.style.position="relative";
|
42
|
objRef.node.appendChild(outputNode);
|
43
|
}
|
44
|
outputNode.style.left=0;
|
45
|
outputNode.style.top=0;
|
46
|
|
47
|
if (! objRef.jg) {
|
48
|
// WZ Graphics object and rendering functions.
|
49
|
objRef.jg=new jsGraphics(objRef.outputNodeId);
|
50
|
objRef.jg.setColor(objRef.lineColor);
|
51
|
|
52
|
//TBD: The following causes lines to be drawn incorrectly in Mozilla 1.71
|
53
|
objRef.jg.setStroke(parseInt(objRef.lineWidth));
|
54
|
}
|
55
|
|
56
|
var aoiBox = objRef.model.getParam("aoi");
|
57
|
if (aoiBox) {
|
58
|
var ul = objRef.model.extent.getPL(aoiBox[0]);
|
59
|
var lr = objRef.model.extent.getPL(aoiBox[1]);
|
60
|
var width= lr[0]-ul[0];
|
61
|
var height= lr[1]-ul[1];
|
62
|
|
63
|
objRef.jg.clear();
|
64
|
|
65
|
//check if ul=lr, then draw cross, else drawbox
|
66
|
if ((width < objRef.crossSize) && (height < objRef.crossSize) ) {
|
67
|
// draw cross
|
68
|
var x=(lr[0]+ul[0])/2;
|
69
|
var y=(lr[1]+ul[1])/2;
|
70
|
var c=objRef.crossSize/2;
|
71
|
objRef.jg.drawLine(x+c,y,x-c,y);
|
72
|
objRef.jg.drawLine(x,y+c,x,y-c);
|
73
|
} else {
|
74
|
// draw box
|
75
|
objRef.jg.drawRect(ul[0],ul[1],width,height);
|
76
|
}
|
77
|
objRef.jg.paint();
|
78
|
}
|
79
|
}
|
80
|
this.model.addListener("aoi",this.paint, this);
|
81
|
|
82
|
MapContainerBase.apply(this,new Array(widgetNode, model));
|
83
|
|
84
|
/**
|
85
|
* Reset internal variables after container is redrawn due to refreshing
|
86
|
* of the model.
|
87
|
* @param objRef Pointer to this object.
|
88
|
*/
|
89
|
this.clearAoiBox = function(objRef) {
|
90
|
if (objRef.jg) objRef.jg.clear();
|
91
|
}
|
92
|
this.model.addListener("bbox",this.clearAoiBox, this);
|
93
|
|
94
|
/**
|
95
|
* Reset internal variables after container is redrawn due to refreshing
|
96
|
* of the model.
|
97
|
* @param objRef Pointer to this object.
|
98
|
*/
|
99
|
this.refresh = function(objRef) {
|
100
|
objRef.clearAoiBox(objRef);
|
101
|
objRef.jg=null;
|
102
|
}
|
103
|
this.model.addListener("newModel",this.refresh, this);
|
104
|
|
105
|
}
|