案例:Windows Phone 7 (Mango) 应用程序。
我有一个(数百个)项目列表,其中包含一个地理坐标。每个项目的参数数据用于渲染图像,这些图像显示在列表框中。
是否可以将 WP7 Map 元素呈现为 writeablebitmap?如果没有,是否可以从地图元素中禁用 UI 手势,所以它至少表现得像静态图像?
案例:Windows Phone 7 (Mango) 应用程序。
我有一个(数百个)项目列表,其中包含一个地理坐标。每个项目的参数数据用于渲染图像,这些图像显示在列表框中。
是否可以将 WP7 Map 元素呈现为 writeablebitmap?如果没有,是否可以从地图元素中禁用 UI 手势,所以它至少表现得像静态图像?
如果您只想要地图的静态图像,我建议您使用Bing地图的静态地图 API,而不是每个列表项的地图控件。
静态地图 API 还允许您指定图像大小,以便减少手机的下载大小。
如果您仍想使用 Bing 地图控件,可以通过将 IsHitTestVisible 设置为 false 来禁用 UI 手势,就像在 XAML 中这样:
<my:Map IsHitTestVisible="False" />
尝试GFTab评论中建议的示例
为了使其静态,您可以尝试 IsHitTestVisible="False"
以下是我如何从应用程序中当前可见的区域制作辅助磁贴:
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
}
}