User Tools

Site Tools


source_code_webeditionsample_contextmenuwithsubmenu_cs.zip

Source Code WebEditionSample ContextMenuWithSubMenu CS.zip

TestForm.aspx.cs

using System;
using System.Configuration;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
namespace CustomZoomLevelSet
{
    public partial class TestForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46);
                Map1.MapUnit = GeographyUnit.DecimalDegree;
                WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
                Map1.CustomOverlays.Add(worldMapKitOverlay);
                ContextMenu menuOnMap = new ContextMenu("area", 180);
                ContextMenuItem redirectItem = new ContextMenuItem("<a href='http://www.thinkgeo.com' target='_blank'>ThinkGeo<a>");
                ContextMenuItem InfomationItem = new ContextMenuItem("<div onclick='popupInfomation();'>Infomation(Client Event)</div>");
                menuOnMap.MenuItems.Add(redirectItem);
                ContextMenuItem subItem = new ContextMenuItem("sub menu");
                redirectItem.MenuItems.Add(subItem);
                menuOnMap.MenuItems.Add(InfomationItem);
                Map1.ContextMenu = menuOnMap;
             }
        }
    }
}

Footer.ascx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CenterMapBasedOnLatLong.UC
{
    public partial class Footer : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

Header.ascx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CenterMapBasedOnLatLong.UC
{
    public partial class Header : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

TestForm.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="CustomZoomLevelSet.TestForm" %>
<%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %>
<%@ Register Src="UC/Footer.ascx" TagName="Footer" TagPrefix="uc1" %>
<%@ Register Src="UC/Header.ascx" TagName="Header" TagPrefix="uc2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <link href="~/theme/default/samplepic/style.css" rel="stylesheet" type="text/css" />
    <link href="Theme/css.css" rel="stylesheet" type="text/css" />
    <title>Add a Context Menu</title>
    <script type="text/javascript">
        function popupInfomation() {
            alert("Infomadddtion popup by ContextMenu");
        }
        var tgMap = null;
        var OnMapCreating = function(map) {
            tgMap = map;
            Class.Extent(ContextMenu.prototype, {
                moveTo: function(x, y) {
                    var screenWidth = parseInt(document.body.clientWidth);
                    var screenHeight = parseInt(document.body.clientHeight);
                    if (!IsIE()) {
                        screenWidth = parseInt(document.documentElement.clientWidth);
                        screenHeight = parseInt(document.documentElement.clientHeight);
                    }
                    var ctxWidth = parseInt(this.div.style.width);
                    if (x + ctxWidth > screenWidth) {
                        x -= ctxWidth;
                    }
                    var ctxHeight = this.div.children.length * 20;
                    if (y + ctxHeight > screenHeight) {
                        y -= ctxHeight;
                    }
                    this.div.style.left = x + 'px';
                    this.div.style.top = y + 'px';
                }
            })
        }
        function IsIE() {
            if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                return true;
            }
            else //Firefox
            {
                if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                    return false;
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <table border="0px" width="100%" cellpadding="0px" cellspacing="0px" style="height: 100%;">
        <tr>
            <td style="height: 82px;">
                <uc2:Header ID="Header1" runat="server" />
            </td>
        </tr>
        <tr>
            <td style="height: 100%; border-top: solid 1px #ece9d8;">
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%">
                </cc1:Map>
            </td>
        </tr>
        <tr>
            <td style="height: 50px; border-top: outset 0px #666666; background-color: #ece9d8;">
                <uc1:Footer ID="Footer1" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
source_code_webeditionsample_contextmenuwithsubmenu_cs.zip.txt · Last modified: 2015/09/09 03:37 by admin