var INPUT_ADDRESSES_COUNT = 2; //numero di TextBox utilizzate [Costante]; var ID_PREFERENCE = "preference"; var arrayAddressesIndex = -1; //indice di riferimento dell'indirizzo che si sta parserizzando; var currentInputAddress; //attuale indirizzo inserito dall'utente da parserizzare; var currentIdInputAddress; //attuale id dell'indirizzo inserito dall'utente da parserizzare; var arrayAddressProcessed = new Array(); var textCollectionProcessed = new Array(INPUT_ADDRESSES_COUNT); textCollectionProcessed[0] = 0; textCollectionProcessed[1] = 0; //------------------------------------------------------------------------------------------------------------ //costruttore per inizializzare il singolo indirizzo; function addressObjJs(obj) { this.latitude = 0; this.longitude = 0; if( obj.Point != null ) { this.latitude = obj.Point.coordinates[1]; this.longitude = obj.Point.coordinates[0]; this.addressValue = obj.address; } else this.addressValue = obj; } //costruttore per inizializzare il vettore degli indirizzi trovati; function addressesObjJs(idInputAddress) { this.idInputAddress = idInputAddress; this.addresses = new Array(); } // inizializzo vettore di flag che mi serve per vedere se ho gia' parserizzato l'indirizzo. // inizializzo pure l'indice dell'array degli indirizzi parserizzati. function initialization() { for(var i=0; i < textCollectionProcessed.length; i++) textCollectionProcessed[i] = 0; arrayAddressesIndex = -1; } //------------------------------------------------------------------------------------------------------------ function calculateItinerary() { for(var i=0; i < textCollection.length; i++) { if (textCollectionProcessed[i] == 1) continue; currentInputAddress = textCollection[i].value; currentIdInputAddress = textCollection[i].id; if(textGoogleSearchCollection[i].value == 'false') { var addressObj = new addressObjJs(currentInputAddress); var addressesObj = new addressesObjJs(currentIdInputAddress); addressesObj.addresses.push(addressObj); arrayAddressesIndex++; arrayAddressProcessed[arrayAddressesIndex] = addressesObj; textCollectionProcessed[i] = 1; continue; } geocoder.getLocations(currentInputAddress, callbackGeocoder); textCollectionProcessed[i] = 1; return; } showResults(); } function callbackGeocoder(response) { if (!response || response.Status.code != 200) { showInformationPanel("Non è stata trovata nessuna corrispondenza per i parametri richiesti di partenza e/o destinazione."); return; } else { arrayAddressesIndex++; var addressesObj = new addressesObjJs(currentIdInputAddress); if (response.Placemark.length == 1) { var addressObj = new addressObjJs(response.Placemark[0]); addressesObj.addresses.push(addressObj); } else { for(k=0; k < response.Placemark.length; k++) { var addressObj = new addressObjJs(response.Placemark[k]); addressesObj.addresses.push(addressObj); } } arrayAddressProcessed[arrayAddressesIndex] = addressesObj; calculateItinerary(); } } function showResults() { for(i=0; i < arrayAddressProcessed.length; i++) { var idInputAddress = arrayAddressProcessed[i].idInputAddress; if(arrayAddressProcessed[i].addresses.length > 1) { populateTextObj(idInputAddress, i, 0); document.getElementById("addToPoiUser_" + (i + 1)).style.display = "inline"; var content = "
" + arrayAddressProcessed[0].addresses[0].addressValue + "
" + arrayAddressProcessed[1].addresses[0].addressValue + "";
setInnerHTML(ID_MAP_HEADER, contentItinerary);
}
function populateTextObj(idObj, indexI, indexJ)
{
setObjValue(idObj + "_lat", arrayAddressProcessed[indexI].addresses[indexJ].latitude);
setObjValue(idObj + "_lon", arrayAddressProcessed[indexI].addresses[indexJ].longitude);
setTextBox(idObj, arrayAddressProcessed[indexI].addresses[indexJ].addressValue, '');
if(getById(idObj).value != "" && getById(idObj).value != MESSAGES['commons.label.defaulttextobjaddress'])
getById('clearButton_1').src = "images/ico_delete.gif";
hideAddressesPanel();
}