GMap.Net WPF中的Map向下倾斜和旋转

4c8rllxm  于 2023-11-21  发布在  .NET
关注(0)|答案(1)|浏览(197)

我期待着在GMap.NET.WindowsPresentation中实现驾驶导航。是否有可能向下倾斜和旋转Map。
我认为轴承做旋转,但我不知道如何倾斜或倾斜下来。
mapControl.Bearing = 10;mapControl.Bearing -= 10;
任何帮助都将不胜感激。谢谢

k7fdbhmy

k7fdbhmy1#

我和你有同样的问题。GMap.NET专注于显示2DMap,而不是3DMap。因此,它只能改变方位(正如你已经提到的),但不能改变相机倾斜。

public static void gmapControlLoadEvent(GMapControl gMapControl)
        {
            gMapControl.MapProvider = GMapProviders.GoogleHybridMap;

            GMap.NET.GMaps.Instance.Mode = AccessMode.ServerAndCache;

            gMapControl.MinZoom = 4;
            gMapControl.MaxZoom = 20;
            gMapControl.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionWithoutCenter;
            gMapControl.CanDragMap = true;
            gMapControl.DragButton = MouseButtons.Left;
            gMapControl.IgnoreMarkerOnMouseWheel = true;

            //gMapControl.ShowCenter = false; //HIDE THE UGLY CROSS

            goToCoordinates(gMapControl, Variables.latitud, Variables.longitud);
            applyDefaultZoom(gMapControl);
        }

        public static void applyDefaultZoom(GMapControl gMapControl)
        {
            try
            {
                double desiredHeightMeters = Convert.ToDouble(0.01);
                int zoomLevel = calculateZoomLevel(gMapControl, desiredHeightMeters);
                gMapControl.Zoom = zoomLevel;
            }
            catch
            {
                gMapControl.Zoom = 0.5;
            }
        }

        public static int calculateZoomLevel(GMapControl gMapControl, double desiredHeightInMeters)
        {
            double tileSizeMeters = 256;

            double latitude = gMapControl.Position.Lat * Math.PI / 180;
            double circumference = 2 * Math.PI * Variables.EARTH_RADIUS_METERS * Math.Cos(latitude);

            double zoomLevel = Math.Log((circumference * gMapControl.Zoom) / (desiredHeightInMeters * tileSizeMeters));

            return (int)Math.Round(zoomLevel);
        }

        public static void updatePositionOnGmap(GMapControl gMapControl)
        {
            //gMapControl.Bearing = Variables.heading; //THE USELESS BEARING

            Tuple<double, double> nuevasCoordenadas = UtilidadesCoordenadas.calculateNewPosition(
                    Variables.latitud,
                    Variables.longitud,
                    Variables.kph,
                    Variables.heading);

            goToCoordinates(gMapControl, nuevasCoordenadas.Item1, nuevasCoordenadas.Item2);

            Variables.latitud = nuevasCoordenadas.Item1;
            Variables.longitud = nuevasCoordenadas.Item2;

            gMapControl.Bearing = Variables.norteMapa;
        }

        public static void goToCoordinates(GMapControl gMapControl, Double latitude, Double longitude)
        {
            gMapControl.Position = new PointLatLng(latitude, longitude);
            applyDefaultZoom(gMapControl);
            gMapControl.Refresh();
        }

字符串
这种方位变化对我的情况是无用的,因为Map标 checkout 现翻转,iidoEe.仍然附加到原来的方位(至少与谷歌Map)。
部分解决您的问题:
我放弃了Gmap.NET,尝试了Google API付费方法,添加了webView 2 nuget包。
可悲的是,从来没有找到一种方法来与它互动,从Windows窗体,为真实的时间滚动一个纯JavaScript的解决方案可能需要。

public Form1()
{
    InitializeComponent();

    webView2.EnsureCoreWebView2Async(null);
    webView2.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
}

private void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
    if (e.IsSuccess)

    {
        
        string googleMapsHtml = @"
                    <!DOCTYPE html>
                    <html>
                    <head>
                        <meta name='viewport' content='initial-scale=1.0, user-scalable=no' />
                    </head>
                    <body>
                        <iframe
                            width='600'
                            height='450'
                            style='border:0'
                            loading='lazy'
                            allowfullscreen
                            referrerpolicy='no-referrer-when-downgrade'
                            src='https://www.google.com/maps/embed/v1/place?key=<YOUR_API_KEY>&q=19.419743726181796, -99.08883095309436'>
                        </iframe>
                    </body>
                    </html>
                ";

        webView2.CoreWebView2.NavigateToString(googleMapsHtml);
    }
    else
    {            
        MessageBox.Show("WebView2 initialization failed.");
    }
}


如果你找到更好的解决办法,请告诉我
TL:Dr
https://developers.google.com/codelabs/maps-platform/webgl#0

相关问题