Anonymous user  |  Log in  |  Create Account


Server Side and Client Side GMarker management
Return to the code gallery
Autor: subgurim
Publicado: 2/19/2008
Leído: 81449 veces
Comentarios (0)
Valoracion: 3.421874


/**** Explicación / Description  ****/
An example of how to add a GMarker and then manage it in client side. An external button opens an infowindow.

This example contains only one button and one GMarker, but similar code could be used to many buttons (or other controls) and many GMarkers.


/**** Código de servidor / Server code  ****/
using System;
using System.Web.UI;
using Subgurim.Controles;

public partial class Galeria_codigo_Ejemplos_ServerSideAndClientSideGMarkerManagement : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeServerSide();
            ConfigureClientSide();
        }
    }

    private void InitializeServerSide()
    {
        GLatLng latlng = new GLatLng(39, -0.5);

        GMarker marker = new GMarker(latlng);

        GMap1.Add(marker);
        InitializeClientSide(marker.ID);
    }

    private void InitializeClientSide(string markerId)
    {
        btnGInfoWindow.Attributes.Add("onclick", string.Format("windowMe('{0}');", markerId));
    }

    private void ConfigureClientSide()
    {
        string js =
            string.Format(
                @"
                function windowMe(markerId)
                {{
                    var marker = getGMapElementById({0},markerId);
                    marker.openInfoWindowHtml('Hello world!');
                }}
            ",
                GMap1.GMap_Id);

        GMap1.addCustomJavascript(js);
    }
}


/**** Código HTML / HTML Code  ****/
        <cc1:GMap ID="GMap1" runat="server" />
        <input id="btnGInfoWindow" type="button" value="ClickMe" runat="server" />



Powered by Subgurim.NET