如何在ArcGIS C# Silverlight 应用程序中绘制和显示地图

问题描述 投票:0回答:1

最近需要通过Visual Studio Community 2022在Silverlight C#应用程序中开发一个ArcGIS系统。我现在遇到的主要问题是在地图中设置GraphicsLayer,并在布局中显示地图。而且由于 ArcGIS 不再支持 silverlight,因此很难找到在 C# silverlight 应用程序中开发 ArcGIS 的良好说明。 代码片段如下:

MainPage.xaml:
<UserControl x:Class="SilverlightApplication20230823.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:Anno="http://schemas.microsoft.com/expression/blend/extensions/annotations/2008"               
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
    <Grid.Resources>
        <esri:SimpleLineSymbol x:Key="SLineSymbol" Color="black" Width="1" />
        <esri:SimpleFillSymbol x:Key="DrawFillSymbol" Fill="#4C12EEEE" BorderBrush="#FF04F0FB" BorderThickness="2" />
        <esri:Map Background="White" HorizontalAlignment="Stretch" x:Key="MapMain" VerticalAlignment="Stretch" WrapAround="True">
         <esri:Map.Extent >
             <esri:Envelope XMin="278000" YMin="272000" XMax="353000" YMax="2790000">
                 <esri:Envelope.SpatialReference>
                     <esri:SpatialReference WKID="102443"/>
                 </esri:Envelope.SpatialReference>
             </esri:Envelope>
         </esri:Map.Extent>
         <esri:GraphicsLayer ID="MDraw">
         </esri:GraphicsLayer>
        </esri:Map>
    </Grid.Resources>
    </Grid>
</UserControl>

.cs 文件如下:

MainPage.xaml.cs
    private Draw MDrawObject;
    private Map MapMain = new Map();
    public MainPage()
    {
        MapMain = LayoutRoot.Resources["MapMain"] as Map;
        MapMain.HorizontalAlignment = HorizontalAlignment.Stretch;
        MapMain.VerticalAlignment = VerticalAlignment.Stretch;
        MapMain.WrapAround = true;
        MapMain.SnapToLevels = true;
        MapMain.MinimumResolution = 0.235185;
        MapMain.MaximumResolution = 264.584;
        MapMain.Height = 318;
        MapMain.Width = 483;

        ArcGISTiledMapServiceLayer glayer;
        glayer = new ArcGISTiledMapServiceLayer()
        {
            Url ="..../TCBaseMap/Land_500/MapServer",
            ID = "FDiagram",
            Visible = true
        };
        Map1.Layers.Insert(0, glayer);

        MDrawObject = new Draw(MapMain)
        {
          FillSymbol = LayoutRoot.Resources["DrawFillSymbol"] as FillSymbol,
          LineSymbol = LayoutRoot.Resources["SLineSymbol"] as LineSymbol,
          DrawMode = DrawMode.Rectangle
        };
    }

由于.cs中使用了ESRI.ArcGIS.Client的类,而.xaml中则定义了地图 在中,因此没有地图位置到布局的声明和绑定, 因此编译后,系统不会在屏幕上显示任何地图图层,但其他 silverlight 组件会很好地显示。 如何让地图可以通过MainPage.xaml.cs中的代码显示出来?任何指令都是 非常感谢,非常感谢。

silverlight arcgis silverlight-5.0 arcgis-runtime-net
1个回答
0
投票

您不应该将诸如地图控件之类的 UI 控件放在资源中 - 它应该位于布局本身中。

话虽如此,您确实意识到 Silverlight 插件已经不再支持一段时间了,ArcGIS Silverlight 组件也已经不再支持很多年了。您不应该在 Silverlight 上开始新项目。如果您想构建 Web 应用程序,请使用 ArcGIS Maps SDK for JavaScript,或者如果您正在寻找移动/桌面应用程序,请查看 ArcGIS Maps SDK for .NET(这是旧版 ArcGIS Silverlight SDK 的演变)

© www.soinside.com 2019 - 2024. All rights reserved.