}
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
//called, when html and scripts are loaded.
initialize();
});
function initialize() {
//loads the map
var latlng = new google.maps.LatLng(51.31893, 9.49601); //Kassel, Germany
var myOptions = {
zoom: 7,
center: latlng,
mapTypeControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
markerMgr = new MarkerManager(map);
}
File MarkerManager.js:
function MarkerManager(map, opt_opts) {
var me = this;
me.map_ = map;
me.projectionHelper_ = new ProjectionHelperOverlay(map);
google.maps.event.addListener(me.projectionHelper_, 'ready', function () {
me.projection_ = this.getProjection();
me.initialize(map, opt_opts);
});
function ProjectionHelperOverlay(map) {
this.setMap(map); //method of google.maps.OverlayView
this._map = map;
this._zoom = -1;
this._X0 =
this._Y0 =
this._X1 =
this._Y1 = -1;
}
// ProjectionHelperOverlay inherits from google.maps.OverlayView
ProjectionHelperOverlay.prototype = new google.maps.OverlayView();
/**
* Draw function only triggers a ready event for
* MarkerManager to know projection can proceed to
* initialize.
*/
ProjectionHelperOverlay.prototype.draw = function () {
if (!this.ready) {
this.ready = true;
google.maps.event.trigger(this, 'ready');
}
};
}
When the app is loaded asynchronously I got the Error in ProjectionHelperOverlay(map)
this.setMap is not a function.
When stepping slowly with the debugger, sometimes the app works correctly. So I assume there will be a timing problem.
When loading synchronously the app worked correctly.
------------------------------------------------------------------------------------------------------------------