Skip to content

Cannot Clear All Map Polygons (Android Only) #30097

@asi-evin

Description

@asi-evin

Description

I'm adding a geofencing feature to one of my apps, but I can't seem to clear some of the map polygons if the user chooses to clear/redraw. This issue seems to only effect android.

Steps to Reproduce

  1. Pull bug repo:
  2. Add your Android map API key in AndroidManifest.html (see )
  3. Run the app.
  4. Click "Start Drawing" and create a shape by tapping points for the polygon.
  5. Click "Stop Drawing". A blue boundary, and red "buffer" boundary should be filled in.
  6. Click "Clear Drawing"
  7. Repeat Steps 4-6 a few times.

Expected result: Map should be clear of any polygons.

Actual Result: After the first or second clearing, polygons begin to persist forever.

Video Reproduction:

screen-20250620-105038.mp4

Link to public reproduction project repository

https://github.com/asi-evin/com.maui.map.bug.git

Note: this is stripped-down control from one of my apps. In my app, the map doesn't even clear on the first try.

Version with bug

9.0.80

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No work-a-round found, even tried making current polygons transparent before clearing them. Also tried removing elements one-at-a-time instead of clearing. And originally, I didn't create new MapElements, I would just clear their geolocation data and re-use them but that was even more disastrous.

Update: I have employed the following work-a-round: I have copied the handler and overridden the "ClearMapElements" function. In there, I set the Visibility to "False" before clearing it from the map liek so:

void ClearMapElements()
{
    if (_polylines != null)
    {
        for (int i = 0; i < _polylines.Count; i++)
        {
            _polylines[i].Visible = false; // <- added
            _polylines[i].Remove();
        }

        _polylines = null;
    }

    if (_polygons != null)
    {
        for (int i = 0; i < _polygons.Count; i++)
        {
            _polygons[i].Visible = false; // <- added
            _polygons[i].Remove();
        }

        _polygons = null;
    }

    if (_circles != null)
    {
        for (int i = 0; i < _circles.Count; i++)
        {
            _circles[i].Visible = false; // <- added
            _circles[i].Remove();
        }

        _circles = null;
    }
}

Obviously this isn't ideal, but it "visually" gets accomplishes what I need for now... don't know the memory implications of this would be though.

Metadata

Metadata

Assignees

Labels

area-controls-mapMap / Mapsplatform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions