Polygon Code-Behind Sample

A sample about ASP.NET Google Map Control overlay in code-behind.

A demo about how easy it to add ASP.NET Google Map Control overlay in the code-behind.

Thank you for using the Development Build of ASP.NET Google Map Control to build Google Maps faster.
Purchase the Commercial Build now to get access to all product updates and the ASP.NET Google Map Control expert support.

Source

Markup

<%@ Page Language="C#" MasterPageFile="~/samples/Overlays/Overlays.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GoogleMaps.Samples.samples.Overlays.CodeBehind.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div class="jumbotron">
        <h2>Polygon Code-Behind Sample</h2>
        <p>
            A sample about ASP.NET Google Map Control overlay in code-behind.
        </p>
    </div>
    <p>
        A demo about how easy it to add ASP.NET Google Map Control overlay in the code-behind.
    </p>
    <div class="map-wrap">
        <map:GoogleMap ID="GoogleMap1" runat="server" Width="100%" Height="600px" Latitude="42.1229"
            Longitude="24.7879" Zoom="6" CssClass="map" FullscreenControl="true">
        </map:GoogleMap>
    </div>
    <asp:Label ID="lblInfo" runat="server"></asp:Label>
    
</asp:Content>

Code Behind

using System;
using System.Collections.Generic;
using System.Drawing;
using GoogleMaps.Overlays;

namespace GoogleMaps.Samples.samples.Overlays.CodeBehind
{
    public partial class Default : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var circle = new GoogleCircle
            {
                Draggable = true,
                Editable = true,
                Center = new LatLng(42.1229, 24.7879),
                Radius = 200000
            };
            var polygon = new GooglePolygon
            {
                Draggable = true,
                Editable = true,
                FillColor = Color.Red,
                FillOpacity = .5F,
                StrokeColor = Color.Black,
                StrokeWeight = 5,
                Paths = new List {
                    new LatLng(37.97918, 23.716647),
                    new LatLng(41.036501, 28.984895),
                    new LatLng(44.447924, 26.097879),
                    new LatLng(44.802416, 20.465601),
                    new LatLng(42.002411, 21.436097),
                    new LatLng(37.97918, 23.716647),
                    new LatLng(37.97918, 23.716647)
                }
            };
            var rectangle = new GoogleRectangle
            {
                Draggable = true,
                Editable = true,
                FillColor = Color.Green,
                Bounds = new Bounds
                {
                    SouthWest = new LatLng(44.802416, 20.465601),
                    NorthEast = new LatLng(37.97918, 23.716647)
                }
            };
            GoogleMap1.Overlays.Add(circle);
            GoogleMap1.Overlays.Add(polygon);
            GoogleMap1.Overlays.Add(rectangle);

            // add server side click handler on polygon only
            polygon.Click += Polygon_Click;
        }

        private void Polygon_Click(object sender, MouseEventArgs e)
        {
            lblInfo.Text = string.Format("Polygon clicked at {0}", e.Position);
        }
    }
}