1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Sallanches, France
    Posts
    371
    Answers
    16
    Vote Rating
    1
    myput is on a distinguished road

      0  

    Default Unanswered: call function inside panel with add?

    Unanswered: 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Answers
    3549
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1