ArcGIS Runtime+Simple MVVM VM操纵UI对象

本文介绍如何在使用ArcGISRuntime时,通过自定义按钮实现View的导航功能,避免在UI.cs文件中编写过多逻辑代码,提高代码的可读性和可维护性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前我们提到过MVVM意在将UI与逻辑彻底分离,最理想的情况下我们在UI.cs文件后面不写一句代码,在VM里面不写一句逻辑。

最近用ArcGIS Runtime的时候,出现了这样一个问题:

<esri:SceneView x:Name="mySceneView"
                        ElevationExaggeration="{Binding ElementName=SliderValue,Path=Value}" 
                        >
            <esri:Scene>
                <esri:Scene.Surface>
                    <esri:ServiceElevationSource IsEnabled="True" 
						ServiceUri="http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"/>
                </esri:Scene.Surface>
                <layers:ArcGISTiledMapServiceLayer ID="Imagery"  x:Name="GisTiledMapServiceLayer"
					ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer"/>
                <layers:SceneLayer ID="Buildings" 
					ServiceUri="http://scene.arcgis.com/arcgis/rest/services/Hosted/Building_Vancouver/SceneServer/Layers/0" IsVisible="True"/>
             
            </esri:Scene>
        </esri:SceneView>

我想为mySceneView这个View设置自定义导航,但是它的方法是这样的

mySceneView.SetView(new Camera(new MapPoint(-123.114867093837,
                49.2638368778531, 340.3367222948), 7.374728906848, 69.8626679976746));

但我希望我的.cs文件更加单纯,在C罗Boss的建议下(感谢C罗提供知识赞助),所以我这样处理了

<Button Content="fly" HorizontalAlignment="Left" Margin="50,50,0,0" VerticalAlignment="Top"
                Command="{BindingSetNavigationCommand,UpdateSourceTrigger=Default,Mode=TwoWay}"
                CommandParameter="{Binding ElementName=mySceneView}"
               >

就是说我直接将这个叫mySceneView对象传过去了,然后在VM里面进行逻辑调用,当然这是由于ArcGIS在设计它的框架就已经考虑了这个非UI线程操纵的问题

 public ICommand SetNavigationCommand
        {
            get
            {
                return new DelegateCommand<SceneView>((mySceneView) =>
                {
                    foreach (var x in serviceAgent.GetLines())
                    {
                        mySceneView.SetViewAsync(x,0.3,false);
                    }
                });
            }
        }

好,目的达成~







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值