Mapbox 自定义标记锚点和缩放问题

Mapbox Custom marker anchor and zoom issues

MapBox Android SDK v4.1.1.1 通过 Xamarin 组件 (https://components.xamarin.com/view/mapboxsdk/)

我正在使用上面的 Xamarin 组件提供的示例测试台,并尝试使用 mapbox 标记 class 将可绘制对象设置为标记图标。在运行时,标记锚定似乎默认设置为 top/left,这导致标记在任何放大期间在地图西南方向移动,在缩小时在地图东北方向移动。如果我删除图标的设置,则会使用默认图标,并且在任何缩放和旋转手势期间它都会正确定位。

任何人都可以对这种行为有任何见解以及如何应对吗?

示例代码:

                        protected override async void OnCreate (Bundle bundle)
                        {
                            base.OnCreate (bundle);

                            SetContentView (Resource.Layout.Main);

                            mapView = FindViewById<MapView> (Resource.Id.mapview);
                            mapView.AccessToken = GetString (Resource.String.mapboxAccessToken);
                            mapView.StyleUrl = Mapbox.Constants.Style.MapboxStreets;
                            mapView.OnCreate (bundle);

                            // Get the map instance
                            map = await mapView.GetMapAsync ();
                            map.UiSettings.ZoomControlsEnabled = true;

                            //Removed code for click events

                            map.AddMarker (new MarkerOptions ()
                                           .SetTitle ("Test Marker")
                                           .SetPosition (new LatLng (41.885, -87.679))                            
        //This is the only change made from the provided sample code - for setting the icon             
          .SetIcon(IconFactory.GetInstance(this).FromResource(Resource.Drawable.Driver_Pin)
        //This is the only change made from the provided sample code - for setting the icon 
                                           );
                            var position = new CameraPosition.Builder ()
                                            .Target (new LatLng (41.885, -87.679)) // Sets the new camera position
                                            .Zoom (11) // Sets the zoom
                                            .Build (); // Creates a CameraPosition from the builder
                        map.AnimateCamera (CameraUpdateFactory.NewCameraPosition (position), 3000);
                    }

我转而使用 Mapbox MarkerView class,它可以访问 SetAnchor() 方法,但是无论我使用什么值,它似乎都没有对问题产生任何影响。

             map.AddMarker (new MarkerViewOptions ()
                           .SetTitle ("Test Marker")
                           .SetPosition (new LatLng (41.885, -87.679))
                           .SetAnchor(0.5f, 1.0f) // this should be bottom center
                           .SetIcon(IconFactory.GetInstance(this).FromResource(Resource.Drawable.Driver_Pin))
                          );

我正在使用的可绘制图标是一个简单的方形 PNG,没有填充,地图上的预期点位于图标的底部中心。

此外,如果我启用内置缩放按钮(通过 UISettings),那么放大和缩小似乎也有 top/left 偏差,这意味着不是放大到可见区域的中心点地图,缩放似乎以它西南的一个点为中心。

这个 SO post Drawable icons on route not pinned at base 似乎与我看到的问题有关,OP 的最终评论表明自定义标记图标和锚定仍然存在问题,即使参考了 v4.1.1 中解决的锚定问题。

感谢您的详细介绍,虽然 Mapbox 不直接支持 Xamarin 组件,但我能够在这个 SO 问题中重现该问题。如果 Xamarin 有这个,您可以尝试更新到 4.2.0-beta.5。 MarkerOptions 不应有任何锚定问题,但您 必须向图标底部添加填充(锚定居中)。