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
| function searchAddress() {
var geocoder= viewer.getVariable('geocoder');
var res = geocoder.onSearchClick();
return false;
}
...
Geoportal.Control.LocationUtilityService.Geocode.FormOut= OpenLayers.Class( Geoportal.Control.LocationUtilityService.Geocode, {
addressElement: null,
resultsElement: null,
submitElement: null,
initialize: function(layer, options) {
Geoportal.Control.LocationUtilityService.Geocode.prototype.initialize.apply(this, arguments);
if (typeof(this.addressElement)=='string') {
this.addressElement= OpenLayers.Util.getElement(this.addressElement);
}
if (typeof(this.resultsElement)=='string') {
this.resultsElement= OpenLayers.Util.getElement(this.resultsElement);
}
if (typeof(this.submitElement)=='string') {
this.submitElement= OpenLayers.Util.getElement(this.submitElement);
}
},
destroy: function() {
this.resultsElement= null;
this.addressElement= null;
Geoportal.Control.LocationUtilityService.Geocode.prototype.destroy.apply(this, arguments);
},
activate: function() {
if (!Geoportal.Control.Form.prototype.activate.apply(this,arguments)) {
return false;
}
if (!this.layer.map) {
this.map.addLayer(this.layer);
}
Geoportal.Control.Form.focusOn(this.addressElement);
this.layer.selectCntrl.deactivate();
this.layer.destroyFeatures();
return true;
},
setMap: function(map) {
Geoportal.Control.LocationUtilityService.Geocode.prototype.setMap.apply(this, arguments);
this.addressElement.kbControl= this.map.getControlsByClass(OpenLayers.Control.KeyboardDefaults.prototype.CLASS_NAME)[0];
this.addressElement.value= '';
this.addressElement.onblur= OpenLayers.Function.bind(Geoportal.Control.Form.focusOff, window, this.addressElement);
this.resultsElement.innerHTML= '';//clean up
this.resultsElement.style.display= '';
this.submitElement.onclick= OpenLayers.Function.bind(searchAddress, window);
},
onSearchClick: function(element,evt) {
if (evt || window.event) OpenLayers.Event.stop(evt? evt : window.event);
this.resultsElement.innerHTML= '';//clean up
this.resultsElement.style.display= 'none';
var a= new Geoportal.OLS.Address('FR');
v= OpenLayers.String.trim(this.addressElement.value);
if (v=='') { return false; }
// Retrieve street, city and postal code :
var scp= v.split(',');
// last one is city
// before-last is postal code if more than 2 fields
// all other fields are joined for street
if (scp.length<=1) { return false; }
var city= OpenLayers.String.trim(scp.pop());
if (city=='') { return false; }
var pc= '';
if (scp[scp.length-1].match(/[0-9]{5}/)) {
pc= OpenLayers.String.trim(scp.pop());
}
v= OpenLayers.String.trim(scp.join(','));
var s= new Geoportal.OLS.Street();
s.name= v;
var sa= new Geoportal.OLS.StreetAddress();
sa.addStreet(s);
a.streetAddress= sa;
var p= new Geoportal.OLS.Place({
'classification':'Municipality',
'name':city
});
a.addPlace(p);
a.postalCode= new Geoportal.OLS.PostalCode({'name':pc});
//envoie de la requête au serveur OpenLS
this.layer.GEOCODE(
[a],
{
onSuccess: this.LUSSuccess,
onFailure: this.LUSFailure,
scopeOn: this
});
a.destroy();
a= null;
return true;
}, |
Partager