Results 1 to 2 of 2

Thread: call function inside panel with add?

  1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Answers
    16
    Vote Rating
    1
      0  

    Default call function inside panel with add?

    Hello,

    I have a panel and i want to call an another panel with a function inside who create a map.
    I need this configuration because i want to give latitude and longitude in variable;

    How can i call a function in a panel with beforerender please?

    what i have:
    The main panel:
    Code:
    App.views.DirectoryDetailPanelMap = new Ext.Panel ({
    	fullscreen: true,
    	dockedItems: [App.views.DirectoryDetailPanelMapToolbar],
    	listeners: {
    		beforerender: function() {
    			App.views.DirectoryDetailPanelMap.add(App.views.DirectoryDetailPanelMapCreateMap);
    			//App.views.DirectoryDetailPanelMapCreateMap.initMap("45.935", "6.632");
    		}
    	}
    });
    and the map Panel:
    Code:
    App.views.DirectoryDetailPanelMapCreateMap = new Ext.Panel ({
    	fullscreen: true,
    	initMap: function(latitude, longitude) {
    		var pos = new google.maps.LatLng(latitude, longitude);
    		var desc = '<div class=\'WPAppMapInfoWindow\'>' + data.markerTitle + '<br/>' + data.markerDescription + '</div>';
    		var isRefreshRequired = false;
    		if (this.getComponent(0).getXTypes() === 'box/map') {
    			this.remove(this.getComponent(0));
    			isRefreshRequired = true;
    		}
    		var map = new Ext.Map ({
    			fullscreen: true,
    			title: data.name,
    			markerDesc: desc,
    			markerPos: pos,
    			mapOptions: {
    				zoom: 5,
    				mapTypeId: google.maps.MapTypeId.TERRAIN,
    				center: pos,
    				mapTypeControl: true,
    			},
    			listeners: {
    				delay: 500,
    				afterrender: function(){
    					addMarker(this.map, this.markerPos, this.markerDesc);
    				}
    			}
    		});
    		this.add(map);
    		if(isRefreshRequired) this.doLayout();
    	}
    });
    I don't know how to do for call the function initMap since a panel please

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    I would actually create a utility class for that:

    Code:
    AppUtils = {
        initMap: function(latitude, longitude) {
    		var pos = new google.maps.LatLng(latitude, longitude);
    		var desc = '<div class=\'WPAppMapInfoWindow\'>' + data.markerTitle + '<br/>' + data.markerDescription + '</div>';
    		var isRefreshRequired = false;
    		if (this.getComponent(0).getXTypes() === 'box/map') {
    			this.remove(this.getComponent(0));
    			isRefreshRequired = true;
    		}
    		var map = new Ext.Map ({
    			fullscreen: true,
    			title: data.name,
    			markerDesc: desc,
    			markerPos: pos,
    			mapOptions: {
    				zoom: 5,
    				mapTypeId: google.maps.MapTypeId.TERRAIN,
    				center: pos,
    				mapTypeControl: true,
    			},
    			listeners: {
    				delay: 500,
    				afterrender: function(){
    					addMarker(this.map, this.markerPos, this.markerDesc);
    				}
    			}
    		});
    		this.add(map);
    		if(isRefreshRequired) this.doLayout();
    	}
    };
    Now you have a problem because you use 'this' within that. You can do two things...

    Add an argument in the initMap that is the component and replace 'this' with that argument.

    You can change the scope of the call like this: AppUtil.initMap.call(this, long, lat);
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •