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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1381
      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
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    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
  •