Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] Map not responding to span (zoom) requests in Windows

Open maxcheatham opened this issue 1 year ago • 13 comments

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

  1. Open and run the project from the repository
  2. Add your keys to AndroidManifest.xml (to verify that it works on Android) and MauiProgram.cs
  3. Click Move 1, then Move 2, etc. and observe that the span is not changing, while the location is.
  4. 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

maxcheatham avatar Feb 09 '24 22:02 maxcheatham

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.

ckrutsinger avatar Feb 13 '24 00:02 ckrutsinger

+1 (Also, I didn't get the ItemSource + DataTemplate way of binding Pins to work under Windows, but that's a different bug)

Brosten avatar Feb 13 '24 07:02 Brosten

Is this something that will be addressed?

ckrutsinger avatar Mar 05 '24 16:03 ckrutsinger

Is this something that will be addressed?

Would you be willing to contribute the fix via a PR?

bijington avatar Mar 05 '24 17:03 bijington

@bijington I don't know how to fix it.

ckrutsinger avatar Mar 05 '24 18:03 ckrutsinger

@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

bijington avatar Mar 05 '24 18:03 bijington

Same here, zomm did'nt work. Is it solved or planned to solve ?

TFreudi1 avatar Jul 10 '24 10:07 TFreudi1

@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.

mikelor avatar Jul 22 '24 15:07 mikelor

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: @.***>

TFreudi1 avatar Jul 22 '24 16:07 TFreudi1

@mikelor It does move to the new center, but does not set width and height requested. Clear from the source code snippet provided above.

ksoftllc avatar Jul 22 '24 17:07 ksoftllc

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

mikelor avatar Jul 23 '24 20:07 mikelor

I'm going to test a couple of map projects I have with the new code.

mikelor avatar Jul 23 '24 20:07 mikelor