Drawing Options Sample

A sample about ASP.NET Google Map Control drawing options.

Set different values to options below the map and click on "Apply" to see the result.

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="../../Maps.master" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="GoogleMaps.Samples.Maps.Drawing.Options.Default" %>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
    <div class="jumbotron">
        <h2>Drawing Options Sample</h2>
        <p>A sample about ASP.NET Google Map Control drawing options.</p>
    </div>
    <p>
        Set different values to options below the map and click on "Apply" to see the result.
    </p>

    <div class="map-wrap">
        <map:GoogleMap ID="GoogleMap1" runat="server" MapType="HYBRID" Zoom="8" Latitude="42.1229" Longitude="24.7879" CssClass="map" DefaultAddress="sofia"
            Width="100%" Height="600px" FullscreenControl="true">
        </map:GoogleMap>
        <map:DrawingManager ID="GoogleManager1" TargetControlID="GoogleMap1" runat="server" DrawingMode="CIRCLE">
            <DrawingControlOptions DrawingModes="circle, polygon, polyline" Position="TopLeft" />
        </map:DrawingManager>
    </div>

    <div class="row">
        <div class="form-group">
            <label>Show Drawing Control</label>
            <asp:CheckBox ID="cbShowDrawingControl" runat="server"></asp:CheckBox>
        </div>
        <div class="form-group col-md-6">
            <label>Drawing Control Position</label>
            <asp:DropDownList ID="ddlDrawingPositipon" runat="server" CssClass="form-control" SelectMethod="GetDrawingControlPosition" SelectedValue="<%# GoogleManager1.DrawingControlOptions.Position %>">
            </asp:DropDownList>
        </div>
        <div class="form-group col-md-6">
            <label>Default Drawing Mode</label>
            <asp:DropDownList ID="ddlDrawingMode" runat="server" CssClass="form-control" SelectMethod="GetDrawingModes" SelectedValue="<%# GoogleManager1.DrawingMode %>">
            </asp:DropDownList>
        </div>
        <div class="form-group">
            <label>Drawing Modes Enabled</label>
            <asp:CheckBoxList ID="cblDrawingModes" runat="server">
            </asp:CheckBoxList>
        </div>
        <button class="btn btn-primary">Apply</button>
    </div>

    
</asp:Content>

Code Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using GoogleMaps.Drawing;

namespace GoogleMaps.Samples.Maps.Drawing.Options
{
    public partial class Default : System.Web.UI.Page
    {
        public IEnumerable GetDrawingModes()
        {
            var list = new List();

            foreach (var item in DrawingOverlayType.Values)
            {
                var li = new ListItem(item);
                li.Selected = GoogleManager1.DrawingControlOptions.DrawingModes.Contains(item);
                list.Add(li);
            }

            return list;
        }

        public IEnumerable GetDrawingControlPosition()
        {
            foreach (var item in Enum.GetValues(typeof(ControlPosition)))
            {
                yield return item.ToString();
            }
        }

        public bool GetSelectedDrawingControl()
        {
            return GoogleManager1.DrawingControl;
        }

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

            if (!IsPostBack)
            {
                cbShowDrawingControl.Checked = GoogleManager1.DrawingControl;

                foreach (var item in DrawingOverlayType.Values)
                {
                    var li = new ListItem(item);
                    li.Selected = GoogleManager1.DrawingControlOptions.DrawingModes.Contains(item);
                    cblDrawingModes.Items.Add(li);
                }
            }
            else
            {
                GoogleManager1.DrawingControl = cbShowDrawingControl.Checked;
                GoogleManager1.DrawingMode = ddlDrawingMode.SelectedValue;
                GoogleManager1.DrawingControlOptions.Position = (ControlPosition)Enum.Parse(typeof(ControlPosition), ddlDrawingPositipon.SelectedValue);

                var modes = new List();
                foreach(ListItem item in cblDrawingModes.Items)
                {
                    if(item.Selected)
                    {
                        modes.Add(item.Value);
                    }
                }
                GoogleManager1.DrawingControlOptions.DrawingModes = modes.ToArray();
            }
        }

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