First I we need a map, for example this one here:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
xtype: 'map', | |
height: '100%', | |
id: 'examplemap', | |
width: '100%', | |
listeners: [{ | |
fn: function(element, eOpts) { | |
console.log('Map Painted'); | |
someControllerRef.centerMap(); | |
}, | |
event: 'painted' | |
}] | |
} |
Now comes the important part. You need to add a listener on your map for the painted event. When the painted event is fired we do also need a timeout to set the center. This can be really small.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixThisCenterProblem() { | |
mapPainted = Ext.getCmp('examplemap') || this; | |
var LatLng = new google.maps.LatLng(dummyLatitude, dummyLongitude); | |
setTimeout( | |
function() { | |
mapPainted.setMapCenter(LatLng); | |
}, 500); | |
} |
This should to it, the map will now be centered correctly.
Keine Kommentare:
Kommentar veröffentlichen