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: AoiBoxDHTML.js,v 1.2 2008/03/18 09:59:16 terral Exp $
|
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. Since it
|
16
|
* does not support a targetModel property, it has to be defined as a child widget
|
17
|
* of the context of the map that the box should be drawn into.
|
18
|
* WARNING: This widget cannot be used in maps that use button controls.
|
19
|
* Button controls take care of aoi handling themselves.
|
20
|
* It is designed for use in locator map setups only.
|
21
|
* See also MAP-312
|
22
|
* @deprecated
|
23
|
* @constructor
|
24
|
* @base WidgetBase
|
25
|
* @param widgetNode The node for this object from the Config file.
|
26
|
* @param model The model that contains this object.
|
27
|
*/
|
28
|
function AoiBoxOL(widgetNode, model) {
|
29
|
WidgetBase.apply(this,new Array(widgetNode, model));
|
30
|
|
31
|
this.cursor = 'crosshair';
|
32
|
|
33
|
/**
|
34
|
* Interactive ZoomOut control.
|
35
|
* @param objRef reference to this object.
|
36
|
* @return {OpenLayers.Control} class of the OL control.
|
37
|
*/
|
38
|
this.createControl = function(objRef) {
|
39
|
var Control = OpenLayers.Class( OpenLayers.Control, {
|
40
|
CLASS_NAME: 'mbControl.AoiBoxOL',
|
41
|
type: OpenLayers.Control.TYPE_TOOL,
|
42
|
|
43
|
draw: function() {
|
44
|
this.handler = new OpenLayers.Handler.Box( this,
|
45
|
{done: this.aoiBox}, {keyMask: this.keyMask} );
|
46
|
|
47
|
},
|
48
|
|
49
|
aoiBox: function (position) {
|
50
|
if (position instanceof OpenLayers.Bounds) {
|
51
|
var minXY = this.map.getLonLatFromPixel(
|
52
|
new OpenLayers.Pixel(position.left, position.bottom));
|
53
|
var maxXY = this.map.getLonLatFromPixel(
|
54
|
new OpenLayers.Pixel(position.right, position.top));
|
55
|
var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
|
56
|
maxXY.lon, maxXY.lat);
|
57
|
}
|
58
|
else{
|
59
|
var XY = this.map.getLonLatFromPixel(
|
60
|
new OpenLayers.Pixel(position.x, position.y));
|
61
|
var bounds = new OpenLayers.Bounds(XY.lon, XY.lat,
|
62
|
XY.lon,XY.lat);
|
63
|
}
|
64
|
var bboxOL = bounds.toBBOX().split(',');
|
65
|
var ul = new Array(bboxOL[0],bboxOL[3]);
|
66
|
var lr = new Array(bboxOL[2],bboxOL[1]);
|
67
|
objRef.model.setParam("aoi", new Array(ul, lr));
|
68
|
}
|
69
|
});
|
70
|
|
71
|
return Control;
|
72
|
}
|
73
|
|
74
|
this.init = function(objRef) {
|
75
|
var Control = objRef.createControl(objRef);
|
76
|
var ct=new Control();
|
77
|
objRef.model.map.addControl(ct);
|
78
|
ct.activate();
|
79
|
}
|
80
|
|
81
|
this.model.addListener("loadModel",this.init, this);
|
82
|
/**
|
83
|
* Draws a bounding box around the current AOI.
|
84
|
* @param objRef reference to this widget
|
85
|
*/
|
86
|
this.drawAoiBox = function(objRef) {
|
87
|
if(objRef.model.map){
|
88
|
var ext = objRef.model.getParam('aoi');
|
89
|
var bounds = new OpenLayers.Bounds(ext[0][0], ext[1][1], ext[1][0], ext[0][1]);
|
90
|
objRef.model.aoiBoxLayer = new OpenLayers.Layer.Boxes('Boxes');
|
91
|
objRef.model.map.addLayer(objRef.model.aoiBoxLayer);
|
92
|
var box = new OpenLayers.Marker.Box(bounds);
|
93
|
objRef.model.aoiBoxLayer.addMarker(box);
|
94
|
}
|
95
|
}
|
96
|
/**
|
97
|
* Clears the AOI box.
|
98
|
* @param objRef reference to this widget
|
99
|
*/
|
100
|
this.clearAoiBox = function(objRef) {
|
101
|
if (objRef.model.aoiBoxLayer) {
|
102
|
objRef.model.aoiBoxLayer.destroy();
|
103
|
}
|
104
|
}
|
105
|
|
106
|
// adds a listener to the context to clear the AOI box when AOI changes
|
107
|
this.model.addListener('aoi', this.clearAoiBox, this);
|
108
|
this.model.addListener('aoi', this.drawAoiBox, this);
|
109
|
}
|