Anonymous user  |  Log in  |  Create Account


GetBounds + serverEvents
Return to the code gallery
Autor: subgurim
Publicado: 1/22/2007
Leído: 60913 veces
Comentarios (0)
Valoracion: 4.875002


/**** Explicación / Description  ****/
Recogemos los límites superior derecha e inferior izquierda del mapa, lo mandamos al servidor y en éste creamos dos GMarkers que nos indican donde estaban los límites. Alejamos el zoom para tener una mejor visión de donde estaban los límites.

We get the map bounds, we send it to the server and finally we locate two GMarkers on those bounds. We make a zoom out to saw better where those Bounds were.


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

public partial class Galeria_codigo_Ejemplos_getBounds : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            setupMap();
        }
    }

    private void setupMap()
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("function getBounds()");
        sb.Append("{");
        sb.AppendFormat("var bounds = {0}.getBounds();", GMap1.GMap_Id);
        sb.Append("var southWest = bounds.getSouthWest();");
        sb.Append("var northEast = bounds.getNorthEast();");

        sb.AppendFormat("var ev = new serverEvent('bounds', {0});", GMap1.GMap_Id);
        sb.Append("ev.addArg(southWest.lat());");
        sb.Append("ev.addArg(southWest.lng());");
        sb.Append("ev.addArg(northEast.lat());");
        sb.Append("ev.addArg(northEast.lng());");
        sb.Append("ev.send();");
        sb.Append("}");


        GMap1.addCustomJavascript(sb.ToString());
    }

    protected string GMap1_ServerEvent(object s, Subgurim.Controles.GAjaxServerEventOtherArgs e)
    {
        string js = string.Empty;
        switch (e.eventName)
        {
            case "bounds":
                GMarker marker = new GMarker(new GLatLng(
                Convert.ToDouble(e.eventArgs[0], new System.Globalization.CultureInfo("en-US", false)),
                Convert.ToDouble(e.eventArgs[1], new System.Globalization.CultureInfo("en-US", false))));
                js += marker.ToString(e.who);

                GMarker marker2 = new GMarker(new GLatLng(
                Convert.ToDouble(e.eventArgs[2], new System.Globalization.CultureInfo("en-US", false)),
                Convert.ToDouble(e.eventArgs[3], new System.Globalization.CultureInfo("en-US", false))));               
                js += marker2.ToString(e.who);

                js += string.Format("{0}.zoomOut();", e.who);
                break;
        }
        return js;
    }
}


/**** Código HTML / HTML Code  ****/
    <form id="form1" runat="server">
    <div>
        <input type="button" onclick="getBounds()" value="Click Me!!" />
        <cc1:GMap ID="GMap1" runat="server" enableServerEvents="True" OnServerEvent="GMap1_ServerEvent" />
    </div>
    </form>



Powered by Subgurim.NET