Bing 地图 silverlight 控制图钉缩放问题

发布于 2024-08-27 23:21:34 字数 1024 浏览 5 评论 0原文

基本上我的问题是我已经改编了在这里找到的一段代码

http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1

这正是我想要的它要做的就是根据地图的缩放级别缩放一些图钉图像。唯一的问题是我已经调整了此代码以与 bing 地图 silverlight 控件一起运行(而不是像原始示例中那样的虚拟地球),现在图像比例正确,但它们被重新定位,并且仅在我的缩放级别时达到所需的位置是最大的。知道为什么吗?我们将非常感谢您的帮助:)

下面修改后的代码:

var layer = new MapLayer();
map.AddChild(layer);

//Sydney
layer.AddChild(new Pin
{
    ImageSource = new BitmapImage(new Uri("pin.png", UriKind.Relative)),
    MapInstance = map
}, new Location(-33.86643, 151.2062), PositionMethod.Center);

变得像

layer.AddChild(new Pin
{
    ImageSource = new BitmapImage(new Uri("pin.png", UriKind.Relative)),
    MapInstance = map
}, new Location(-33.92485, 18.43883), PositionOrigin.BottomCenter);

我假设的那样,它与 bing 地图锚定其 UI 元素的不同方式有关。有关细节也非常有用。谢谢你!

Basically my problem is that i've adapted a piece of code found here

http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1

which does exactly what I want it to do, that is scale some pushpin images according to the map's zoom level. The only problem is that I've adapted this code to run with the bing maps silverlight control (not virtual earth like in the original example) and now the images scale correclty, but they are repositioned and only reach the desired position when my zoom level is maximum. Any idea why? Help will be greatly appreciated :)

Modified code below:

var layer = new MapLayer();
map.AddChild(layer);

//Sydney
layer.AddChild(new Pin
{
    ImageSource = new BitmapImage(new Uri("pin.png", UriKind.Relative)),
    MapInstance = map
}, new Location(-33.86643, 151.2062), PositionMethod.Center);

becomes something like

layer.AddChild(new Pin
{
    ImageSource = new BitmapImage(new Uri("pin.png", UriKind.Relative)),
    MapInstance = map
}, new Location(-33.92485, 18.43883), PositionOrigin.BottomCenter);

I am assuming it has something to do with a different way in which bing maps anchors its UIelements. Details on that are also very userful. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠檬 2024-09-03 23:21:34

尝试将您自己的固定大小位图图像添加到地图中,而不是使用图钉类

try adding your own fixed size bitmapimage to the map rather than using the pushpin class

送你一个梦 2024-09-03 23:21:34

感谢earthware的回复,我成功解决了我的问题。只需直接添加图像(不涉及图钉类),为其添加固定大小并相应地设置缩放的 CenterX 和 CenterY 属性即可。代码示例如下:

image.Source = new BitmapImage(new Uri("pin.png", UriKind.Relative));
image.Stretch = System.Windows.Media.Stretch.None;
image.Height = 152;
image.Width = 116;

layer.AddChild(image, new Location(-33.86643, 151.2062), PositionOrigin.BottomCenter);
image.RenderTransform = scaleTr;

scaleTr.CenterX = image.Width / 2; //image is alligned bottom center (see above)
scaleTr.CenterY = image.Height;

Thanks to earthware's response I managed to solve my problem. It is just a matter of adding the image direclty (no pushpin class involved), adding a fixed size to it and setting the CenterX and CenterY properties of the scaling accordingly. Code sample follows:

image.Source = new BitmapImage(new Uri("pin.png", UriKind.Relative));
image.Stretch = System.Windows.Media.Stretch.None;
image.Height = 152;
image.Width = 116;

layer.AddChild(image, new Location(-33.86643, 151.2062), PositionOrigin.BottomCenter);
image.RenderTransform = scaleTr;

scaleTr.CenterX = image.Width / 2; //image is alligned bottom center (see above)
scaleTr.CenterY = image.Height;
柳絮泡泡 2024-09-03 23:21:34

下面的示例展示了如何使用图钉对象(而不是图像对象)通过地图的 ZoomLevel 自动缩放图钉并将它们保持在正确的位置。所有这一切都需要自定义 IValueConverter、ScaleTransform 和一些数据绑定的帮助。

http: //pietschsoft.com/post/2010/06/04/Resizing-and-Auto-Scaling-Pushpin-in-Bing-Maps-Silverlight.aspx

Here's an example that shows how to Auto Scale Pushpins with the Map's ZoomLevel using the Pushpin object (instead of an Image object) and keeps them in the correct location. All with a little help from a custom IValueConverter, ScaleTransform and a little Data Binding.

http://pietschsoft.com/post/2010/06/04/Resizing-and-Auto-Scaling-Pushpin-in-Bing-Maps-Silverlight.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文