This project is read-only.

InfoWindow is shown before the second click

Dec 6, 2009 at 12:51 AM

Hi. I am dynamically adding Markers to the map. and handle the events. But I have a problem with that. here is my code

 

   protected void Page_Load(object sender, EventArgs e)
        {
           
                GoogleMap1 = new GoogleMap();
                GoogleMap1.Width = new Unit(800);
                GoogleMap1.Height = new Unit(600);
                GoogleMap1.Key = Key;
                GoogleMap1.Markers.Add(new GoogleMarker("istanbul"));
                GoogleMap1.MarkerEvents.Click += new EventHandler<GoogleLocationEventArgs>(MarkerEvents_Click);   
                GoogleMap1.Address = "istanbul";
                Panel1.Controls.Add(GoogleMap1);
         
        }

   
        

        void MarkerEvents_Click(object sender, Artem.Web.UI.Controls.GoogleLocationEventArgs e)
        {
            GoogleMarker gm = sender as GoogleMarker;
            gm.InfoContent.Controls.Add(LoadControl("~/InfoWindowControl.ascx"));
            GoogleMap1.MarkerEvents.Click -= new EventHandler<GoogleLocationEventArgs>(MarkerEvents_Click);
        }



My problem is, when I first click the marker, an empty info window is shown. But after the second click, I get what I want.
What can I do for that ?

Dec 6, 2009 at 6:06 PM

Hi

Try adding the InfoWindowContent control  in Page_Load, as well.
It is shown after the first click, because you actually add it when click occurs.
So, before first click to occur, the info window content is missing and that why it is empty.

Regards

Dec 7, 2009 at 4:39 PM
Edited Dec 7, 2009 at 4:40 PM

Hi,

I have tested your case with dynamically added markers and adding UserControl to their InfoContent.
Obviously at present version the InfoContent of markers is not persisted by GoogleMap control.
So, you have to add that UserControl every time you need it.

What I did is adding the InfoContent every time OnPreRender instead just when map double clicked.
Here bellow is the code of my test.

Page markup:

<artem:GoogleMap ID="GoogleMap1" runat="server" Latitude="42.1229" Longitude="24.7879"
    EnableScrollWheelZoom="true" OnDoubleClick="HandleMapDoubleClick">
</artem:GoogleMap>
<asp:Button ID="btnPost" runat="server" Text="Post" />

Code-behind:

public partial class marker_InfoContent : System.Web.UI.Page {

    #region Methods ///////////////////////////////////////////////////////////////////////////

    protected void HandleMapDoubleClick(object sender, GoogleLocationEventArgs e) {

        GoogleMarker marker = new GoogleMarker(e.Location.Latitude, e.Location.Longitude);
        GoogleMap1.Markers.Add(marker);
    }

    protected override void OnPreRender(EventArgs e) {
        base.OnPreRender(e);

        foreach (GoogleMarker marker in GoogleMap1.Markers) {
            marker.InfoContent.Controls.Add(LoadControl("~/controls/TestInfoContent.ascx"));
        }
    }
    #endregion
}
Hope this helps.
Regards
Dec 12, 2009 at 3:07 PM

Hi velio;

I still have the same problem, then I started to search it again. I found

<div id="GoogleMap1asdasd_Templates" style="display: none;">
<div id="Marker0Content">
<span>
my data
</span>
</div>
</div>


I think this is the div that the marker has to show when it is clicked. So I believe the problem is in the second or further clicks, script cannot find that div "

GoogleMap1asdasd_Templates". 
So where can be the problem?