none
Map must (sometimes) be loaded twice in order to render RRS feed

  • Question

  • Hi there,

    I have a Bing Map (for Windows Store Apps 8.1) with pushpin contained inside of a button flyout.  Here is the definition:

    <Button Visibility="{Binding HasGeoData, Converter={StaticResource noteVisibilityConverter}}">
                                Map
                                <Button.Flyout>
                                    <Flyout>
                                        <bm:Map Loaded="Map_OnLoaded" ZoomLevel="16" Height="400" Width="400" Credentials="mycreds">
                                            <bm:Map.Children>
                                                <bm:Pushpin>
                                                    <bm:MapLayer.Position>
                                                        <bm:Location Latitude="{Binding Latitude}" Longitude="{Binding Longitude}" />
                                                    </bm:MapLayer.Position>
                                                </bm:Pushpin>
                                            </bm:Map.Children>
                                        </bm:Map>
                                    </Flyout>
                                </Button.Flyout>
                            </Button>

    And here is the codebehind:

            private void Map_OnLoaded(object sender, RoutedEventArgs e)
            {
                var map = (Map) sender;
                var note = (DisplayNoteHeader)map.DataContext;
                map.Center = new Location(note.Latitude, note.Longitude);
            }

    When I click the button, I see the flyout, and the map loads properly most of the time (70%).  For the 30% of the time it fails to load, I can close the map and re-open, and it will work - so it is only ever the first load that fails.  It looks like the map center isn't set, though the pushpin is still visible.  It turns out I am off the East coast of Africa, which I'm assuming is at coordinates 0, 0.  

    I suspect a timing issue, given the sporadic nature of the issue.  However, having tried defining more (and less) of the functionality in the codebehind, re-ordering the lines of code, binding to events other than Loaded to configure the map, I am out of options.  I'm not sure if I can pre-load the map prior to pushing the button - that might help.

    Any help would be greatly appreciated!

    Thanks.

    Wednesday, July 23, 2014 6:13 PM

Answers

  • Wow. You shouldn't use a heavy control in a flyout control. The Map uses a lot of resources and generates a transaction every time it is loaded. If you just want to show an image of a map with a pin on it in a flyout you will get a lot better performance (and less memory usage) if you use the REST imagery Service. http://msdn.microsoft.com/en-us/library/ff701724.aspx

    If you think the flyout will be used a lot in a single user experience you can load the full map control in the main page, have it generate a session key and then dispose of the map control. You can then use the session key in place of  your Bing Maps key for the REST calls and this will make them all non-billable transactions.


    http://rbrundritt.wordpress.com

    Wednesday, July 23, 2014 7:50 PM

All replies

  • Wow. You shouldn't use a heavy control in a flyout control. The Map uses a lot of resources and generates a transaction every time it is loaded. If you just want to show an image of a map with a pin on it in a flyout you will get a lot better performance (and less memory usage) if you use the REST imagery Service. http://msdn.microsoft.com/en-us/library/ff701724.aspx

    If you think the flyout will be used a lot in a single user experience you can load the full map control in the main page, have it generate a session key and then dispose of the map control. You can then use the session key in place of  your Bing Maps key for the REST calls and this will make them all non-billable transactions.


    http://rbrundritt.wordpress.com

    Wednesday, July 23, 2014 7:50 PM
  • Thanks for the advice - I'm quite new at this.  I'll likely move to a static image to get things moving forward.  

    However, the fact remains that there appears to be a bug in the maps framework given that the functionality works most of the time.  It should still work (albeit with poor performance) even if I tax the framework by making poor design decisions :)

    Thursday, July 24, 2014 12:24 PM