How to display openstreetmap map on c# wpf ? i get black view screen
11:47 18 Nov 2025

in mainwindow.xaml.cs i added a toggle button event to switch from current mode view to the interactive opengooglestreet map view.

at the top i added:

using Microsoft.Web.WebView2.Core;

and then

private bool isMapMode = false;

and

private async void BtnToggleMap_Click(object sender, RoutedEventArgs e)
{
    isMapMode = !isMapMode;

    if (isMapMode)
    {
        // Switch to MAP mode
        BtnToggleMap.Content = "๐Ÿ“ก ื—ื–ื•ืจ ืœืชืฆื•ื’ืช ืจื“ืืจ";
        MapContainer.Visibility = Visibility.Visible;
        RadarContainer.Visibility = Visibility.Collapsed;

        string projectRoot = IOPath.GetFullPath(IOPath.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\"));
        string htmlPath = IOPath.Combine(projectRoot, "Assets", "Map", "map.html");
        string mapFolder = IOPath.Combine(projectRoot, "Assets", "Map");

        try
        {
            if (!File.Exists(htmlPath))
            {
                Log("โš  map.html not found in Assets/Map folder!");
                return;
            }

            // Initialize WebView2
            await MapView.EnsureCoreWebView2Async(null);

            // Enable access for local radar images
            string radarFolder = IOPath.Combine(projectRoot, "Assets", "Radar_Images");
            MapView.CoreWebView2.SetVirtualHostNameToFolderMapping(
                "radar.local", radarFolder, CoreWebView2HostResourceAccessKind.Allow);

            // Enable access for map folder (for leaflet.css and leaflet.js)
            MapView.CoreWebView2.SetVirtualHostNameToFolderMapping(
                "map.local", mapFolder, CoreWebView2HostResourceAccessKind.Allow);

            // Read and modify HTML to use virtual host
            string htmlContent = File.ReadAllText(htmlPath);
            MapView.NavigateToString(htmlContent);

            Log("๐ŸŒ Loaded interactive map mode with local Leaflet files.");

            // Wait for map to load
            await Task.Delay(1500);

            // Send radar frames to map
            await SendRadarFramesToMap();
        }
        catch (Exception ex)
        {
            Log($"โŒ Failed to initialize map: {ex.Message}");
        }
    }
    else
    {
        // Switch back to RADAR mode
        BtnToggleMap.Content = "๐Ÿ—บ ื”ืฆื’ ืžืคื” ืื™ื ื˜ืจืืงื˜ื™ื‘ื™ืช";
        MapContainer.Visibility = Visibility.Collapsed;
        RadarContainer.Visibility = Visibility.Visible;
        Log("๐Ÿ“ก Returned to radar image mode.");
    }
}

and

private async void MapView_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
{
    if (e.IsSuccess)
    {
        Log("โœ… Map loaded successfully.");
        // Send radar frames after map loads
        await SendRadarFramesToMap();
    }
    else
    {
        Log($"โŒ Map failed to load: {e.WebErrorStatus}");
    }
}

it's reaching to the line

Log("โœ… Map loaded successfully.");

but what i see is black on the right side when running the application.

showing black instead the map

this is the map.html file content a bit longer.




  
  
  ืžืคืช ืจื“ืืจ

  
  
  

  


  

i don't get any errors just black screen on the left side.

c# wpf openstreetmap webview2