图钉调整大小绑定zoomlevel [英] Pushpin resize binding zoomlevel

查看:80
本文介绍了图钉调整大小绑定zoomlevel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将WinRT与bing地图配合使用,并且在缩放地图时尝试设置(以编程方式)我的图钉的RenderTransform值. 我尝试了解决方案,但是Windows 8控件似乎不支持绑定到ZoomLevel属性. 没有人有任何解决方法或可行的示例吗? 预先谢谢

I'm using WinRT with bing maps and i'm trying to set (programmatically) the RenderTransform value of my pushpin when zooming on map. I tried this Solution but seems that the Windows 8 controls do not support binding to the ZoomLevel property. does anyone have any either workaround or working example ? Thankyou in advance

推荐答案

我在这里发布了一个示例,可以在需要时供他人使用.利用您对使用"ViewChanged"事件的建议,我编写了以下代码片段:

I post here an example that can be used from others if needed. Exploiting your suggestion of using the "ViewChanged" event I wrote this code snippet:

    private double Interpolate(double x0, double y0, double x1, double y1, double x)
    {
        return y0 * (x - x1) / (x0 - x1) + y1 * (x - x0) / (x1 - x0);
    }

    private void mapZoom_Event(object sender, ViewChangedEventArgs e)
    {
        double scale;
        foreach (Pushpin currentPin in currentPins)
        {
            double zoom = Map.ZoomLevel;

            scale = interpolate(10, 1 / 2, 18, 3, zoom);

            if (scale < 1)
                scale = 1;

            ScaleTransform pushpinsScaleTransform = new ScaleTransform()
            {
                ScaleX = scale,
                ScaleY = scale
            };
            currentPin.RenderTransform = pushpinsScaleTransform;
        }
    }

其中 currentPins 是地图中的IEnumerable. 内插 方法是一种简单的Lienar函数,可以线性缩放图钉的大小.

where currentPins is an IEnumerable that are in the Map. The Interpolate method is a simple Lienar function where it should linearly scale the size of your pushpin.

这篇关于图钉调整大小绑定zoomlevel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆