The More with symfony book

Appendice A - codice JavaScript per sfWidgetFormGMapAddress

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The More with symfony book" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com
symfony training
Be trained by symfony experts
Feb 21: Köln (Getting Started with Symfony2 - English)
Feb 27: Köln (Mastering Symfony2 - English)
Mar 05: Köln (Web Development with Symfony2 - Deutsch)
Mar 05: Montreal (Web Development with Symfony2 - English)
Mar 05: Montreal (Getting Started with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The More with symfony book" in Italian for the 1.4 version - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
More with Symfony
Support symfony!
Buy this book
or donate.
Buy More with Symfony from amazon.com

Il seguente codice è il JavaScript necessario per far funzionare il widget sfWidgetFormGMapAddress:

function sfGmapWidgetWidget(options){
  // attributi globali di this
  this.lng      = null;
  this.lat      = null;
  this.address  = null;
  this.map      = null;
  this.geocoder = null;
  this.options  = options;
 
  this.init();
}
 
sfGmapWidgetWidget.prototype = new Object();
 
sfGmapWidgetWidget.prototype.init = function() {
 
  if(!GBrowserIsCompatible())
  {
    return;
  }
 
  // recupera l'elemento del dom
  this.lng      = jQuery("#" + this.options.longitude);
  this.lat      = jQuery("#" + this.options.latitude);
  this.address  = jQuery("#" + this.options.address);
  this.lookup   = jQuery("#" + this.options.lookup);
 
  // crea l'oggetto google geocoder
  this.geocoder = new GClientGeocoder();
 
  // crea la mappa
  this.map = new GMap2(jQuery("#" + this.options.map).get(0));
  this.map.setCenter(new GLatLng(this.lat.val(), this.lng.val()), 13);
  this.map.setUIToDefault();
 
  // riferimenti incrociati tra gli oggetti
  this.map.sfGmapWidgetWidget = this;
  this.geocoder.sfGmapWidgetWidget = this;
  this.lookup.get(0).sfGmapWidgetWidget = this;
 
  // aggiunge la località predefinita
  var point = new GLatLng(this.lat.val(), this.lng.val());
  var marker = new GMarker(point);
  this.map.setCenter(point, 15);
  this.map.addOverlay(marker);
 
  // collega l'azione di movimento sulla mappa
  GEvent.addListener(this.map, "move", function() {
     var center = this.getCenter();
     this.sfGmapWidgetWidget.lng.val(center.lng());
     this.sfGmapWidgetWidget.lat.val(center.lat());
  });
 
  // collega l'azione click sulla mappa
  GEvent.addListener(this.map, "click", function(overlay, latlng) {
    if (latlng != null) {
      sfGmapWidgetWidget.activeWidget = this.sfGmapWidgetWidget;
 
      this.sfGmapWidgetWidget.geocoder.getLocations(
        latlng,
        sfGmapWidgetWidget.reverseLookupCallback
      );
    }
  });
 
  // collega l'azione click al campo di ricerca
  this.lookup.bind('click', function(){
    sfGmapWidgetWidget.activeWidget = this.sfGmapWidgetWidget;
 
    this.sfGmapWidgetWidget.geocoder.getLatLng(
      this.sfGmapWidgetWidget.address.val(),
      sfGmapWidgetWidget.lookupCallback
    );
 
    return false;
  })
}
 
sfGmapWidgetWidget.activeWidget = null;
sfGmapWidgetWidget.lookupCallback = function(point)
{
  // prende il widget e pulisce la variabile di stato
  var widget = sfGmapWidgetWidget.activeWidget;
  sfGmapWidgetWidget.activeWidget = null;
 
  if (!point) {
    alert("address not found");
    return;
  }
 
  widget.map.clearOverlays();
  widget.map.setCenter(point, 15);
  var marker = new GMarker(point);
  widget.map.addOverlay(marker);
}
 
sfGmapWidgetWidget.reverseLookupCallback = function(response)
{
  // prende il widget e pulisce la variabile di stato
  var widget = sfGmapWidgetWidget.activeWidget;
  sfGmapWidgetWidget.activeWidget = null;
 
  widget.map.clearOverlays();
 
  if (!response || response.Status.code != 200) {
    alert('no address found');
    return;
  }
 
  // prende l'informazione sulla località e inizializza le variabili
  var place = response.Placemark[0];
  var point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
  var marker = new GMarker(point);
 
  // aggiunge il segnalino al centro della mappa
  widget.map.setCenter(point, 15);
  widget.map.addOverlay(marker);
 
  // aggiorna i valori
  widget.address.val(place.address);
  widget.lat.val(place.Point.coordinates[1]);
  widget.lng.val(place.Point.coordinates[0]);
}
Appendice B - Esempio di installazione personalizzata »

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.