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

GmapPanel

Comparte tus mejoras y extensiones para Ext 4.0.

Ext.foro.Nuevo
Mensajes: 2
Registrado: 21 Ene 2009, 07:37
NotaPublicado: 16 Jun 2011, 08:32
Como con la version 3, aqui os traigo el plugin GmapPanel para la version Ext 4.0.2, tiene las mismas caracteristicas que en la 3:
- Poner una imagen personalizada de para el punto
- Puntos por latitud y longitud, y por direccion.
- Insercion de eventos.

Código: Seleccionar todo
Ext.define('Ext.ux.GMapPanel', {
    extend: 'Ext.Panel',
   
    alias: 'widget.gmappanel',

    requires: ['Ext.window.MessageBox'],
   
    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);
       
        this.callParent();

    },
    afterRender : function(){
       
        var wh = this.ownerCt.getSize(),
        point;
       
       Ext.applyIf(this, wh);
      
       this.callParent();   
      
       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);
       }
      
       //if (typeof this.addControl == 'object' && this.gmapType === 'map') {
       //    this.gmap.addControl(this.addControl);
       //}
      

        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'){
                  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();
           }
           /*if (this.gmapType === 'panorama'){
               this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
           }*/
       }
   
      /* GEvent.bind(this.gmap, 'load', this, function(){
           this.onMapReady();
       });*/
    // google.maps.event.addListener(this.gmap, 'load', this, function(){
          // alert('asdfjmjmh');
           
        //});

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

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

    },
    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);

        //this.getMap().addOverlay(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)) {
            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);
            /*var marker = new google.maps.Marker({
                map: this.getMap(),
                position: response[0].geometry.location
            });
            this.markersArray_overlay.push(marker);*/
          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);
           /* var marker = new google.maps.Marker({
                map: this.getMap(),
                position: response[0].geometry.location
            });
            this.markersArray_overlay.push(marker);*/
       }else{
          Ext.MessageBox.alert('Unable to Locate Address', 'Geocode was not successful for the following reason: '+status);
       }
       
       
    }

});



Ejemplo de una llamada al plugin:
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: 16 Jun 2011, 18:09
Muchas gracias por compartirlo. Se agradece. :)
Aprender haciendo...
Desarrollo de aplicaciones en ExtJS [CONSULTAR].
Buscar en el foro antes de preguntar y Leer la Documentación.
Imagen

Ext.foro.Nuevo
Mensajes: 1
Registrado: 28 Nov 2011, 11:40
NotaPublicado: 27 Feb 2012, 15:15
consulta soy nuevo en esto de los gmappanel

De donde puedo sacar ejemplos de como crear marcas de forma dinamica.

En resumidas cuentas necesito poder agregar marcas al mapa cuando se seleccione un elemento de una grilla(esta contiene la latitud y longitud del elemento seleccionado), el cual se debe actualizar cada cierto tiempo.

Volver a Ext 4.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!