Changeset 1190
- Timestamp:
- 10/14/08 09:39:42 (3 months ago)
- Files:
-
- sandbox/camptocamp/MapFishUnhcr/client/apidoc_config/Menu.txt (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/examples/search/c2corg.html (modified) (2 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/MapFish.js (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Protocol.js (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Protocol/MapFish.js (modified) (2 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Protocol/MergeFilterDecorator.js (modified) (6 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/SearchMediator.js (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Searcher.js (modified) (2 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Searcher/Form.js (modified) (3 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Searcher/Map.js (modified) (16 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/core/Protocol/test_MergeFilterDecorator.html (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/core/Searcher/test_Map.html (modified) (3 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/core/test_SearchMediator.html (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/list-tests.html (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/widgets/data/test_SearchStoreMediator.html (modified) (8 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/widgets/data/SearchStoreMediator.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/MapFishUnhcr/client/apidoc_config/Menu.txt
r1124 r1190 69 69 File: Protocol (no auto-title, core/Protocol.js) 70 70 File: MapFish (no auto-title, core/Protocol/MapFish.js) 71 File: TriggerEventDecorator (no auto-title, core/Protocol/TriggerEventDecorator.js) 72 File: MergeFilterDecorator (no auto-title, core/Protocol/MergeFilterDecorator.js) 71 73 } # Group: Protocol 72 74 73 File: SearchMediator (no auto-title, core/SearchMediator.js)74 75 File: PrintProtocol (no auto-title, core/PrintProtocol.js) 75 76 File: Offline (no auto-title, core/Offline.js) sandbox/camptocamp/MapFishUnhcr/client/examples/search/c2corg.html
r1124 r1190 93 93 map.addControl(new OpenLayers.Control.PanZoomBar()); 94 94 95 var mediator = new mapfish.SearchMediator({ 95 // we need to wrap the MapFish protocol in a trigger event 96 // decorator protocol so that the default popup can be 97 // displayed by the searcher 98 var protocol = mapfish.Protocol.decorateProtocol({ 96 99 protocol: new mapfish.Protocol.MapFish({ 97 100 url: mapfish.SERVER_BASE_URL + 'summits', … … 99 102 maxfeatures: 10 100 103 } 101 }) 104 }), 105 TriggerEventDecorator: null 102 106 }); 103 107 104 108 searcher = new mapfish.Searcher.Map({ 105 109 mode: mapfish.Searcher.Map.BOX, 106 mediator: mediator,110 protocol: protocol, 107 111 displayDefaultPopup: true 108 112 }); sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/MapFish.js
r1173 r1190 99 99 "core/Routing.js", 100 100 "core/Util.js", 101 "core/SearchMediator.js",102 101 "core/Searcher.js", 103 102 "core/Searcher/Map.js", 104 103 "core/Searcher/Form.js", 104 "core/PrintProtocol.js", 105 "core/Offline.js", 105 106 "core/Protocol.js", 106 107 "core/Protocol/MapFish.js", 107 108 "core/Protocol/WFS.js", 108 109 "core/Protocol/MergeFilterDecorator.js", 109 "core/PrintProtocol.js", 110 "core/Offline.js", 111 "core/Protocol.js", 112 "core/Protocol/MapFish.js", 110 "core/Protocol/TriggerEventDecorator.js", 113 111 "widgets/MapComponent.js", 114 112 "widgets/Shortcuts.js", sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Protocol.js
r1124 r1190 18 18 */ 19 19 20 /* 21 * @requires OpenLayers/Protocol.js 20 /** 21 * Namespace: mapfish.Protocol 22 * Contains convenience methods for protocol manipulation. 22 23 */ 24 mapfish.Protocol = { 23 25 24 /** 25 * Class: mapfish.Protocol 26 * Abstract protocol class. Not to be instantiated directly. Use 27 * one of the protocol subclasses instead. 28 * 29 * mapfish.Protocol actually references <OpenLayers.Protocol> 30 */ 31 mapfish.Protocol = OpenLayers.Protocol; 26 /** 27 * APIFunction: decorateProtocol 28 * Decorate a protocol. 29 * 30 * Example of use: 31 * (start code) 32 * var protocol = mapfish.Protocol.decorateProtocol({ 33 * protocol: protocol, 34 * TriggerEventDecorator: { 35 * eventListeners: { 36 * crudfinished: function() { 37 * alert("CRUD operation completed"); 38 * } 39 * } 40 * }, 41 * MergeFilterDecorator: null 42 * }); 43 * (end) 44 * 45 * Parameters: 46 * config - {Object} Config object specifying how protocol must be 47 * decorated, see the above the example. 48 * 49 * Returns: 50 * {<OpenLayers.Protocol>} The resulting protocol. 51 * */ 52 decorateProtocol: function(config) { 53 var protocol = config.protocol; 54 for (var key in config) { 55 if (key != "protocol") { 56 if (!mapfish.Protocol[key]) { 57 OpenLayers.Console.error( 58 "mapfish.Protocol." + key + " does not exist"); 59 } else { 60 protocol = new mapfish.Protocol[key]( 61 OpenLayers.Util.extend( 62 {protocol: protocol}, config[key]) 63 ); 64 } 65 } 66 } 67 return protocol; 68 } 69 }; sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Protocol/MapFish.js
r1124 r1190 45 45 initialize: function(options) { 46 46 options = options || {}; 47 options.format = new OpenLayers.Format.GeoJSON(); 47 if (!options.format) { 48 options.format = new OpenLayers.Format.GeoJSON(); 49 } 48 50 OpenLayers.Protocol.HTTP.prototype.initialize.call(this, options); 49 51 }, … … 104 106 */ 105 107 "read": function(options) { 108 // workaround a bug in OpenLayers 109 options.params = OpenLayers.Util.applyDefaults( 110 options.params, this.options.params); 106 111 if (options) { 107 112 this.filterAdapter(options); sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Protocol/MergeFilterDecorator.js
r1176 r1190 20 20 /* 21 21 * @requires OpenLayers/Util.js 22 * @requires core/Protocol.js22 * @requires OpenLayers/Protocol.js 23 23 * @requires core/Searcher.js 24 24 */ … … 109 109 */ 110 110 "read": function(options) { 111 options.filter = this.mergeFilters(options.filter); 111 options.filter = this.mergeFilters( 112 options.filter || options.params, options.searcher); 113 delete options.searcher; 112 114 return this.protocol.read(options); 113 115 }, … … 118 120 * 119 121 * Parameters: 120 * filter - {<OpenLayers.Filter>} 122 * filter - {<OpenLayers.Filter>}|{Object} 123 * searcher - {<mapfish.Searcher>} 121 124 * 122 125 * Returns: 123 126 * {<OpenLayers.Filter>} The resulting filter. 124 127 */ 125 mergeFilters: function(filter) { 126 for (var i = 0, len = this.searchers.length; i < len; i++) { 127 filter = this.toFilter(this.searchers[i].getFilter(), filter); 128 mergeFilters: function(filter, searcher) { 129 var i, len, s; 130 for (i = 0, len = this.searchers.length; i < len; i++) { 131 s = this.searchers[i]; 132 if (s != searcher) { 133 filter = this.toFilter(s.getFilter(), filter); 134 } 128 135 } 129 136 return filter; … … 145 152 } 146 153 if (!filter) { 147 filter = new OpenLayers.Filter.Logical({ 148 type: OpenLayers.Filter.Logical.AND 149 }); 154 filter = new OpenLayers.Filter.Logical({ 155 type: OpenLayers.Filter.Logical.AND 156 }); 157 } else if (!this.isFilter(filter)) { 158 filter = this.fromObjToFilter(filter); 150 159 } else if (!this.isLogicalFilter(filter)) { 151 filter = new OpenLayers.Filter.Logical({152 type: OpenLayers.Filter.Logical.AND,153 filters: [filter]154 });160 filter = new OpenLayers.Filter.Logical({ 161 type: OpenLayers.Filter.Logical.AND, 162 filters: [filter] 163 }); 155 164 } 156 165 var filters = filter.filters; … … 158 167 filters.push(obj); 159 168 } else { 160 for (var key in obj) { 161 filters.push( 162 new OpenLayers.Filter.Comparison({ 163 type: OpenLayers.Filter.Comparison.EQUAL_TO, 164 property: key, 165 value: obj[key] 166 }) 167 ); 168 } 169 filters.push(this.fromObjToFilter(obj)); 169 170 } 170 171 return filter; 172 }, 173 174 /** 175 * Method: fromObjToFilter 176 * 177 * Paremeters: 178 * obj - {Object} 179 * 180 * Returns: 181 * {<OpenLayers.Filter.Logical>} 182 */ 183 fromObjToFilter: function(obj) { 184 var filters = []; 185 for (var key in obj) { 186 filters.push( 187 new OpenLayers.Filter.Comparison({ 188 type: OpenLayers.Filter.Comparison.EQUAL_TO, 189 property: key, 190 value: obj[key] 191 }) 192 ); 193 } 194 return new OpenLayers.Filter.Logical({ 195 type: OpenLayers.Filter.Logical.AND, 196 filters: filters 197 }); 171 198 }, 172 199 … … 265 292 CLASS_NAME: "mapfish.Protocol.MergeFilterDecorator" 266 293 }); 267 /*268 * Copyright (C) 2007 Camptocamp269 *270 * This file is part of MapFish Client271 *272 * MapFish Client is free software: you can redistribute it and/or modify273 * it under the terms of the GNU General Public License as published by274 * the Free Software Foundation, either version 3 of the License, or275 * (at your option) any later version.276 *277 * MapFish Client is distributed in the hope that it will be useful,278 * but WITHOUT ANY WARRANTY; without even the implied warranty of279 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the280 * GNU General Public License for more details.281 *282 * You should have received a copy of the GNU General Public License283 * along with MapFish Client. If not, see <http://www.gnu.org/licenses/>.284 */285 286 /**287 * Class: mapfish.Protocol.MergeFilterDecorator288 */289 mapfish.Protocol.MergeFilterDecorator = OpenLayers.Class({290 291 /**292 * Property: searchers293 * Array({<mapfish.Searcher>} Array of searchers294 */295 searchers: null,296 297 /**298 * APIProperty: protocol299 * {<OpenLayers.Protocol>} The protocol to use for sending search300 * requests.301 */302 protocol: null,303 304 /**305 * Constructor: mapfish.Protocol.MergeFilterDecorator306 *307 * Parameters:308 * protocol - {<OpenLayers.Protocol>} The protocol to decorate309 * options - {Object}310 */311 initialize: function(protocol, options) {312 this.searchers = [];313 this.protocol = protocol;314 OpenLayers.Util.extend(this, options);315 OpenLayers.Util.applyDefaults(this, this.protocol);316 },317 318 /**319 * APIMethod: read320 * Construct a request for reading new features.321 *322 * Parameters:323 * options - {Object} Optional object for configuring the request.324 * This object is modified and should not be reused.325 *326 * Returns:327 * {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>328 * object, whose "priv" property references the HTTP request, this329 * object is also passed to the callback function when the request330 * completes, its "features" property is then populated with the331 * the features received from the server.332 */333 read: function(options) {334 options = options || {};335 336 var filter = this.toFilter(options.filter);337 338 for (var i = 0, len = this.searchers.length; i < len; i++) {339 filter = this.toFilter(this.searchers[i].getFilter(), filter);340 }341 342 options.filter = filter;343 return this.protocol.read(options);344 },345 346 /**347 * Method: toFilter348 *349 * Parameters:350 * obj - {Object}351 * filter - {<OpenLayers.Filter>}352 *353 * Returns:354 * {<OpenLayers.Filter.Logical>}355 */356 toFilter: function(obj, filter) {357 filter = filter || new OpenLayers.Filter.Logical(358 {type: OpenLayers.Filter.Logical.AND});359 360 var filters = filter.filters;361 362 if (this.isFilter(obj)) {363 filters.push(obj);364 } else {365 for (var key in obj) {366 filters.push(367 new OpenLayers.Filter.Comparison({368 type: OpenLayers.Filter.Comparison.EQUAL_TO,369 property: key,370 value: obj[key]371 })372 );373 }374 }375 return filter;376 },377 378 /**379 * Method: isFilter380 * Check if the object passed is a <OpenLayers.Filter> object.381 *382 * Parameters:383 * obj - {Object}384 */385 isFilter: function(obj) {386 return !!obj && !!obj.CLASS_NAME &&387 !!obj.CLASS_NAME.match(/^OpenLayers\.Filter/);388 },389 390 CLASS_NAME: "mapfish.SearchMediator"391 });sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/SearchMediator.js
r1124 r1190 1 /*2 * Copyright (C) 2007-2008 Camptocamp3 *4 * This file is part of MapFish Client5 *6 * MapFish Client is free software: you can redistribute it and/or modify7 * it under the terms of the GNU General Public License as published by8 * the Free Software Foundation, either version 3 of the License, or9 * (at your option) any later version.10 *11 * MapFish Client is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14 * GNU General Public License for more details.15 *16 * You should have received a copy of the GNU General Public License17 * along with MapFish Client. If not, see <http://www.gnu.org/licenses/>.18 */19 20 /*21 * @requires OpenLayers/Util.js22 * @requires OpenLayers/Ajax.js23 * @requires OpenLayers/Filter/Logical.js24 */25 26 /**27 * Class: mapfish.SearchMediator28 * A SearchMediator object is to be used when multiple searchers must be coupled29 * (e.g. coupling a search form with a BBOX searcher).30 */31 mapfish.SearchMediator = OpenLayers.Class({32 33 /**34 * Property: searchers35 * Array({<mapfish.Searcher>} Array of searchers controlled by this36 * mediator.37 */38 searchers: null,39 40 /**41 * APIProperty: protocol42 * {<OpenLayers.Protocol>} The protocol to use for sending search43 * requests.44 */45 protocol: null,46 47 /**48 * Property: response49 * {<OpenLayers.Protocol.Response>} The response got from the protocol.50 */51 response: null,52 53 /**54 * Property: events55 * {<OpenLayers.Events>}56 */57 events: null,58 59 /**60 * Constant: EVENT_TYPES61 * {Array(String)} Supported event types. Register a listener62 * for a particular event with the following syntax:63 * (start code)64 * mediator.events.register(type, obj, listener);65 * (end)66 *67 * Listeners will be called with a reference to an event object.68 *69 * Supported events:70 * - *searchtriggered* Triggered when a search request was triggered,71 * listeners will receive an object with a *filter property72 * referencing the <OpenLayers.Filter> object associated to the73 * search request.74 * - *searchfinished* Triggered when the search request completes,75 * listeners will receive an {<OpenLayers.Protocol.Response>}76 * object.77 * - *clear* Triggered when the clear API method is called.78 */79 EVENT_TYPES: ["searchtriggered", "searchfinished", "searchcanceled", "clear"],80 81 /**82 * Constructor: mapfish.SearchMediator83 *84 * Parameters:85 * options - {Object}86 */87 initialize: function(options) {88 OpenLayers.Util.extend(this, options);89 this.searchers = [];90 this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);91 if(this.eventListeners instanceof Object) {92 this.events.on(this.eventListeners);93 }94 },95 96 /**97 * Method: destroy98 */99 destroy: function () {100 if (this.protocol.autoDestroy) {101 this.protocol.destroy();102 }103 this.protocol = null;104 105 this.searchers = null;106 107 if (this.events) {108 this.events.destroy();109 this.events = null;110 }111 },112 113 /**114 * Method: triggerSearch115 * Trigger search request to the search service.116 */117 triggerSearch: function() {118 var filter = null, f = null, params = null;119 for (var i = 0, len = this.searchers.length; i < len; i++) {120 if (f = this.searchers[i].getFilter())121 filter = this.toFilter(f, filter);122 }123 124 this.events.triggerEvent("searchtriggered", {filter: filter});125 126 // workaround a bug in OpenLayers127 params = OpenLayers.Util.extend(128 {}, this.protocol.options.params);129 130 this.response = this.protocol.read({131 filter: filter,132 callback: this.finishSearch,133 params: params,134 scope: this135 });136 },137 138 /**139 * Method: finishSearch140 * Called with we get a response from the search service.141 *142 * Parameters:143 * {<OpenLayers.Protocol.Response>} The protocol response.144 */145 finishSearch: function(response) {146 this.response = null;147 this.events.triggerEvent("searchfinished", response);148 },149 150 /**151 * Method: cancelSearch152 * Cancel ongoing search.153 */154 cancelSearch: function() {155 if (this.response) {156 var response = this.response;157 if (response.priv &&158 typeof response.priv.abort == "function") {159 response.priv.abort();160 this.response = null;161 this.events.triggerEvent("searchcanceled", response);162 }163 }164 },165 166 /**167 * Method: toFilter168 *169 * Parameters:170 * obj - {Object}171 * filter - {<OpenLayers.Filter>}172 *173 * Returns:174 * {<OpenLayers.Filter.Logical>}175 */176 toFilter: function(obj, filter) {177 filter = filter || new OpenLayers.Filter.Logical(178 {type: OpenLayers.Filter.Logical.AND});179 180 var filters = filter.filters;181 182 if (this.isFilter(obj)) {183 filters.push(obj);184 } else {185 for (var key in obj) {186 filters.push(187 new OpenLayers.Filter.Comparison({188 type: OpenLayers.Filter.Comparison.EQUAL_TO,189 property: key,190 value: obj[key]191 })192 );193 }194 }195 return filter;196 },197 198 /**199 * Method: isFilter200 * Check if the object passed is a <OpenLayers.Filter> object.201 *202 * Parameters:203 * obj - {Object}204 */205 isFilter: function(obj) {206 return !!obj.CLASS_NAME &&207 !!obj.CLASS_NAME.match(/^OpenLayers\.Filter/);208 },209 210 /**211 * APIMethod: clear212 * Clear all the previous results.213 */214 clear: function() {215 this.events.triggerEvent("clear");216 },217 218 CLASS_NAME: "mapfish.SearchMediator"219 });220 sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Searcher.js
r1124 r1190 18 18 */ 19 19 20 /*21 * @requires core/SearchMediator.js22 */23 24 20 /** 25 21 * Class: mapfish.Searcher … … 30 26 31 27 /** 32 * Property: mediator33 * {<mapfish.SearchMediator>} - The search mediator.34 */35 mediator: null,36 37 /**38 28 * Constructor: mapfish.Searcher 39 *40 * Parameters:41 * options {Object} Optional object whose properties will be set on the42 * instance.43 29 * 44 30 * Returns: 45 31 * {<mapfish.Searcher>} 46 32 */ 47 initialize: function() { 48 if (!this.mediator) { 49 OpenLayers.Console.error("no mediator set"); 50 return; 51 } 52 this.mediator.searchers.push(this); 53 }, 33 initialize: function() {}, 54 34 55 35 /** sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Searcher/Form.js
r1124 r1190 36 36 37 37 /** 38 * APIProperty: protocol 39 * {<OpenLayers.Protocol>} - The protocol. 40 */ 41 protocol: null, 42 43 /** 38 44 * APIProperty: map 39 45 * {DOMElement} The form node. 40 46 */ 41 47 form: null, 48 49 /** 50 * Property: response 51 * {<OpenLayers.Protocol.Response>} The response returned by the 52 * read call to <OpenLayers.Protocol> object. 53 */ 54 response: null, 42 55 43 56 /** … … 52 65 */ 53 66 initialize: function(options) { 67 mapfish.Searcher.prototype.initialize.call(this, options); 54 68 OpenLayers.Util.extend(this, options); 55 mapfish.Searcher.prototype.initialize.call(this, options);56 69 if (!this.form) { 57 70 OpenLayers.Console.error("no form set"); 71 return; 72 } 73 if (!this.protocol) { 74 OpenLayers.Console.error("no protocol set"); 58 75 return; 59 76 } … … 62 79 /** 63 80 * APIMethod: triggerSearch 64 * To be called to instruct the search mediator to trigger 65 * search. 81 * To be called to trigger search. 66 82 */ 67 83 triggerSearch: function() { 68 this.mediator.cancelSearch(); 69 this.mediator.triggerSearch(); 84 // FIXME really we should rely on the protocol itself to 85 // cancel the request, the Protocol class in OpenLayers 86 // 2.7 does not expose a cancel() method 87 if (this.response) { 88 var response = this.response; 89 if (response.priv && 90 typeof response.priv.abort == "function") { 91 response.priv.abort(); 92 this.response = null; 93 } 94 } 95 this.response = this.protocol.read( 96 {filter: this.getFilter(), searcher: this}); 70 97 }, 71 98 sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Searcher/Map.js
r1124 r1190 21 21 /* 22 22 * @requires core/Searcher.js 23 * @requires core/ SearchMediator.js23 * @requires core/Protocol.js 24 24 * @requires OpenLayers/Map.js 25 25 * @requires OpenLayers/Util.js … … 42 42 */ 43 43 mapfish.Searcher.Map = OpenLayers.Class(mapfish.Searcher, OpenLayers.Control, { 44 45 /** 46 * APIProperty: protocol 47 * {<OpenLayers.Protocol>} - The protocol. 48 */ 49 protocol: null, 44 50 45 51 /** … … 110 116 * {Boolean} Display a default popup with the search results, 111 117 * does not apply if mode is set to <mapfish.Searcher.Map.HOVER>, 112 * defaults to false. 118 * defaults to false, or if the protocol used isn't of type 119 * <mapfish.Protocol.TriggerEventDecorator>. 113 120 */ 114 121 displayDefaultPopup: false, … … 132 139 133 140 /** 141 * Property: popupLonLat 142 * {<OpenLayers.LonLat>} The <OpenLayers.LonLat> object representing 143 * where the popup must be displayed. 144 */ 145 popupLonLat: null, 146 147 /** 148 * Property: response 149 * {<OpenLayers.Protocol.Response>} The response returned by the 150 * read call to <OpenLayers.Protocol> object. 151 */ 152 response: null, 153 154 /** 134 155 * Constructor: mapfish.Searcher.Map 135 156 * … … 144 165 this.mode = mapfish.Searcher.Map.CLICK; 145 166 167 mapfish.Searcher.prototype.initialize.call(this, options); 146 168 OpenLayers.Control.prototype.initialize.call(this, options); 147 mapfish.Searcher.prototype.initialize.call(this, options); 169 170 if (!this.protocol) { 171 OpenLayers.Console.error("no protocol set"); 172 return; 173 } 148 174 149 175 switch(this.mode) { … … 191 217 this.map.events.register( 192 218 "moveend", this, this.handleMoveend); 193 } else if (this.displayDefaultPopup) { 194 this.mediator.events.on({ 195 searchfinished: this.displayPopup, 219 } else if (this.displayDefaultPopup && 220 this.protocol.CLASS_NAME == 221 "mapfish.Protocol.TriggerEventDecorator") { 222 this.protocol.events.on({ 223 crudfinished: this.displayPopup, 196 224 scope: this 197 225 }); … … 215 243 this.map.events.unregister( 216 244 "moveend", this, this.handleMoveend); 217 } else if (this.displayDefaultPopup) { 218 this.mediator.events.un({ 219 searchfinished: this.displayPopup, 245 } else if (this.displayDefaultPopup && 246 this.protocol.CLASS_NAME == 247 "mapfish.Protocol.TriggerEventDecorator") { 248 this.protocol.events.un({ 249 crudfinished: this.displayPopup, 220 250 scope: this 221 251 }); … … 234 264 handlePoint: function(evt) { 235 265 this.position = evt.xy; 266 this.popupLonLat = this.map.getLonLatFromViewPortPx(this.position); 236 267 this.triggerSearch(); 237 268 }, … … 252 283 minXY.lon, minXY.lat, 253 284 maxXY.lon, maxXY.lat); 285 this.popupLonLat = this.position.getCenterLonLat(); 254 286 } else { 255 287 this.position = position; 288 this.popupLonLat = this.map.getLonLatFromViewPortPx(this.position); 256 289 } 257 290 this.triggerSearch(); … … 264 297 handleMoveend: function() { 265 298 this.position = this.map.getExtent(); 299 this.popupLonLat = this.position.getCenterLonLat(); 266 300 this.triggerSearch(); 267 301 }, … … 272 306 triggerSearch: function() { 273 307 this.cancelSearch(); 274 this.mediator.triggerSearch(); 308 309 var filter = this.getFilter(); 310 filter = this.isFilter(filter) ? {filter: filter} : {params: filter}; 311 var options = OpenLayers.Util.extend({searcher: this}, filter); 312 313 this.response = this.protocol.read(options); 275 314 }, 276 315 … … 284 323 */ 285 324 cancelSearch: function(evt) { 286 this.mediator.cancelSearch(); 325 // FIXME really we should rely on the protocol itself to 326 // cancel the request, the Protocol class in OpenLayers 327 // 2.7 does not expose a cancel() method 328 if (this.response) { 329 var response = this.response; 330 if (response.priv && 331 typeof response.priv.abort == "function") { 332 response.priv.abort(); 333 this.response = null; 334 } 335 } 287 336 if (this.mode == mapfish.Searcher.Map.HOVER) { 288 337 this.onMouseMove(); … … 300 349 301 350 if (features && features.length > 0) { 302 var lonlat;303 if (this.position instanceof OpenLayers.Bounds) {304 lonlat = this.position.getCenterLonLat();305 } else {306 lonlat = this.map.getLonLatFromViewPortPx(this.position);307 }308 309 351 var k; 310 352 … … 327 369 var popup = new OpenLayers.Popup.FramedCloud( 328 370 "mapfish_popup", // popup id 329 lonlat,// OpenLayers.LonLat object371 this.popupLonLat, // OpenLayers.LonLat object 330 372 null, // popup is autosized 331 373 html, // html string … … 338 380 339 381 /** 382 * Method: isFilter 383 * Check if the object passed is a <OpenLayers.Filter> object. 384 * 385 * Parameters: 386 * obj - {Object} 387 * 388 * Returns: 389 * {Boolean} 390 */ 391 isFilter: function(obj) { 392 return !!obj.CLASS_NAME && 393 !!obj.CLASS_NAME.match(/^OpenLayers\.Filter/); 394 }, 395 396 /** 340 397 * Method: getFilter 341 398 * Get the search filter. … … 345 402 */ 346 403 getFilter: function() { 347 var filter; 348 mapfish.Searcher.prototype.getFilter.call(this); 349 if (this.position instanceof OpenLayers.Bounds) { 350 filter = new OpenLayers.Filter.Spatial({ 351 type: OpenLayers.Filter.Spatial.BBOX, 352 value: this.position 353 }); 354 } else { 355 var tolerance = this.searchTolerance; 356 if (tolerance && this.searchToleranceUnits == "pixels") { 357 tolerance *= this.map.getResolution(); 358 } 359 var lonlat = this.map.getLonLatFromViewPortPx(this.position); 360 filter = {lon: lonlat.lon, lat: lonlat.lat}; 361