-
16 Nov 2011 1:59 AM #1
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:
and the map 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"); } } });
I don't know how to do for call the function initMap since a panel pleaseCode: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(); } });
-
17 Nov 2011 12:19 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3161
I would actually create a utility class for that:
Now you have a problem because you use 'this' within that. You can do two things...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(); } };
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote