Anonymous user  |  Log in  |  Create Account
Autor: subgurim
Publicado: 1/17/2007
Leído: 69740 veces
Comentarios (0)
Valoracion: 4.105241


/**** Explicación / Description  ****/
Castellano
Vamos creando una polilínea conforme clicamos sobre el mapa, y se nos muestra en un textarea dónde hemos clicado. No es más que una funcionalidad básica que emula http://koti.mbnet.fi/ojalesa/exam/editor_v2.html

Si te atreves a mejorarlo, publícalo aquí!!

English
We're making a polyline while clicking to the map. A text area shows where does this clicks have been done. It's just a basic emulation of http://koti.mbnet.fi/ojalesa/exam/editor_v2.html

If you're able to improve it, publish it here!!

/**** Código de servidor / Server code  ****/
using System;

using Subgurim.Controles;
using System.Text;

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

    private void myMap()
    {
        showHideControls();
        clickHandler();      

        StringBuilder sb = new StringBuilder();
        sb.Append(polylines());
        GMap1.addCustomJavascript(sb.ToString());
    }

    private string polylines()
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendFormat(
            @"       
            function draw()
            {{
                if (lines.length > 1)
                {{
                    aux = lines.slice(lines.length - 2, lines.length);
                    {0}.addOverlay(new GPolyline(aux,'#000000', 3, 2));
                }}
            }}
            ", GMap1.GMap_Id);

        return sb.ToString();
    }

    private void clickHandler()
    {
        GMap1.addListener(new GListener(GMap1.GMap_Id, GListener.Event.click,
            "function (marker, point) {clickHandler(marker, point);}"));
    }

    private void showHideControls()
    {
        GControl zoom = new GControl(GControl.preBuilt.LargeMapControl);
        GControl maps = new GControl(GControl.preBuilt.MapTypeControl, new GControlPosition(GControlPosition.position.Top_Right));
        GControl scale = new GControl(GControl.preBuilt.ScaleControl);
        GControl ovm = new GControl(GControl.preBuilt.GOverviewMapControl);

        GListener listener = new GListener(GMap1.GMap_Id, GListener.Event.mouseover,
            string.Format(@"
            function()
            {{
                {0}
                {1}
                {2}
                {3}
            }}",
               zoom.ToString(GMap1.GMap_Id),
               maps.ToString(GMap1.GMap_Id),
               scale.ToString(GMap1.GMap_Id),
               ovm.ToString(GMap1.GMap_Id)
               ));

        GMap1.addListener(listener);

        GListener listener2 = new GListener(GMap1.GMap_Id, GListener.Event.mouseout,
            string.Format(@"
            function()
            {{
                {0}.hideControls()
            }}", GMap1.GMap_Id));

        GMap1.addListener(listener2);
    }
}


/**** Código HTML / HTML Code  ****/
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GLiner.aspx.cs" Inherits="Galeria_codigo_Ejemplos_GLiner" %>

<%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>GLiner</title>
   
    <script type="text/javascript">
        
        lines = [];
        function clickHandler(marker, point)
        {
            var txt = document.getElementById('history');
            txt.value += 'new GLatLng('+point.lat()+', '+point.lng()+'); // point ' + lines.length + '\n';
            lines.push(point);
           
            draw();
        }
       
    </script>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <cc1:GMap ID="GMap1" runat="server" Width="600px" Height="400px" />
        <textarea id="history" rows="10" cols="60"></textarea>
    </div>
    </form>
</body>
</html>


/**** Código Javascript / Javascript Code  ****/
.aspx
        lines = [];
        function clickHandler(marker, point)
        {
            var txt = document.getElementById('history');
            txt.value += 'new GLatLng('+point.lat()+', '+point.lng()+'); // point ' + lines.length + '\n';
            lines.push(point);
           
            draw();
        }

.aspx.cs
        sb.AppendFormat(
            @"       
            function draw()
            {{
                if (lines.length > 1)
                {{
                    aux = lines.slice(lines.length - 2, lines.length);
                    {0}.addOverlay(new GPolyline(aux,'#000000', 3, 2));
                }}
            }}
            ", GMap1.GMap_Id);
Powered by Subgurim.NET