Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] Polygons, polylines and circles never render on the map.

Open DmitrikSerhiy opened this issue 1 year ago • 7 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Current Behavior

The map never shows any map elements.

Expected Behavior

When MapElement is added to the MapElements collection, it should be rendered on the map.

Steps To Reproduce

  1. Create a map element (circle, polygon or polyline)
  2. Add it to the MapElements collection

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/main/samples/CommunityToolkit.Maui.Sample/Pages/Views/Maps

Environment

- CommunityToolkit.Maui: 7.0.1
- CommunityToolkit.Maui.Maps: 2.0.0
- CommunityToolkit.Mvvm: 8.2.2
- OS: Windows 10 Build 10.0.19041.0
- .NET MAUI: 8.0

Anything else?

I have a strong feeling that it's not supported. I have yet to find a working example with a map having any element in your repository or any other.

    // initialize map from xaml.cs file
    var map = new Microsoft.Maui.Controls.Maps.Map
    {
        IsZoomEnabled = true,
        IsShowingUser = false,
        IsScrollEnabled = true,
        IsTrafficEnabled = false,
    };

    //Create a circle element
    var circle = new Circle
    {
        Center = new Location(50.450971, 30.522604),
        Radius = Distance.FromKilometers(100),
        StrokeColor = Color.FromArgb("#88FF0000"),
        StrokeWidth = 8,
        FillColor = Color.FromArgb("#88FFC0CB")
    };

    //Add circle to the map
map.MapElements.Add(circle);

DmitrikSerhiy avatar Feb 23 '24 10:02 DmitrikSerhiy

@jfversluis do you know what the state of maps is in .NET MAUI? This package was only intended to be a stop gap until .NET MAUI supported maps on Windows. I thought the team had announced supporting it at some point however, I see the docs still states that it isn't supported https://learn.microsoft.com/dotnet/maui/user-interface/controls/map?view=net-maui-8.0

bijington avatar Feb 25 '24 11:02 bijington

We're waiting until the WinUI team finished their work on 1.5 and then we can hook it up for .NET MAUI.

Work is being tracked here: https://github.com/dotnet/maui/issues/20356

jfversluis avatar Feb 25 '24 11:02 jfversluis

@bijington It's clear the map from MAUI is not supported for Windows. This issue is regarding the map from CommunityToolkit.Maui.Maps package. The map itself works. Webview contains a map from Bing. But It seems it does not support rendering map elements on it. Am I right?

DmitrikSerhiy avatar Feb 25 '24 11:02 DmitrikSerhiy

I am unable to verify the issue right now as my Windows setup is a complete mess. I was mostly trying to see if this was something we could pass over to the .NET MAUI team but I guess we cannot.

bijington avatar Feb 25 '24 11:02 bijington

From looking at the code this was indeed never implemented on our side for Windows.

Depending on how easy/hard it is to do we should consider if it's worth it seeing that this should be supported by .NET MAUI directly in the foreseeable future.

jfversluis avatar Feb 25 '24 12:02 jfversluis

@DmitrikSerhiy Try to add elements on Loaded, like this:

private readonly Circle _circle;

public CustomMap()
{
    _circle = new Circle
    {
        // any properties
    }
    
    Loaded += OnLoaded;
}

private void OnLoaded(object? sender, EventArgs e)
{
    MapElements.Add(_circle);
}

vector-perfect avatar Mar 05 '24 08:03 vector-perfect

I've tried this approach. It has no difference.

I am setting the map in the OnAppering method of the page. Then I add map element to the collection in Loaded event. Map does not reflect MapElements collection. Debug shows that collection is populated. But it simply does not mean anything. Nothing renders in the map.

If that would be the case, then pins wouldn't work as well. But pins are rendered no matter when you add them to the Pins collection.

According to @jfversluis it's just not implemented for windows. And we have to wait for WinUI team Map control implementation and THEN wait a bit more for the MAUI team to implement appropriate Map handler and THEN wait just a little bit more for the CommunityToolkit.Maui.Maps package maintainers to hook it up and actually implement it.

The bottom line is don't expect it within this year (IMHO)

I can't afford to wait so long. I am switching to ArcGIS maps for MAUI.

DmitrikSerhiy avatar Mar 05 '24 10:03 DmitrikSerhiy