예제 #1
0
 public function init()
 {
     // Set defaults
     $this->matchValues($this->model, $this->options);
     $this->options['markers'] = array('latitude' => (double) $this->model[$this->attributeLat], 'longitude' => (double) $this->model[$this->attributeLon], 'draggable' => true);
     parent::init();
     $cs = Yii::app()->getClientScript();
     $idLat = $this->resolveID($this->attributeLat);
     $idLon = $this->resolveID($this->attributeLon);
     $idZoom = $this->resolveID($this->attributeZoom);
     $cs->registerScript("GMapsInputWidget" . $this->id, '
         GEvent.addListener($.googleMaps.gMap, "tilesloaded", function() {
             var marker = $.googleMaps.marker[0];
             if (typeof marker != "undefined") {
                 GEvent.addListener(marker, "dragend", function() {
                     $("#' . $idLat . '").val(marker.getPoint().lat());
                     $("#' . $idLon . '").val(marker.getPoint().lng());
                 });
                 GEvent.addListener($.googleMaps.gMap, "zoomend", function() {
                     $("#' . $idZoom . '").val($.googleMaps.gMap.getZoom());
                 });
                 GEvent.addListener($.googleMaps.gMap, "click", function(overlay, latLng) {
                     marker.setLatLng(latLng);
                     $("#' . $idLat . '").val(latLng.lat());
                     $("#' . $idLon . '").val(latLng.lng());
                 });
             }
         });
     ');
 }