Xamarin表单贴图-3D过渡效果

Xamarin表单贴图-3D过渡效果,3d,uwp,xamarin.forms,maps,3d,Uwp,Xamarin.forms,Maps,一旦达到PCL项目定义的缩放级别,我将尝试将2D视图转换为3D视图 那么,我做了什么(在PCL部分),我创建了一个customMap.cs对象,它基本上是从Xamarin.Forms.Map继承的对象:public类customMap:Map public class CustomMap : Map { /// <summary> /// Just for my test since I can't find the way to find the current l

一旦达到PCL项目定义的缩放级别,我将尝试将2D视图转换为3D视图

那么,我做了什么(在PCL部分),我创建了一个customMap.cs对象,它基本上是从Xamarin.Forms.Map继承的对象:
public类customMap:Map

public class CustomMap : Map
{
    /// <summary>
    /// Just for my test since I can't find the way to find the current location of the camera
    /// </summary>
    public static readonly BindableProperty LocationProperty =
        BindableProperty.Create(nameof(Location), typeof(Position), typeof(CustomMap), new Position(47.942660, 0.261979));

    /// <summary>
    /// Assessor for Location property.
    /// </summary>
    public Position Location
    {
        get { return (Position)GetValue(LocationProperty); }
        set { SetValue(LocationProperty, value); }
    }

    /// <summary>
    /// Just for my test since I can't find the way to get the current zoom level
    /// </summary>
    public static readonly BindableProperty ZoomLevelProperty =
        BindableProperty.Create(nameof(ZoomLevel), typeof(Distance), typeof(CustomMap), new Distance());

    /// <summary>
    /// Assessor for ZoomLevel property.
    /// </summary>  
    public Distance ZoomLevel
    {
        get { return (Distance)GetValue(ZoomLevelProperty); }
        set { SetValue(ZoomLevelProperty, value); }
    }

    #region Constructor
    public CustomMap()
    {
        this.PropertyChanged += (object sender, PropertyChangedEventArgs e) =>
        {
            CustomMap map = sender as CustomMap;
            if (map.VisibleRegion != null)
            {
                this.ZoomLevel = map.VisibleRegion.Radius;
            }
        };
        isMapLoaded = false;
    }
    #endregion

    #region Additionnals
    private bool isMapLoaded;
    /// <summary>
    /// Method called from the renderer once the map is loaded
    /// </summary> 
    public void MapLoaded()
    {
        isMapLoaded = true;
        if (this.VisibleRegion != null)
        {
            this.ZoomLevel = this.VisibleRegion.Radius;
        }
    }
    public bool IsMapLoaded { get { return (isMapLoaded); } }
    #endregion
}
现在,我面临两个问题。首先,我有一个异常没有被
private async void UpdateCameraView()
==>
中的
try{}
捕获,程序“[17780]Map3DProject.UWP.exe”退出时带有代码-1073741819(0xc000005)“访问冲突”。
我在互联网上搜索,它说我正在访问一个空值,这是不可能的,因为我正在检查值+我用断点检查过的值,所有内容似乎都已初始化

此外,如果无法访问当前摄影机区域位置值,如何管理从2D到3D的过渡(当您达到x米/英里的缩放时)?因为,参考,我需要一个
地质点
来创建一个具有半径的场景

在这个文档中,我看到您还可以调用
mapsecene.CreateFromCamera(nativeMap.ActualCamera),但是我无法应用任何旋转值。。所以,对我来说没用

如果有人对我的逻辑有任何建议或对我的问题有任何答案,欢迎发表评论

谢谢,


Max

您能告诉我您在哪一行代码中获得了访问冲突
异常吗?//设置空中三维视图。|<代码>nativeMap.Style=MapStyle.Aerial3DWithRoads
/// <summary>
/// CustomRenderer for the CustomMap created in the PCL part.
/// This Renderer gives us the possibility to add/override some functionalities.
/// </summary>
public class CustomMapRenderer : MapRenderer
{
    /// <summary>
    /// Instance of the native map for this plateform.
    /// </summary>
    MapControl nativeMap;

    /// <summary>
    /// Instance of our Custom control declared in the PCL part.
    /// </summary>
    CustomMap customMap;

    /// <summary>
    /// We override the OnElementChanged() event handler to get the desired instance. We also use it for updates.
    /// </summary>
    /// <param name="e">It contains either the NewElement or the OldElement</param>
    protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
    {
        base.OnElementChanged(e);

        if (e.NewElement != null)
        {
            customMap = (CustomMap)e.NewElement;
            nativeMap = Control as MapControl;

            nativeMap.Loaded += ((sender, re) =>
            {
                customMap.MapLoaded();
            });
        }
    }

    /// <summary>
    /// The on element property changed callback.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="PropertyChangedEventArgs"/>Instance containing the event data.</param>
    protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);
        if (this.customMap == null || this.nativeMap == null)
            return;

        if (e.PropertyName == CustomMap.ZoomLevelProperty.PropertyName)
            UpdateCameraView();
    }

    private async void UpdateCameraView()
    {
        if (customMap == null || nativeMap == null)
            return;

        if (nativeMap.Is3DSupported && customMap.IsMapLoaded)
        {
            try
            {
                // Set the aerial 3D view.
                nativeMap.Style = MapStyle.Aerial3DWithRoads;

                // Specify the location.
                BasicGeoposition hwGeoposition = new BasicGeoposition() { Latitude = customMap.VisibleRegion.LatitudeDegrees, Longitude = customMap.VisibleRegion.LongitudeDegrees };
                Geopoint hwPoint = new Geopoint(hwGeoposition);
                // Create the map scene.
                MapScene hwScene = MapScene.CreateFromLocationAndRadius(hwPoint,
                                                                                     80, //show this many meters around
                                                                                     0, //looking at it to the North
                                                                                     60); //degrees pitch

                // Set the 3D view with animation.
                await nativeMap.TrySetSceneAsync(hwScene, MapAnimationKind.Bow);
            } catch (Exception e)
            {
                Debug.WriteLine("------------------------");
                Debug.WriteLine(e.ToString());
                Debug.WriteLine(e.StackTrace);
                Debug.WriteLine("------------------------");
            }
        }
        else
        {
            // If 3D views are not supported, display dialog.
            ContentDialog viewNotSupportedDialog = new ContentDialog()
            {
                Title = "3D is not supported",
                Content = "\n3D views are not supported on this device.",
                PrimaryButtonText = "OK"
            };
            await viewNotSupportedDialog.ShowAsync();
        }
    }
}