javascript - google maps: open infowindow after map & marker load -
i'm working google maps api 3. it's bit of annoyance, how infowindow.open
after marker , map have loaded?
i've tried add various listeners such tilesloaded
, idle
, haven't had joy.
in working example see infowindow
loading before else: http://codepen.io/anon/pen/wvbexy
function initialize() { if (document.getelementbyid("maper")) { var latlng = new google.maps.latlng(52.370778, 4.899448); var mapoptions = { zoom: 11, center: latlng, scrollwheel: "", scalecontrol: "", disabledefaultui: "", maptypeid: google.maps.maptypeid.roadmap }; var tinygmaps = new google.maps.map(document.getelementbyid("maper"), mapoptions); var marker = new google.maps.marker({ map: tinygmaps, position: tinygmaps.getcenter() }); var contentstring = '<p>why me first?</p>'; var infowindow = new google.maps.infowindow({ content: contentstring, position: latlng, }); infowindow.open(tinygmaps, marker); //var openwindow = google.maps.event.addlistener(tilelistener, 'tilesloaded', open_infowindow); // hummmm! } } google.maps.event.adddomlistener(window, 'load', initialize); function open_infowindow() { infowindow.open(tinygmaps, marker); google.maps.event.removelistener(tilelistener); };
edit: changed codepen listen tilesloaded before displaying infowindow. fork of codepen tilesloaded listener here: http://codepen.io/brenzy/pen/vlywgn
because needs code:
google.maps.event.addlisteneronce(tinygmaps, 'tilesloaded', function() { // open infowindow });
on machine, listening both tilesloaded , idle appear function same. (without either listener, infowindow displayed before map.)
i assuming version didn't work, because missed line
infowindow.open(tinygmaps, marker);
when refactoring, infowindow being opened before listener fired.
Comments
Post a Comment