• Publicidad (ayudanos a mantener el Foro haciendo un click sobre la misma)
  • Cuixer, una forma de administrar páginas web que nunca viste!

Ext.ux.GMapPanel - Google Maps v.3

Comparte tus mejoras y extensiones para Ext 3.0.

Ext.foro.Nuevo
Mensajes: 2
Registrado: 21 Ene 2009, 07:37
NotaPublicado: 20 Oct 2010, 06:47
Aqui os dejo la extension GMapPanel co la nueva version de google maps v3.2, además se incluye la opcion de poder modificar el marcador del punto a mostrar.

Ext.ux.GMapPanel
Código: Seleccionar todo
/**
* @class Ext.ux.GMapPanel
* @extends Ext.Panel
* @author Rafael Ruiz
*/
Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
   
    initComponent : function(){
      this.markersArray_overlay= new Array();
        var defConfig = {
            plain: true,
            zoomLevel: 3,
            yaw: 180,
            pitch: 0,
            zoom: 1,
            gmapType: 'map',
            border: false
        };
       
        Ext.applyIf(this,defConfig);
       
        Ext.ux.GMapPanel.superclass.initComponent.call(this);       

    },
    afterRender : function(){
       
        var wh = this.ownerCt.getSize();
        Ext.applyIf(this, wh);
       
        Ext.ux.GMapPanel.superclass.afterRender.call(this);   
       
               
        var myLatlng = new google.maps.LatLng(0, 0);
        var myOptions = {
          zoom: this.zoomLevel,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
       
        var myLatlong=new google.maps.LatLng(this.setCenter.lat,this.setCenter.lng)
        var panoramaOptions = {
                 position:myLatlong,
                 pov: {
                   heading: this.yaw,
                   pitch:this.pitch,
                   zoom:this.zoom
                 }
               };

                   
       
        if (this.gmapType === 'map'){
            this.gmap = new google.maps.Map(this.body.dom, myOptions);
        }
       
        if (this.gmapType === 'panorama'){
            this.gmap = new google.maps.StreetViewPanorama(this.body.dom,panoramaOptions);
           
        }
       
       
       
        google.maps.event.trigger(this.gmap, 'resize');
       
        if (typeof this.setCenter === 'object') {
           if (typeof this.setCenter.geoCodeAddr === 'string'){
               this.geoCodeLookup(this.setCenter.geoCodeAddr);
            }else{
               if (this.gmapType === 'map'){
                  var point = new google.maps.LatLng(this.setCenter.lat,this.setCenter.lng);
                   this.gmap.setCenter(point);
               }
               if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){                   
                    this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
                }
               this.onMapReady();
            }           
           
        }

     

    },
    onMapReady : function(){
       if(this.gmapType === 'map'){
        this.addMarkers(this.markers);
        this.addMapControls();
        this.addOptions(); 
       }
    },
    onResize : function(w, h){

        Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);

    },
    setSize : function(width, height, animate){
       
        Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
       
    },
    getMap : function(){
       
        return this.gmap;
       
    },
    getCenter : function(){
       
        return this.getMap().getCenter();
       
    },
    getCenterLatLng : function(){
       
        var ll = this.getCenter();
        return {lat: ll.lat(), lng: ll.lng()};
       
    },
    addMarkers : function(markers) {
   
        if (Ext.isArray(markers)){
            for (var i = 0; i < markers.length; i++) {
               
               if (typeof markers[i].geoCodeAddr === 'string'){
                  
                  this.geoCodeLookupMarker(markers[i].geoCodeAddr);
                  
                  var mkr_point = this.getMap().getCenter();
                  this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners, markers[i].image);
                   
                }else{
                   var mkr_point = new google.maps.LatLng(markers[i].lat,markers[i].lng);
                   this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners, markers[i].image);
                }
               
            }
        }
       
    },
    addMarker : function(point, marker, clear, center, listeners, imagen){
       
        Ext.applyIf(marker,new google.maps.Marker());
       
        if(imagen!=null){   
        var blueIcon = new google.maps.MarkerImage(imagen.imageurl,
                 // This marker is 20 pixels wide by 32 pixels tall.
                 new google.maps.Size(imagen.imagewidth, imagen.imageheight),
                 // The origin for this image is 0,0.
                 new google.maps.Point(0,0),
                 // The anchor for this image is the base of the flagpole at 0,32.
                 new google.maps.Point(imagen.imagewidth/2, imagen.imageheight));
           if(imagen.imageurl_shadow!=null){
           var blueIcon_shadow = new google.maps.MarkerImage(imagen.imageurl_shadow,
               // The shadow image is larger in the horizontal dimension
               // while the position and offset are the same as for the main image.
               new google.maps.Size(imagen.imagewidth_shadow, imagen.imageheight_shadow),
               new google.maps.Point(0,0),
               new google.maps.Point(imagen.imagewidth/2, imagen.imageheight_shadow));
             
             
             
            
            // Set up our GMarkerOptions object
            marker = new google.maps.Marker({position:point, title:marker.title, icon:blueIcon, shadow: blueIcon_shadow, map: this.getMap() });
           }else{
              marker = new google.maps.Marker({position:point, title:marker.title, icon:blueIcon, map: this.getMap() });
           }
        }else{
           marker = new google.maps.Marker({position:point, title:marker.title, map: this.getMap() });
        }
        if (clear === true){
           if ( this.markersArray_overlay) {
                for (o in this.markersArray_overlay) {
                   this.markersArray[o].setMap(null);
                }
                this.markersArray_overlay.length = 0;
           }

        }
        if (center === true) {
            this.getMap().setCenter(point);
        }

        var mark = marker;
        if (typeof listeners === 'object'){
            for (evt in listeners) {
               google.maps.event.addListener(mark, evt, listeners[evt]);
            }
        }
        this.markersArray_overlay.push(mark);

       

    },
    addMapControls : function(){
       
        if (this.gmapType === 'map') {
            if (Ext.isArray(this.mapControls)) {
                for(i=0;i<this.mapControls.length;i++){
                    this.addMapControl(this.mapControls[i]);
                }
            }else if(typeof this.mapControls === 'string'){
                this.addMapControl(this.mapControls);
            }else if(typeof this.mapControls === 'object'){
                this.getMap().addControl(this.mapControls);
            }
        }
       
    },
    addMapControl : function(mc){
       
        var mcf = window[mc];
        if (typeof mcf === 'function') {
            this.getMap().addControl(new mcf());
        }   
       
    },
    addOptions : function(){
       
        if (Ext.isArray(this.mapConfOpts)) {
            var mc;
            for(i=0;i<this.mapConfOpts.length;i++){
                this.addOption(this.mapConfOpts[i]);
            }
        }else if(typeof this.mapConfOpts === 'string'){
            this.addOption(this.mapConfOpts);
        }       
       
    },
    addOption : function(mc){
       
        var mcf = this.getMap()[mc];
        if (typeof mcf === 'function') {
            this.getMap()[mc]();
        }   
       
    },
    geoCodeLookup : function(addr) {
       
        this.geocoder = new google.maps.Geocoder();
        this.geocoder.geocode({'address':addr}, this.addAddressToMap.createDelegate(this));
    },
    addAddressToMap : function(response, status) {
       
       if (status == google.maps.GeocoderStatus.OK) {
          this.getMap().setCenter(response[0].geometry.location);
           
          this.onMapReady();
       }else{
          Ext.MessageBox.alert('Unable to Locate Address', 'Geocode was not successful for the following reason: '+status);
       }
       
    },   
   
    geoCodeLookupMarker : function(addr) {
       this.geocoder = new google.maps.Geocoder();
       this.geocoder.geocode({'address':addr}, this.addAddressToMapMarker.createDelegate(this));
    },
    addAddressToMapMarker : function(response, status) {
       if (status == google.maps.GeocoderStatus.OK) {
          this.getMap().setCenter(response[0].geometry.location);
         
       }else{
          Ext.MessageBox.alert('Unable to Locate Address', 'Geocode was not successful for the following reason: '+status);
       }
       
       
    }

});

Ext.reg('gmappanel', Ext.ux.GMapPanel);



Ejemplo de llamada:
Código: Seleccionar todo
{
                  xtype: 'gmappanel',
                  zoomLevel: 14,
                  gmapType: 'map',
                  width:480,
                  height:480,
                  mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
                  mapControls: ['GSmallMapControl','GMapTypeControl'],
                  setCenter: {
                                                                                                         lat: [latitud_punto],
                                                     lng:  [longitud_punto],
                                                                                                         marker: false
                                                                                  },
                                                                                  markers: [{
                                                                                                         lat: [latitud_punto],
                                                     lng:  [longitud_punto],
                                                                                                         setCenter:true,
                                                                                                          marker: {title: '[titulo_marcador]'
                                                                                               },
                                                                                 listeners: {
                                                       click: function(e, mark){
                                                                                                     // funcion que se desee ejecutar
                                                                                              }
                                                                                             },
                                           image:{ imageurl:'[url_imagen_marcador]', imagewidth:[ancho_imagen_marcador], imageheight:[alto_imagen_marcador], imageurl_shadow:'[url_imagen_sombra_marcador]', imagewidth_shadow:[ancho_imagen_sombra_marcador], imageheight_shadow:[alto_imagen_sombra_marcador]}
                       }]
               }
Para no ver esta publicidad, debes ser usuario del Foro.
Publicidad (ayudanos a mantener el Foro haciendo un click sobre la misma)


Cuixer, una forma de administrar páginas web que nunca viste!

Avatar de Usuario
Ext.foro.Administrador
Mensajes: 1932
Registrado: 07 Mar 2008, 20:45
Ubicación: Argentina
NotaPublicado: 27 Oct 2010, 03:28
Perfecto! Gracias por compartirla! ;)
Aprender haciendo...
Desarrollo de aplicaciones en ExtJS [CONSULTAR].
Buscar en el foro antes de preguntar y Leer la Documentación.
Imagen

Volver a Ext 3.0: Extensiones y mejoras





  • Publicidad (ayudanos a mantener el Foro haciendo un click sobre la misma)
  • Cuixer, una forma de administrar páginas web que nunca viste!