Xamarin表格地图 - 3D过渡效果

时间:2017-06-03 15:07:44

标签: 3d uwp xamarin.forms maps

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

所以,wat我做了(在PCL部分),我创建了一个 customMap.cs 一个对象,它基本上是一个继承自Xamarin.Forms.Map的对象:public class 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
}

所以现在,在渲染器部分,如果我们看一下UWP(我有一台Windows机器,所以它使我的构建/测试更容易/更快在本地x86上运行),我做了一个基本的渲染器:{{ 1}}

public class CustomMapRenderer : MapRenderer

现在,我面临两个问题/问题。首先,我有一个例外,/// <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(); } } } ==&gt;中的try {}无法捕获。 private async void UpdateCameraView()我在互联网上搜索,它说我正在访问一个空值,这是真的可能,因为我检查了值+我检查了一个断点,一切似乎初始化..

另外,如果我无法访问当前的相机区域位置值,如何管理从2D到3D的转换(当达到x米/英里的缩放时)?因为,引用Display maps with 2D, 3D, and Streetside views documentation,我需要The program '[17780] Map3DProject.UWP.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.来创建一个半径为的场景。

在本文档中,我看到您也可以拨打Geopoint,但我无法应用任何轮换价值。所以,对我来说无用

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

感谢,

最高

0 个答案:

没有答案