简体   繁体   中英

Is it possible to render a view from Bing Maps to a WriteableBitmap?

Case: Windows Phone 7 (Mango) application.

I have a list of (hundreds of ) items, containing a geocoordinate. Each item's parameter data is used to render an image, and these images are displayed in a listbox.

Is it possible to render a WP7 Map element to a writeablebitmap? If not, is it possible to disable UI gestures from the map element, so it at least behaves like a static image?

If you just want a static image of a map I would recommend using the Static Map API for Bing maps instead of a Map control for each list item.

The static map API also lets you specify the image size so the download size to the phone can be reduced.

If you still want to use the Bing Map control, you can disable UI gestures by setting IsHitTestVisible to false, like this in XAML:

<my:Map IsHitTestVisible="False" />

Try the example suggested in comment from GFTab

For making it static, you can try IsHitTestVisible="False"

Here is how I made a secondary tile from the areay currenly visible in the application:

    private void pinCurrentMapCenterAsSecondaryTile() {
        try {
            var usCultureInfo = new CultureInfo("en-US");
            var latitude = map.Center.Latitude.ToString(usCultureInfo.NumberFormat);
            var longitude = map.Center.Longitude.ToString(usCultureInfo.NumberFormat);
            var zoom = map.ZoomLevel.ToString(usCultureInfo.NumberFormat);
            var tileParam = "Lat=" + latitude + "&Lon=" + longitude + "&Zoom=" + zoom;
            if (null != App.CheckIfTileExist(tileParam)) return; // tile for exactly this view already exists

            using (var store = IsolatedStorageFile.GetUserStoreForApplication()) {
                var fileName = "/Shared/ShellContent/" + tileParam + ".jpg";
                if (store.FileExists(fileName)) {
                    store.DeleteFile(fileName);
                }
                // hide pushpins and stuff
                foreach (var layer in map.Children.OfType<MapLayer>()) {
                    layer.Visibility = Visibility.Collapsed;
                }
                using (var saveFileStream = new IsolatedStorageFileStream(fileName, FileMode.Create, store)) {
                    var wb = new WriteableBitmap(173, 173);
                    b.Render(
                        map,// the map defined in XAML
                        new TranslateTransform {  
                            // use the transformation to clip the center of the current map-view
                            X = -(map.ActualWidth - 173)/2,
                            Y = -(map.ActualHeight - 173)/2,
                    });
                    wb.Invalidate();
                    wb.SaveJpeg(saveFileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                }
                foreach (var layer in map.Children.OfType<MapLayer>()) {
                    layer.Visibility = Visibility.Visible;
                }
            }

            ShellTile.Create(
                new Uri("/MainPage.xaml?" + tileParam, UriKind.Relative),
                new StandardTileData {
                    BackTitle = "ApplicationName",
                    Count = 0,
                    // You can only load images from the web or isolated storage onto secondary tiles
                    BackgroundImage = new Uri("isostore:/Shared/ShellContent/" + tileParam + ".jpg", UriKind.Absolute),
                });
        } catch (Exception e) {
            // yeah, this is 7331!!11elfelf
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM