User Tools

Site Tools


source_code_webeditionsample_zoomintofeature_cs_100312.zip

Source Code WebEditionSample ZoomInToFeature CS 100312.zip

TestForm.aspx.cs

using System;
using System.Configuration;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
namespace ZoomInToFeature
{
    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(-180,90,180,-90);
                Map1.MapUnit = GeographyUnit.DecimalDegree;
                Map1.MapTools.OverlaySwitcher.Enabled = true;
                Map1.MapTools.MouseCoordinate.Enabled = true;
                LayerOverlay layerOverlay = new LayerOverlay("WorldOverlay", false, TileType.SingleTile);
                layerOverlay.TransitionEffect = TransitionEffect.None;
                string shapePath = MapPath("App_Data
Countries02.shp");
                ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(shapePath);
                Layer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
                Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                layerOverlay.Layers.Add("Countries",Layer1);
                InMemoryFeatureLayer highlightLayer = new InMemoryFeatureLayer();
                highlightLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, 60, 180, 60), GeoColor.GeographicColors.DeepOcean);
                highlightLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                LayerOverlay dynamicOverlay = new LayerOverlay("HightLightDynamicOverlay");
                dynamicOverlay.Layers.Add("HighLightLayer", highlightLayer);
                dynamicOverlay.IsBaseOverlay = false;
                Map1.CustomOverlays.Add(layerOverlay);
                Map1.CustomOverlays.Add(dynamicOverlay);
             }
        }
        protected void Map1_Click(object sender, MapClickedEventArgs e)
        {
            LayerOverlay layerOverlay = (LayerOverlay)Map1.CustomOverlays["WorldOverlay"];
            LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["HightLightDynamicOverlay"];
            ShapeFileFeatureLayer shapeFileLayer = (ShapeFileFeatureLayer)(layerOverlay.Layers["Countries"]);
            InMemoryFeatureLayer highLightLayer = (InMemoryFeatureLayer)(dynamicOverlay.Layers["HighLightLayer"]);
            //Gets the features the user clicked on.
            shapeFileLayer.Open();
            Collection<Feature> selectedFeatures = shapeFileLayer.QueryTools.GetFeaturesContaining(e.Position,ReturningColumnsType.NoColumns);
            shapeFileLayer.Close();
            if (selectedFeatures.Count > 0)
            {
                highLightLayer.InternalFeatures.Clear();
                //Adds the first feature of the selected features to the hightlight layer.
                highLightLayer.InternalFeatures.Add(selectedFeatures[0].Id, selectedFeatures[0]);
                //Sets the extent of the map to the bounding box of the feature.
                //Notice that zoom level snapping is happening due to the image tiling in the web edition.
                RectangleShape featureExtent = selectedFeatures[0].GetShape().GetBoundingBox();
                Map1.CurrentExtent = featureExtent;
 
            }
        }
    }
}

TestForm.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="ZoomInToFeature.TestForm" %>
<%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %>
<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" />
    <title>Zoom In to Feature</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%"
        onclick="Map1_Click">
    </cc1:Map>
   <%-- <description:descriptionpanel ID="DescPanel" runat="server">
        This sample displays a google map. Click buttons below to switch between different Google maps.
        <br />
        <br />
        <asp:Button CssClass="btn" ID="btnRoad" runat="server" Text="Normal" OnClientClick="Map1.SetCurrentBackgroundMapType(G_NORMAL_MAP); return false;" />
        <asp:Button CssClass="btn" ID="btnAerial" runat="server" Text="Hybrid" OnClientClick="Map1.SetCurrentBackgroundMapType(G_HYBRID_MAP); return false;" /><br />
        <asp:Button CssClass="btn" ID="btnSatellite" runat="server" Text="Satellite" OnClientClick="Map1.SetCurrentBackgroundMapType(G_SATELLITE_MAP); return false;" />
        <asp:Button CssClass="btn" ID="btnPhysical" runat="server" Text="Physical" OnClientClick="Map1.SetCurrentBackgroundMapType(G_PHYSICAL_MAP); return false;" />
    </description:descriptionpanel>--%>
    </form>
</body>
</html>
source_code_webeditionsample_zoomintofeature_cs_100312.zip.txt · Last modified: 2015/09/09 03:38 by admin