Changeset 7016
- Timestamp:
- 04/27/08 02:44:22 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/topp/almanac/lib/OpenLayers/Control/Geocoder.js
r6969 r7016 10 10 */ 11 11 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, 12 24 13 25 /** … … 19 31 */ 20 32 initialize: function(options) { 33 this.serverProj = new OpenLayers.Projection("EPSG:4326"); 21 34 OpenLayers.Control.prototype.initialize.apply(this, [options]); 22 35 try { … … 37 50 38 51 /** 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 /** 39 81 * APIMethod: getLocation 82 * Geocode an address and call a callback with the resulting location. 83 * If no match is found, callback will receive null. 40 84 * 41 85 * Parameters: 42 86 * address - {String} An address string. 43 87 * 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. 45 90 */ 46 getLocation: function(address, callback) {91 getLocation: function(address, callback) { 47 92 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); 50 100 } 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); 62 102 }, this); 63 103
