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] Map not responding to span (zoom) requests in Windows #1686

Closed
2 tasks done
maxcheatham opened this issue Feb 9, 2024 · 17 comments · Fixed by #2323
Closed
2 tasks done

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

maxcheatham opened this issue Feb 9, 2024 · 17 comments · Fixed by #2323
Labels
area/views Issue/Discussion/PR that has to do with Views bug Something isn't working

Comments

@maxcheatham
Copy link

maxcheatham commented Feb 9, 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

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

Preview Give feedback
No tasks being tracked yet.
@maxcheatham maxcheatham added bug Something isn't working unverified labels Feb 9, 2024
@maxcheatham maxcheatham changed the title [BUG] Map not responding to span (zoom) requests [BUG] Map not responding to span (zoom) requests in Windows Feb 9, 2024
@ckrutsinger
Copy link

ckrutsinger commented Feb 13, 2024

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.

@Brosten
Copy link

Brosten commented Feb 13, 2024

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

@vhugogarcia vhugogarcia added the area/views Issue/Discussion/PR that has to do with Views label Feb 16, 2024
@ckrutsinger
Copy link

Is this something that will be addressed?

@bijington
Copy link
Contributor

Is this something that will be addressed?

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

@ckrutsinger
Copy link

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

@bijington
Copy link
Contributor

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

Oh sorry I read this comment (#1686 (comment)) and assumed it meant you had an idea where the issue is

@TFreudi1
Copy link

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

@mikelor
Copy link
Contributor

mikelor commented Jul 22, 2024

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

@TFreudi1
Copy link

TFreudi1 commented Jul 22, 2024 via email

@ksoftllc
Copy link

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

@mikelor
Copy link
Contributor

mikelor commented Jul 23, 2024

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.

maps.mp4

@mikelor
Copy link
Contributor

mikelor commented Jul 23, 2024

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

@losh99
Copy link

losh99 commented Oct 22, 2024

Any update on implementing this fix and when it will be released?

@mikelor
Copy link
Contributor

mikelor commented Oct 30, 2024

You could implement the code fix listed above. I'm traveling at the moment, so I won't be able to submit a pull request until next week.

mikelor added a commit to mikelor/CommunityToolkit-Maui that referenced this issue Nov 6, 2024
@mikelor
Copy link
Contributor

mikelor commented Nov 6, 2024

Hey @bijington, I implemented a fix for this. Let me know if I need to do anything else.

@mikelor
Copy link
Contributor

mikelor commented Nov 8, 2024

hey @losh99 this is now in release 2.04 of CommunityToolkit.Maui.Maps

@losh99
Copy link

losh99 commented Nov 8, 2024

Thanks @mikelor really appreciated!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/views Issue/Discussion/PR that has to do with Views bug Something isn't working
Projects
None yet
9 participants