1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id$
|
4
|
*/
|
5
|
|
6
|
// Ensure this object's dependancies are loaded.
|
7
|
mapbuilder.loadScript(baseDir+"/widget/ButtonBase.js");
|
8
|
mapbuilder.loadScript(baseDir+"/util/openlayers/OpenLayers.js");
|
9
|
|
10
|
/**
|
11
|
* When this button is selected, clicks on the MapPane trigger a Metacat query with the
|
12
|
* currently set AOI.
|
13
|
* @constructor
|
14
|
* @base ButtonBase
|
15
|
* @authors P. Mark Anderson anderson@nceas.ucsb.edu, Matthew Perry perry@nceas.ucsb.edu
|
16
|
* @param widgetNode The widget node from the Config XML file.
|
17
|
* @param model The model for this widget
|
18
|
*/
|
19
|
function AoiMetacatQuery(widgetNode, model) {
|
20
|
// Extend ButtonBase
|
21
|
ButtonBase.apply(this, new Array(widgetNode, model))
|
22
|
|
23
|
// Grab the important values from the config file
|
24
|
var metacat = widgetNode.selectSingleNode("mb:metacat").firstChild.nodeValue;
|
25
|
var skin = widgetNode.selectSingleNode("mb:skin").firstChild.nodeValue;
|
26
|
var tolerance = widgetNode.selectSingleNode("mb:pixel_tolerance").firstChild.nodeValue;
|
27
|
|
28
|
var method = "popup";
|
29
|
|
30
|
this.cursor = 'crosshair';
|
31
|
|
32
|
this.createControl = function(objRef) {
|
33
|
var Control =
|
34
|
OpenLayers.Class(OpenLayers.Control, {
|
35
|
/**
|
36
|
* Property: type
|
37
|
* {OpenLayers.Control.TYPE}
|
38
|
*/
|
39
|
type: OpenLayers.Control.TYPE_TOOL,
|
40
|
|
41
|
/**
|
42
|
* Property: out
|
43
|
* {Boolean} Should the control be used for zooming out?
|
44
|
*/
|
45
|
out: false,
|
46
|
|
47
|
/**
|
48
|
* Method: draw
|
49
|
*/
|
50
|
draw: function() {
|
51
|
this.handler = new OpenLayers.Handler.Box( this,
|
52
|
{done: this.zoomBox}, {keyMask: this.keyMask} );
|
53
|
},
|
54
|
|
55
|
/**
|
56
|
* Method: zoomBox
|
57
|
* Queries metacat and displays the result in a popup window.
|
58
|
* Parameters:
|
59
|
* position - {<OpenLayers.Bounds>} or {<OpenLayers.Pixel>}
|
60
|
*/
|
61
|
zoomBox: function (position) {
|
62
|
|
63
|
if (position instanceof OpenLayers.Bounds) {
|
64
|
var minXY = this.map.getLonLatFromPixel(
|
65
|
new OpenLayers.Pixel(position.left, position.bottom));
|
66
|
var maxXY = this.map.getLonLatFromPixel(
|
67
|
new OpenLayers.Pixel(position.right, position.top));
|
68
|
var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
|
69
|
maxXY.lon, maxXY.lat);
|
70
|
|
71
|
//alert("bounds:" + bounds);
|
72
|
|
73
|
// Determine the BBOX
|
74
|
var x1 = bounds.left;
|
75
|
var y1 = bounds.bottom;
|
76
|
var x2 = bounds.right;
|
77
|
var y2 = bounds.top;
|
78
|
} else { // it's a pixel
|
79
|
|
80
|
var minXY = this.map.getLonLatFromPixel(
|
81
|
new OpenLayers.Pixel(position.x, position.y));
|
82
|
var x1 = minXY.lon;
|
83
|
var y1 = minXY.lat;
|
84
|
var x2 = minXY.lon;
|
85
|
var y2 = minXY.lat;
|
86
|
}
|
87
|
|
88
|
if ( x1 == x2 && y1 == y2 ) {
|
89
|
// BBOX is really a point; give a bit of wiggle room
|
90
|
// tolerance is number of pixels to buffer, set in config
|
91
|
var extent = this.map.getExtent();
|
92
|
var res = extent.getWidth() / this.map.size.w;
|
93
|
//alert("res:" + res);
|
94
|
x1 = x1 - tolerance * res;
|
95
|
y1 = y1 - tolerance * res;
|
96
|
x2 = x2 + tolerance * res;
|
97
|
y2 = y2 + tolerance * res;
|
98
|
}
|
99
|
|
100
|
var url = metacat + "?action=spatial_query&xmin=" + x1 + "&xmax=" + x2 +
|
101
|
"&ymin=" + y1 + "&ymax=" + y2 + "&skin=" + skin;
|
102
|
|
103
|
if (method == 'popup') {
|
104
|
newwindow = window.open(url,'queryWin',
|
105
|
'height=600,width=800,status=yes,toolbar=yes,menubar=no,location=yes,resizable=yes,scrollbars=yes');
|
106
|
if (window.focus) {newwindow.focus()}
|
107
|
}
|
108
|
|
109
|
},
|
110
|
|
111
|
CLASS_NAME: "mbControl.AoiMetacatQuery"
|
112
|
});
|
113
|
|
114
|
return Control;
|
115
|
}
|
116
|
}
|
117
|
|