简体   繁体   English

是否可以将视图从Bing Maps渲染到WriteableBitmap?

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

Case: Windows Phone 7 (Mango) application. 案例:Windows Phone 7(Mango)应用程序。

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? 是否可以将WP7 Map元素呈现为writeablebitmap? If not, is it possible to disable UI gestures from the map element, so it at least behaves like a static image? 如果不是,是否可以从map元素禁用UI手势,因此它至少表现得像静态图像一样?

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. 如果您只想要地图的静态图像,建议您为Bing地图使用静态地图API,而不是为每个列表项使用Map控件。

The static map API also lets you specify the image size so the download size to the phone can be reduced. 静态地图API还允许您指定图像大小,以便可以减少手机的下载大小。

If you still want to use the Bing Map control, you can disable UI gestures by setting IsHitTestVisible to false, like this in XAML: 如果仍要使用Bing Map控件,则可以通过将IsHitTestVisible设置为false来禁用UI手势,例如XAML中的代码:

<my:Map IsHitTestVisible="False" />

Try the example suggested in comment from GFTab 尝试GFTab评论中建议的示例

For making it static, you can try IsHitTestVisible="False" 为了使其静态,可以尝试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
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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