-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCswSearch.js
126 lines (117 loc) · 3.87 KB
/
CswSearch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Ext.namespace("gxp.plugins");
gxp.plugins.CswSearch = Ext.extend(gxp.plugins.Tool, {
ptype: "csw_search",
constructor: function(config) {
gxp.plugins.CswSearch.superclass.constructor.apply(this, arguments);
},
addOutput: function(config) {
map = this.target.mapPanel.map;
bboxControl = new OpenLayers.Control({ id: "bbox-draw-control" });
OpenLayers.Util.extend(bboxControl, {
map: map,
url: this.outputConfig.cswUrl,
draw: function() {
this.box = new OpenLayers.Handler.Box( bboxControl,
{"done": this.go }
);
//this.box.activate();
},
ready: function() { this.box.activate(); },
go: function(bounds) {
// Bounds returned are in pixel space
ll = this.map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom));
ur = this.map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top));
bounds = new OpenLayers.Bounds(ll.lon, ll.lat, ur.lon, ur.lat);
// Project it to EPSG:4326
sourceProj = new OpenLayers.Projection("EPSG:3857");
destProj = new OpenLayers.Projection("EPSG:4326");
bounds = bounds.transform(sourceProj, destProj);
performSearch(this.url, Ext.getCmp("csw-search-field").getSearchTerms(), bounds, 1);
this.box.deactivate();
}
});
map.addControl(bboxControl);
config = Ext.apply({
xtype: "panel",
id: "csw-search-container",
layout: "border",
tbar: [
"Search: ",
" ",
new Ext.form.TriggerField({
id: "csw-search-field",
width: 300,
triggerClass: "x-form-search-trigger",
app: this.target,
cswUrl: this.outputConfig.cswUrl,
onTriggerClick: function() {
performSearch(this.cswUrl, this.getSearchTerms(), this.getBbox(), 1);
},
getSearchTerms: function() {
return this.getValue().replace(',', '').split(' ');
},
getBbox: function() {
var checkBox = Ext.getCmp('limit-by-map-extent');
bbox = null;
if (checkBox.getValue() == true) {
// Get bbox of mapExtent in EPSG:3857
webBounds = this.app.mapPanel.map.getExtent();
// Project it to EPSG:4326
sourceProj = new OpenLayers.Projection("EPSG:3857");
destProj = new OpenLayers.Projection("EPSG:4326");
return webBounds.transform(sourceProj, destProj);
}
else { return null; }
},
listeners: {
specialkey: function(f, e) {
if(e.getKey() == e.ENTER) {
this.onTriggerClick();
}
}
}
}),
{
xtype: "button",
id: "csw-search-loading"
}
],
items: [
{
xtype: "toolbar",
id: "csw-bbox-tools",
region: 'north',
items: [
new Ext.Button({
handler: function(btn, e) {
btn.map.getControl("bbox-draw-control").box.activate();
},
text: 'Draw Area of Interest',
icon: 'csw/img/shape_handles.png',
map: this.target.mapPanel.map
}),
'->',
new Ext.form.Checkbox({
id: 'limit-by-map-extent',
boxLabel: 'Use map extent to limit results',
}),
' '
],
height: 27,
}, {
xtype: "tabpanel",
id: "csw-tab-container",
region: "center",
bodyStyle: "border: none;",
headerStyle: "border-width: 0px; border-bottom-width: 1px;",
activeTab: 0,
searchStore: cswResultsStore(false, this.target.mapPanel.map, this.outputConfig.cswUrl),
savedStore: cswResultsStore(true, this.target.mapPanel.map, this.outputConfig.cswUrl),
}
]
}, config || {});
var cswSearch = gxp.plugins.CswSearch.superclass.addOutput.call(this, config);
return cswSearch;
}
});
Ext.preg(gxp.plugins.CswSearch.prototype.ptype, gxp.plugins.CswSearch);