OpenLayers OpenLayers

Changeset 7016

Show
Ignore:
Timestamp:
04/27/08 02:44:22 (9 months ago)
Author:
tschaub
Message:

setBounds method for prioritizing results, always call callback, set client and server proj appropriately

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/topp/almanac/lib/OpenLayers/Control/Geocoder.js

    r6969 r7016  
    1010     */ 
    1111    geocoder: null, 
     12     
     13    /** 
     14     * Property: clientProj 
     15     * {<OpenLayers.Projection>} The spatial reference for the client (the map). 
     16     */ 
     17    clientProj: null, 
     18 
     19    /** 
     20     * Property: serverProj 
     21     * {<OpenLayers.Projection>} The spatial reference for the geocoding service. 
     22     */ 
     23    serverProj: null, 
    1224 
    1325    /** 
     
    1931     */ 
    2032    initialize: function(options) { 
     33        this.serverProj = new OpenLayers.Projection("EPSG:4326"); 
    2134        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
    2235        try { 
     
    3750     
    3851    /** 
     52     * Method: setMap 
     53     * Handle whatever needs to be done when control is added to map. 
     54     *  
     55     * Parameters: 
     56     * map - {<OpenLayers.Map>}  
     57     */ 
     58    setMap: function(map) { 
     59        OpenLayers.Control.prototype.setMap.apply(this, [map]); 
     60        this.clientProj = this.map.projection; 
     61    }, 
     62     
     63    /** 
     64     * Method: setBounds 
     65     * Sets the geocoder to magnify geocoding results within or near the given 
     66     *     bounds.  Note that setting bounds does not restrict results to that 
     67     *     extent, though it will elevate them in priority. 
     68     * 
     69     * Parameters: 
     70     * bounds - {<OpenLayers.Bounds>} A bounds for prioritizing results. 
     71     */ 
     72    setBounds: function(bounds) { 
     73        bounds = bounds.clone().transform(this.clientProj, this.serverProj); 
     74        this.geocoder.setViewport(new GLatLngBounds( 
     75            new GLatLng(bounds.bottom, bounds.left), 
     76            new GLatLng(bounds.top, bounds.right) 
     77        )); 
     78    }, 
     79     
     80    /** 
    3981     * APIMethod: getLocation 
     82     * Geocode an address and call a callback with the resulting location. 
     83     *     If no match is found, callback will receive null. 
    4084     * 
    4185     * Parameters: 
    4286     * address - {String} An address string. 
    4387     * callback - {Function} A function to be called with the resulting 
    44      *     <OpenLayers.LonLat> 
     88     *     <OpenLayers.LonLat>.  If no match is found, callback will receive 
     89     *     null. 
    4590     */ 
    46     getLocation: function(address, callback)
     91    getLocation: function(address, callback)
    4792        if(!callback) { 
    48             callback = function(lonlat) { 
    49                 alert(lonlat); 
     93            callback = function() {}; 
     94        } 
     95        var bound = OpenLayers.Function.bind(function(point) { 
     96            var lonlat = null; 
     97            if(point) { 
     98                var lonlat = new OpenLayers.LonLat(point.lng(), point.lat()); 
     99                lonlat.transform(this.serverProj, this.clientProj); 
    50100            } 
    51         } 
    52          
    53         var bound = OpenLayers.Function.bind(function(point) { 
    54             if(point){ 
    55                 var lonlat = new OpenLayers.LonLat(point.lng(), point.lat());             
    56                 lonlat.transform( 
    57                     new OpenLayers.Projection("EPSG:4326"), 
    58                     new OpenLayers.Projection(this.map.projection) 
    59                 ); 
    60                 callback(lonlat); 
    61             } 
     101            callback(lonlat); 
    62102        }, this); 
    63103