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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| Geoportal.Map.prototype.setCenterAtLocation=function(options) {
options= options || {};
var gnLayer= null;
var newZoom= options.zoom || undefined;
var lyrId= null;
var Ls= null;
var self= this;
var center= null;
var olsOpts= {
isGeonames: true,
maximumResponses: 10,
formatOptions: {
version:'1.0'
},
requestOptions: {
method:'GET'
}
};
// utility functions :
// clean geonames/address if needed and center :
var _fcln= options.onComplete || function() {
if (gnLayer) { gnLayer.destroy(); }
if (!center) { center= options.defaultCenter };
if (center) {
self.setCenter(center, newZoom);
if (options.afterCentered) {
if (arguments.length>0) {
var f= arguments[0];
var viewer= self.getApplication();
viewer.options= viewer.options || {};
var ga= f.attributes.address;
//var lbl= olsOpts.isGeonames? options.place : options.address;
var lbl= OpenLayers.i18n((olsOpts.isGeonames?
'gpControlLocationUtilityServiceGeoNames'
: 'gpControlLocationUtilityServiceGeocode')+
'.name');
var dsc= ga.toHTMLString();
OpenLayers.Util.applyDefaults(viewer.options, {
label:lbl,
description:dsc
});
}
options.afterCentered.apply(self,[]);
}
}
return;
};
// clean center :
var _fonf= options.onFailure || function(r) {
center= null;
_fcln();
return;
};
// process responses :
var _fons= options.onSuccess || function(r) {
if (!this.queriedAddresses) {
_fonf(r);
return;
}
var fs= this.queriedAddresses[0].features;
if (!fs) {
_fonf(r);
return;
}
// sort by geoname's type and response accuracy :
if (this.isGeonames) {
fs.sort(Geoportal.Control.LocationUtilityService.GeoNames.orderBDNyme);
}
center= new OpenLayers.LonLat(fs[0].geometry.x,fs[0].geometry.y);
if(newZoom=="undefined"){
if (this.isGeonames) {
newZoom= Geoportal.Control.LocationUtilityService.GeoNames.setZoomForBDNyme(fs[0]);
} else {
newZoom= Geoportal.Control.LocationUtilityService.Geocode.prototype.setZoom.apply(this,[fs[0]]);
}
}
_fcln(fs[0]);
return;
};
lyrId= 'PositionOfInterest:OPENLS;Geocode';
if (options.place && this.catalogue.getLayerGeoRMKey(null,lyrId)) {// placename
var a= null;
var v= OpenLayers.String.trim(options.place);
if (v!='') {
a= new Geoportal.OLS.Address('PositionOfInterest');
a.name= v;
Ls= this.getLayersByName(lyrId);
if (Ls && Ls.length>0) {
Ls[0].destroy();
}
Ls= null;
gnLayer= new Geoportal.Layer.OpenLS.Core.LocationUtilityService(lyrId, olsOpts);
this.addLayer(gnLayer);
gnLayer.GEOCODE(
[a],
{
onSuccess: _fons,
onFailure: _fonf,
scopeOn:gnLayer
});
a.destroy();
a= null;
return;//callbacks will take place ...
}
}
lyrId= 'StreetAddress:OPENLS;Geocode';
olsOpts.isGeonames= false;
if (options.address && this.catalogue.getLayerGeoRMKey(null,lyrId)) {// geocoding
var a= null;
// Retrieve street, city and postal code :
var scp= options.address.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) {
var city= OpenLayers.String.trim(scp.pop());
if (city.length>0) {
var pc= '';
if (scp[scp.length-1].match(/[0-9]{5}/)) {
pc= OpenLayers.String.trim(scp.pop());
}
var s= new Geoportal.OLS.Street();
s.name= OpenLayers.String.trim(scp.join(','));
var sa= new Geoportal.OLS.StreetAddress();
sa.addStreet(s);
a= new Geoportal.OLS.Address('StreetAddress');
a.streetAddress= sa;
var p= new Geoportal.OLS.Place({
'classification':'Municipality',
'name':city
});
a.addPlace(p);
a.postalCode= new Geoportal.OLS.PostalCode({'name':pc});
Ls= this.getLayersByName(lyrId);
if (Ls && Ls.length>0) {
Ls[0].destroy();
}
Ls= null;
gnLayer= new Geoportal.Layer.OpenLS.Core.LocationUtilityService(lyrId, olsOpts);
this.addLayer(gnLayer);
gnLayer.GEOCODE(
[a],
{
onSuccess: _fons,
onFailure: _fonf,
scopeOn:gnLayer
});
a.destroy();
a= null;
return;//callbacks will take place ...
}
}
}
} |
Partager