Maui
Maui copied to clipboard
[BUG] Map not responding to span (zoom) requests in Windows
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 MoveToRegion command of the Map changes the location, but does not change the span or zoom of the map in Windows. IsZoomEnabled is true.
Expected Behavior
The map should change its zoom/span to the requested parameters. The Android map is behaving correctly. The map is changing its zoom/span to the requested parameters.
Steps To Reproduce
- Open and run the project from the repository
- Add your keys to AndroidManifest.xml (to verify that it works on Android) and MauiProgram.cs
- Click Move 1, then Move 2, etc. and observe that the span is not changing, while the location is.
- Also note that the Add Circle command does not seem to work on Windows.
Link to public reproduction project repository
https://github.com/bluedot/TestMap2
Environment
- .NET MAUI CommunityToolkit: 2.0.0
- OS: Windows 11
- .NET MAUI: 8.0.3
Anything else?
Hopefully, everything should be in the repository.
### Tasks
I can see that in the map handler implementation, the MapSpan is used to set the center but not the width and height of the map view. See https://raw.githubusercontent.com/CommunityToolkit/Maui/main/src/CommunityToolkit.Maui.Maps/Handler/Map/MapHandler.Windows.cs
public static new void MapMoveToRegion(IMapHandler handler, IMap map, object? arg)
{
var newRegion = arg as MapSpan;
if (newRegion == null)
{
return;
}
if (handler is MapHandlerWindows mapHandler)
{
mapHandler.regionToGo = newRegion;
}
CallJSMethod(handler.PlatformView, $"setRegion({newRegion.Center.Latitude.ToString(CultureInfo.InvariantCulture)},{newRegion.Center.Longitude.ToString(CultureInfo.InvariantCulture)});");
}
https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/map/change-the-map-view shows how to set the entire rectangle.
+1 (Also, I didn't get the ItemSource + DataTemplate way of binding Pins to work under Windows, but that's a different bug)
Is this something that will be addressed?
Is this something that will be addressed?
Would you be willing to contribute the fix via a PR?
@bijington I don't know how to fix it.
@bijington I don't know how to fix it.
Oh sorry I read this comment (https://github.com/CommunityToolkit/Maui/issues/1686#issuecomment-1939939029) and assumed it meant you had an idea where the issue is
Same here, zomm did'nt work. Is it solved or planned to solve ?
@ckrutsinger do you have a simple example that demonstrates this?
The CommunityToolkit.Samples application works for me, but I'm not sure if that's what you are trying to do.
void Button_OnClicked(object? sender, EventArgs e)
{
BasicMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Location(50, 6), Distance.FromKilometers(1)));
}
EDIT: Just saw your sample above. Going to take a look.
Try Distance.FromMeters(100)It don't zoom, looks always like 1 km.Von meinem/meiner Galaxy gesendet -------- Ursprüngliche Nachricht --------Von: mike lorengo @.> Datum: 22.07.24 17:31 (GMT+01:00) An: CommunityToolkit/Maui @.> Cc: TFreudi1 @.>, Comment @.> Betreff: Re: [CommunityToolkit/Maui] [BUG] Map not responding to span (zoom) requests in Windows (Issue #1686) @ckrutsinger do you have a simple example that demonstrates this? The CommunityToolkit.Samples application works for me, but I'm not sure if that's what you are trying to do. void Button_OnClicked(object? sender, EventArgs e) { BasicMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Location(50, 6), Distance.FromKilometers(1))); }
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
@mikelor It does move to the new center, but does not set width and height requested. Clear from the source code snippet provided above.
Yep. I was able to duplicate it.
I took a look and @ckrutsinger is correct. The handler code is only using the center to set the region. I modified the code so that it looks like this
CallJSMethod(handler.PlatformView, $"setRegion({newRegion.Center.Latitude.ToString(CultureInfo.InvariantCulture)},{newRegion.Center.Longitude.ToString(CultureInfo.InvariantCulture)},{newRegion.LatitudeDegrees.ToString(CultureInfo.InvariantCulture)},{newRegion.LongitudeDegrees.ToString(CultureInfo.InvariantCulture)});");
and modified the setRegion script as follows
function setRegion(latitude, longitude, latitudeDegrees, longitudeDegrees)
{
map.setView({bounds: new Microsoft.Maps.LocationRect(new Microsoft.Maps.Location(latitude, longitude), latitudeDegrees, longitudeDegrees) });
}
That seems to fix it, as shown in the video below.
https://github.com/user-attachments/assets/cbaa43cb-e78a-4691-a2a2-faf1f5e3a847
I'm going to test a couple of map projects I have with the new code.