Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Windows Map control no longer displays the User's Location Pin after adding a Pin to the Map when IsShowingUser is set to True #1801

Closed
2 tasks done
mikelor opened this issue Apr 7, 2024 · 1 comment · Fixed by #1817
Labels
bug Something isn't working unverified

Comments

@mikelor
Copy link
Contributor

mikelor commented Apr 7, 2024

Is there an existing issue for this?

  • I have searched the existing issues

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

Current Behavior

When displaying the Windows map control with the IsUserShowing attribute set to True and adding a Pin, the user's location pin disappears from the map, and no longer shows.

Expected Behavior

When IsShowingUser attribute is set to True, I would expect the User's location Pin to still be showing after adding a Pin to the Map.

Steps To Reproduce

  1. Open up the CommunityToolkit.Maui.Sample Solution
  2. Modify line 18, in the MapsPinsPage.xaml to add IsShowingUser="True"
  3. Compile and run the sample
  4. When the map displays it should show a Pin with your location
  5. Click the "Add Pin" button to add a Pin.
  6. The User Location Pin is no longer displayed

Link to public reproduction project repository

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

Environment

- .NET MAUI CommunityToolkit: 8.0.1
- OS: Windows 11 Pro 24H2
- .NET MAUI: 8.0.14

Anything else?

In looking at the source MapHandler.Windows.cs line 112 adds the location via the CallJSMethod(handler.PlatformView, $"addLocationPin()) call.

When adding a Pin, it gets added to the collection of Pins.
When the map handler is refreshed, there is a call to MapPins(). The method MapPins() removes all the Pins, and then adds them back via the Pin collection.

I believe that the User's location is never added back. There are multiple ways to solve this, but I first wanted to see if you could reproduce this error.

@mikelor mikelor added bug Something isn't working unverified labels Apr 7, 2024
@mikelor mikelor changed the title [BUG] [BUG] Windows Map control no longer displays the User's Location Pin after adding a Pin to the Map when IsShowingUser is set to True Apr 7, 2024
@mikelor
Copy link
Contributor Author

mikelor commented Apr 7, 2024

My initial thinking is to modify the script function removeAllPins in line 302 to the following:

function removeAllPins()
{
    map.entities.clear();
    
    if (locationPin != null )
    {
      map.entities.push(locationPin);
      map.setView({
        center: location
      });
    }
}

This would add back the locationPin to the map.entities collection if it was not null.

Since the locationPin is only set in the addLocationPin() function which is called from the MapIsShowingUser(IMapHandler handler, IMap map) method. The removeLocationPin() function sets the value of locationPin to null.

Setting the view via the 'setView()` function is debatable since it modifies the current view region. After thinking about this a bit, I would suggest not including it. The developer can always modify the view back to the location if they choose.

brminnick added a commit that referenced this issue Apr 27, 2024
…ter adding a Pin to the Map when IsShowingUser is set to True #1801 (#1817)

Implementing Fix for Issue #1807. Modify Windows Map Pins Page sample show user. Updated MapHandler.Windows RemoveAllPins() to add back user location if showing user.

Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment