-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformSearch.js
126 lines (115 loc) · 3.71 KB
/
performSearch.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
performSearch = function(cswUrl, searchTerms, bbox, start) {
var theFilter = generateFilters(searchTerms, bbox);
// Build the searchObject
var searchObject = {
maxRecords: 10,
resultType: "results",
startPosition: start,
Query: {
ElementSetName: {"value": "summary"},
Constraint: {
version: "1.1.0",
Filter: theFilter
}
}
};
// Generate the CSW Search String
var parser = new OpenLayers.Format.CSWGetRecords();
var cswSearchString = parser.write(searchObject);
// Set the loading icon rolling
Ext.getCmp("csw-search-loading").setIcon("csw/img/loading.gif");
// Send the request
Ext.Ajax.request({
// TODO: Adjust so that proxy location is read from OpenLayers or Viewer config
url: "/proxy/?url=" + encodeURIComponent(cswUrl),
method: "POST",
xmlData: cswSearchString,
callback: function(options, success, response) {
Ext.getCmp("csw-search-loading").setIcon(null);
// Parse the response
if (success) {
cswResponse = response.responseText;
parsedResponse = parser.read(cswResponse);
tabContainer = Ext.getCmp("csw-tab-container");
resultsStore = tabContainer.searchStore;
if (tabContainer.findById("csw-search-table") == null) {
tabContainer.add(Ext.apply(resultsStore.panel, {
listeners: {
add: function(table, newPanel, index) {
// Make sure the map contains a bboxLayer
if (table.layout == "toolbar") { return; }
map = table.map;
bboxLyrs = map.getLayersByName("Search Result Footprints");
if (bboxLyrs.length < 1) {
bboxLyr = bboxLayer();
map.addLayer(bboxLyr);
addBboxControls(bboxLyr, map, table);
}
else {
bboxLyr = bboxLyrs[0];
}
// Add a bbox to the layer
bboxLyr.addFeatures([ newPanel.feature ]);
},
remove: function(table, removedPanel) {
table.map.getLayersByName("Search Result Footprints")[0].removeFeatures([ removedPanel.feature ]);
}
}
}));
}
// parsedResponse.success = false indicates an exception was returned
resultsStore.removeAll();
if (parsedResponse.success == false) { return; }
else {
resultsStore.loadData(parsedResponse);
resultsStore.adjustPaginator(parsedResponse.SearchResults);
}
tabContainer.activate("csw-results-table");
}
else {
alert("Search Failed!");
}
}
});
};
/**
* Create OpenLayers.Filter for use in CSW GetRecords request. Of the general type
* (keyword OR keyword OR ...) AND WITHIN bbox
* @param searchTerms -- a simple array of keywords
* @param bbox -- an OpenLayers.Bounds object, assumed projection of WGS84
* @returns -- an OpenLayers.Filter, or null if no terms or bbox was provided.
*/
function generateFilters(searchTerms, bbox) {
if (searchTerms.length > 0) {
var keywordFilters = [];
fullFilter = null;
for (var i = 0; i < searchTerms.length; i++) {
keywordFilters.push(new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LIKE,
property: "AnyText",
value: searchTerms[i]
}));
}
keywordFilter = new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.OR,
filters: keywordFilters
});
fullFilter = keywordFilter;
}
if (bbox) {
bboxFilter = new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.WITHIN,
property: 'ows:BoundingBox',
value: bbox, // should be of type OpenLayers.Bounds(xmin,ymin,xmax,ymax), should be in WGS84
projection: "EPSG: 4326"
});
fullFilter = bboxFilter;
}
if (searchTerms.length > 0 && bbox) {
fullFilter = new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.AND,
filters: [ keywordFilter, bboxFilter ]
});
}
return fullFilter;
};