reinitiate tabbed Infowindow

103 views
Skip to first unread message

geom

unread,
Feb 22, 2012, 4:43:47 AM2/22/12
to Google Maps JavaScript API v3
I use an tabbed infowindow to add infos to a database.
When the infowindow displays first, everything works fine.
The second infowindow shows only the tabs, but without my form.

The infowindows are creted by this way:

<code>
infowindow = new google.maps.InfoWindow({content: contentString});

//Add listener to map, to insert new Marker
google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
map.setCenter(event.latLng);
map.setZoom(17);

google.maps.event.addListener(infowindow, 'domready', function() {
addTabbar();
});
</code>

where the addTabbar-function looks like this, where tab1, tab2 and
tab3 are the id's of the div's with the forms:

<code>
function addTabbar() {
tabbar=new dhtmlXTabBar("tabbar","top");
tabbar.setImagePath("./dhtmlx/imgs/");
tabbar.addTab("b1","Sorte","100px");
tabbar.addTab("b2","Zustand","100px");
tabbar.addTab("b3","Pflanzung","100px");
tabbar.setContent("b1","tab1");
tabbar.setContent("b2","tab2");
tabbar.setContent("b3","tab3");
tabbar.setTabActive('b1');
}
</code>


After the form is filled in the data is saved via saveData() to the
database and on success the infowindow is closed.

<code>
if (responseCode == 200 && data.length <= 1) {
alert("Baum in der Datenbank gespeichert.");
infowindow.close();
marker.setDraggable(false);
</code>

But it seems that the infowindow still persists so that the next
infowindow cannot create the divs with the same id's.
Is there a way to reinitiate the infowindows so that the second, and
third one will behave like the first one created?

Georges


geom

unread,
Feb 23, 2012, 10:06:24 AM2/23/12
to google-map...@googlegroups.com
I had to change the code the following way, so that the tabbed infowindow is created within the function that creates the new marker.
To clear the infowindow after inserting the data to the database I added infowindow=null at the end of the saveData()-function.

<code>
//Add listener to map, to insert new Marker and create infowindow

google.maps.event.addListener(map, "click", function(event) {
    marker = new google.maps.Marker({
          position: event.latLng,
          map: map,
          draggable: true
        });
    map.setCenter(event.latLng);
    map.setZoom(17);

infowindow = new google.maps.InfoWindow({
content: contentString});

    google.maps.event.addListener(infowindow, 'domready', function() {
      addTabbar();
    });
</code>

 and in saveData() i added to the end of the function:


<code>
        if (responseCode == 200 && data.length <= 1) {
          alert("Baum in der Datenbank gespeichert.");
          infowindow.close();
          marker.setDraggable(false);
          infowindow=null;
</code>


 

Pil

unread,
Feb 23, 2012, 11:30:34 AM2/23/12
to Google Maps JavaScript API v3
It's laudable that you make your solution pulic - although you didn't
reveal all the code to create the tabs, so it's useless.
Reply all
Reply to author
Forward
0 new messages