1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    4
    Vote Rating
    0
    quicklink is on a distinguished road

      0  

    Question Mark and infowindow in Ext.Map, InfoWindow not work?

    Mark and infowindow in Ext.Map, InfoWindow not work?


    Hi, When I add more markers with each marker its infowindow, it seems that every marker points to last infowindow added.


    This is the code:

    Code:
    painted: function(me){
                     if(debug)
                         console.log('map.painted', me);
                        //get map instance
                        var map = me.getMap();
                        //get data from store.
                        var locations = store.data.items;
                        //var for determinate the rectangle in geographical coordinates
                        var latlngbounds = new google.maps.LatLngBounds( );
                        //parse data and add one marker for each locations.
                        for (var i = 0; i < locations.length; i++) 
                        {
                          //get coordinates after check the elements have coordinates.
                          if (locations[i].data.latitude != null && locations[i].data.longitude != null)
                          {
                              var currentCoord = new google.maps.LatLng(locations[i].data.latitude, locations[i].data.longitude);
                              //create marker
                              var marker = new google.maps.Marker({
                              position: currentCoord,
                            title : locations[i].data.displayName,
                                map: map
                              });
                              
                              //add coordinates into LatLngBounds
                              latlngbounds.extend(currentCoord);        
                              
                              //add into obixWatch the status uri
                              obixWatch.addURIs([ { uri:locations[i].data.statusUri, handler:me.config.updateMarkerStatus, dispName:'', pickle:marker } ]);
                              
                              var childNodes = locations[i].childNodes;
                              
                              //Create popup
                              var infowindow = new google.maps.InfoWindow({
                            content: locations[i].data.displayName
                            });
                            
                            //Add into ObixWatch all childs status.
                              for (var j = 0; j < childNodes.length; j++) {
                                  obixWatch.addURIs([ { uri:childNodes[i].data.statusUri, handler:me.config.updatePopupStatus, dispName:childNodes[i].data.displayName, pickle:infowindow, item:locations[i].data.statusUri } ]);
                              }
                              
                                         //add event to manage the click operation into marker.
                               google.maps.event.addListener(marker, 'click', function() {
                                  infowindow.open(map, marker);
                           });
                          }
                      }
                      //Center the view in the map.   
                      map.setCenter( latlngbounds.getCenter());//TODO: funziona corrett. solo se esco e rientro in mappa. Why?
                    }
             },

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You should put the infowindow instance on the marker.

    Code:
    marker.infowindow = new new google.maps.InfoWindow({....});
    Then you can do this:

    Code:
    google.maps.event.addListener(marker, 'click', function() {
        marker.infowindow.open(map, marker);
    });
    Although what is the marker variable within the function?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    4
    Vote Rating
    0
    quicklink is on a distinguished road

      0  

    Default


    I tried to do as you said but I get the same result.
    you have no idea why?


    Code:
                    show: function(me)                {
                        if (debug)
                            console.log('map.show', me);
                            
                        // get map instance
                        var map = me.getMap();
                        
                        // get data from store
                      var locations = store.data.items;
                      
                      // var for determinate the rectangle in geographical coordinates
                      var latlngbounds = new google.maps.LatLngBounds();
                      
                      //Support var with uri to be added into obixwatch
                      var uris = [];
                      
                      // parse data and add one marker for each locations
                      for (var i = 0; i < locations.length; i++) 
                      {
                          // get coordinates after check the elements have coordinates
                          if (locations[i].data.latitude != null && locations[i].data.longitude != null)
                          {
                              var currentCoord = new google.maps.LatLng(locations[i].data.latitude, locations[i].data.longitude);
                              
                              // create marker
                              var marker = new google.maps.Marker({
                              position: currentCoord,
                            title : locations[i].data.displayName,
                                  infowindow: new google.maps.InfoWindow({ content: locations[i].data.displayName }),
                                map: map
                              });
                              
                              // add coordinates into LatLngBounds
                                        latlngbounds.extend(currentCoord);        
                              
                              // add into obixWatch the status uri
                                        uris.push({ uri: locations[i].data.statusUri, handler: me.config.updateMarkerStatus, dispName: '', pickle: marker });
                              
                              var childNodes = locations[i].childNodes;
                              
                              // create popup
    //                          var infowindow = new google.maps.InfoWindow({
    //                        content: locations[i].data.displayName
    //                        });
                                                      
                            // add into ObixWatch all childs status
                              for (var j = 0; j < childNodes.length; j++) {
                                  uris.push({ uri: childNodes[i].data.statusUri, handler: me.config.updatePopupStatus, dispName: childNodes[i].data.displayName, address: locations[i].data.address, pickle: marker.infowindow, item: locations[i].data.displayName });
                              }
                              
                                         // add event to manage the click operation into marker
                               google.maps.event.addListener(marker, 'click', function() {
                                  marker.infowindow.open(map, marker);
                           });
                          }
                      }
                      obixWatch.addURIs(uris);
                      
                      // center the view in the map   
                                map.setCenter(latlngbounds.getCenter());
    
                    }


  4. #4
    Sencha User
    Join Date
    Dec 2011
    Posts
    4
    Vote Rating
    0
    quicklink is on a distinguished road

      0  

    Default


    up

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You should do this in the maprender event.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1