-
Notifications
You must be signed in to change notification settings - Fork 693
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
MapControl in release not working without a call to InitializeMap #9324
Comments
I hit the same problem. Tried both the token you'd use with UWP mapcontrol and the one you'd use with Azure maps (the latter which it looks like this control is just wrapping the Azure Maps Javascript control in a webview). |
Looks like public MainWindow()
{
this.InitializeComponent();
mapControl.MapServiceToken = mapServiceToken;
mapControl.Loaded += MapControl_Loaded;
}
private void MapControl_Loaded(object sender, RoutedEventArgs e)
{
var webView = VisualTreeHelper.GetChild(mapControl, 0) as WebView2;
webView.NavigationCompleted += WebView_NavigationCompleted;
}
private async void WebView_NavigationCompleted(WebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs args)
{
sender.NavigationCompleted -= WebView_NavigationCompleted;
var result = await sender.ExecuteScriptAsync($"initializeMap(0,0,\"{mapControl.MapServiceToken}\");");
} I'm honestly not quite sure why this fixes it - it seems like this is exactly what the code is already doing. |
BTW I would like to expect we can have a native MapControl just like what the UWP MapControl was, instead of the current WebView based garbage. |
It kind of works for me after upgrading to version |
I was taken aback by that. It makes no sense. Oh boy can't wait to see how they bring back InkCanvas now... |
@eduardobragaxz It's probably worth opening an issue specifically discussing this rather than bringing it up on this unrelated issue, since several are now mentioning it here |
@dotMorten you're right, my bad. I opened a discussion in the WinUI repo: #9323 |
I tested with preview 1 and it works fine, please reopen the issue with a repro app if you can still repro. Here is the code I used: |
Still able to reproduce this issue: Target framework: net8.0-windows10.0.19041.0 Package references
With the workaround @dotMorten suggested, the map shows. Otherwise, just a blue screen (worse if running unpackaged). |
I'm not seeing Preview1 work any better either without my workaround. both x86 and x64 tested, with and without debugger attached, and both C# and C++. I think this issue should be reopened. |
@dotMorten can you share the repro project you have? |
Here you go: |
@dotMorten can you send more information regarding hardware/os version you tried on? Just tested this repro app and it worked for me. |
Still broken in the final v1.5 release. I've seen this issue referred to in other discussions as well. Surprised this made it to release. My workaround above does still seem to do the trick, but it's by no means ideal. |
@dotMorten we are still working on getting a repro. Will service a fix to 1.5 once the issue is understood and we have a fix. |
Since my workaround essentially does what your code does but ensures it delays until webview is ready I’m guessing there’s race conditions at play. But then again I’ve never seen it work, and I don’t know of anyone outside Microsoft who has |
Agreed that this needs to be addressed. Does sound like a race condition. Just tried out a simple example
and that worked out of the box for me on 1.5 stable. Will ask a few more folks in the team to give it a try to see if someone can repro. If there is some pattern where it works vs where it does not work, that would be helpful. There are also a couple of issues here. If the key is not correct, then we also get the blue screen, but this seems to be different from that since it works with your workaround for you which means the key is fine. |
Yes this isn't a keys issue. The blue background is caused by this: #9377 I'm guessing someone forgot to remove some early debugging style? |
I can reproduce this. The root cause is this check for an alpha-numeric token. There should be no such check and instead rely on error propagation from the server side. (My token has a hyphen in it.) microsoft-ui-xaml/controls/dev/MapControl/MapControl.cpp Lines 131 to 133 in c8bd154
|
Workaround: Ask users to recycle their keys until an alpha-numeric-only variant appears. This is of course unacceptable from a security perspective, so hopefully the team is now paying attention to this issue and will service this ASAP. |
Thank you for reporting this issue (and huge thanks to @riverar for debugging this). We've checked in a fix for our first 1.5 servicing release. IsValidMapServiceToken is still needed since the token is passed into ExecuteScriptAsync in a string literal. We've updated it to just check for a double quote instead:
|
@gegao18 This change will fail on Something like... - auto token = IsValidMapServiceToken() ? MapServiceToken() : L"";
- auto parameters = std::format(L"{},\"{}\"", pos, token);
+ auto token = JsonValue::CreateStringValue(MapServiceToken());
+ auto script = std::format(L"initializeMap({},'{}');", pos, token.Stringify().c_str());
if (auto webView = m_webView.get())
{
auto core = webView.CoreWebView2();
// Initializing Azure Maps on WebView
// params: longitude, latitude, mapServiceToken
- returnedValue = co_await core.ExecuteScriptAsync(L"initializeMap(" + parameters + L");");
+ returnedValue = co_await core.ExecuteScriptAsync(script);
for (uint32_t i = 0; i < Layers().Size(); i++)
{
winrt::MapElementsLayer layer = Layers().GetAt(i).as<winrt::MapElementsLayer>();
OnLayerAdded(layer);
}
} Thanks for the quick triage! |
@gegao18 Ping |
Thanks for pinging. For 1.5.1 we made the quick fix that accepts all but ". For 1.6 we have the full fix that passes an encoded token into the map. |
@gegao18 Perfect, thanks again. |
Describe the bug
Is the MapControl in the experimental release supposed to be working? All I'm seeing is a blue screen
Steps to reproduce the bug
New WinUI application
Update to experimental release
Use following XAML in MainWindow
Expected behavior
Shows a map, or at least throws a meaningful error as why it's not showing anything
Screenshots
NuGet package version
1.5.240124002-experimental2
Packaging type
Tried both Packaged and Unpackaged
Windows version
Windows 11
IDE
VS 2022 (Version 17.9.0 Preview 4.0)
The text was updated successfully, but these errors were encountered: