Changeset 3049 for contribs

Show
Ignore:
Timestamp:
10/06/09 12:21:52 (3 years ago)
Author:
yves
Message:

Added query (tooltips)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • contribs/mapfish-api/trunk/MapFishApi/js/Search.js

    r2968 r3049  
    22  
    33MapFish.API.Search = OpenLayers.Class({ 
     4 
    45    /** 
    56     * Property: api 
     
    1415    popupEvents: null, 
    1516    featuresCache: null, 
     17    searcher: null, 
     18    queryProtocol: null, 
     19    eventProtocol: null, 
     20    filterProtocol: null, 
    1621 
    1722    /** 
     
    2833        this.featuresCache = []; 
    2934     
    30         this.markers = this.getMarkersLayer(); 
    31         this.api.map.addLayer(this.markers); 
     35        if (!config.disableSearch) { 
     36            this.markers = this.getMarkersLayer(); 
     37            this.api.map.addLayer(this.markers); 
     38     
     39            this.select = new OpenLayers.Control.SelectFeature( 
     40                this.markers, {hover: true, multiple: false} 
     41            ); 
     42            this.api.map.addControl(this.select); 
     43            this.select.activate(); 
     44     
     45            this.recenterProtocol = new mapfish.Protocol.MapFish({ 
     46                url: this.api.baseConfig.recenterUrl, 
     47                callback: this.recenterProtocolCallback, 
     48                scope: this 
     49            }); 
     50        } 
     51         
     52        if (!config.disableQuery) {  
     53            this.queryProtocol = new mapfish.Protocol.MapFish({ 
     54                url: this.api.baseConfig.queryUrl, 
     55                format: new OpenLayers.Format.JSON() 
     56            }); 
     57             
     58            this.eventProtocol = new mapfish.Protocol.TriggerEventDecorator({ 
     59                protocol: this.queryProtocol 
     60            }); 
     61             
     62            this.filterProtocol = new mapfish.Protocol.MergeFilterDecorator({ 
     63                protocol: this.eventProtocol 
     64            });  
     65            this.filterProtocol.register({ 
     66                getFilter: function() { 
     67                    var layers = []; 
     68                    var olLayers = this.api.map.getLayersByName({test: function(str) {return true;}}); 
     69                    for (l in olLayers) { 
     70                        if (olLayers[l].params && 
     71                            olLayers[l].params.LAYERS && 
     72                            olLayers[l].params.LAYERS.length > 0) { 
     73                            layers = layers.concat(olLayers[l].params.LAYERS); 
     74                        } 
     75                    } 
     76                    return {layers: layers}; 
     77                }.createDelegate(this) 
     78            }); 
     79             
     80            this.searcher = new mapfish.Searcher.Map({ 
     81                mode: mapfish.Searcher.Map.CLICK, 
     82                searchTolerance: 10, 
     83                protocol: this.filterProtocol 
     84            }); 
     85             
     86            this.eventProtocol.events.on({ 
     87                crudfinished: this.queryProtocolCallback, 
     88                scope: this 
     89            }); 
    3290 
    33         this.select = new OpenLayers.Control.SelectFeature( 
    34             this.markers, {hover: true} 
    35         ); 
    36         this.api.map.addControl(this.select); 
    37         this.select.activate(); 
    38  
    39         this.recenterProtocol = new mapfish.Protocol.MapFish({ 
    40             url: this.api.baseConfig.recenterUrl, 
    41             callback: this.recenterProtocolCallback, 
    42             scope: this 
    43         }); 
     91            this.api.map.addControl(this.searcher); 
     92            this.searcher.activate();  
     93        } 
    4494    }, 
    4595 
     
    80130        this.hidePopup(); 
    81131        this.api.map.zoomToExtent(f.bounds); 
    82         this.showPopup(f.data.name, f.data.content); 
     132        this.showPopup(f.data.name, f.data.content, this.recenterFeature); 
    83133 
    84134        // Finished 
     
    109159    }, 
    110160 
     161    queryProtocolCallback: function(response) { 
     162         
     163        var lonlat = this.searcher.popupLonLat; 
     164        var feature = new OpenLayers.Feature.Vector(new 
     165                          OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)); 
     166        this.showPopup(response.title, response.features.content, feature); 
     167    }, 
     168     
    111169    hidePopup: function() { 
    112170 
     
    116174    }, 
    117175 
    118     showPopup: function(title, html) { 
     176    showPopup: function(title, html, feature) { 
    119177 
    120         if (this.recenterFeature) { 
     178        if (feature) { 
    121179 
    122180            this.hidePopup(); 
     
    124182                map: this.api.map, 
    125183                title: title, 
    126                 feature: this.recenterFeature, 
     184                feature: feature, 
    127185                width: 250, 
    128186                html: html,