Phone 7 Bing 地图控件 - 点击时添加图钉

发布于 2024-09-26 19:29:03 字数 1010 浏览 3 评论 0原文

我正在使用最新的 Phone 7 RTM 工具(今天下载,2010 年 10 月 7 日)。

我试图在这里做一件简单的事情:

当用户在地图控件上点击一次时,我想在那里放置一个图钉。 另外,我想保留地图控件的常规内置行为(点击两次进行缩放)。

(如果无法保留这两种行为,则可以长按地图来放置图钉)。

当我尝试解决这个问题时,我发现了对 Phone7 的控制映射进行更改的文档: http://msdn.microsoft.com/en-us/library/ff955762.aspx

然后我看到了新类 MapInputEventArgs,它有一个 ViewportPoint 成员。

在查看常规 SilverLight 地图控件上的代码示例时,我看到了类似这样的内容:

private void OnMouseClick(object sender, MapMouseEventArgs e)
    {
        Point clickLocation = e.ViewportPoint;
        Location location = x_Map.ViewportPointToLocation(clickLocation);

        Pushpin pushpin = new Pushpin(); 
        m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude));
    }

但在 Phone7 的情况下,我找不到适当的事件处理程序,并且我找不到谁在地图中使用 MapInputEventArgs控制。 在谷歌上搜索它只得到 1 个结果!

那么,“点击一次”的适当事件在哪里,以及在触发此事件后如何获取 ViewportPoint ?

提前致谢。

I am using the latest Phone 7 RTM tools ( downloaded it today, October 7 2010).

I am trying to do a simple thing here:

when the user taps once on the map control, i want to put a pushpin there.
also, i want to keep the regular built-in behavior of the map control ( tap twice to zoom).

(If it's not possible to keep both behaviors , then maybe a long press on the map to put pushpin).

When trying figuring this out, i came across this documentation of the changes made to the control map for Phone7:
http://msdn.microsoft.com/en-us/library/ff955762.aspx

Then i saw the new class MapInputEventArgs, which has a ViewportPoint member.

When looking at code examples on the regular SilverLight map control i saw something like this:

private void OnMouseClick(object sender, MapMouseEventArgs e)
    {
        Point clickLocation = e.ViewportPoint;
        Location location = x_Map.ViewportPointToLocation(clickLocation);

        Pushpin pushpin = new Pushpin(); 
        m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude));
    }

But in Phone7 case, I can't find the appropriate event handler, and I could not find who uses MapInputEventArgs in the map control.
Searching it on google gets me only 1 result !!

So , where is the appropriate event for "Tap once", and how can i get a ViewportPoint after this event has been fired ?

Thanks in advance.

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

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

发布评论

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

评论(3

薄暮涼年 2024-10-03 19:29:04

好吧,这不太漂亮,但我也遇到了同样的问题,我想出了一种解决方法,当您从屏幕上松开手指时,该解决方法就会起作用。我实例化一个布尔值:

         bool noPin = false;

然后用它来确定用户是否正在执行缩放或平移(这些在 MouseLeftButtonDown 和 MouseLeftButtonUp 事件之间触发)。在向上事件中,我然后检查用户是否正在缩放或平移,如果没有,则放置我的图钉。

    private void mHome_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        noPin = false;
    }

    private void mHome_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        if (!noPin)
            PlacePushPin();
    }

    private void mHome_MapPan(object sender, MapDragEventArgs e)
    {
        tbTemp.Text += "pan";
    }

    private void mHome_MapZoom(object sender, MapZoomEventArgs e)
    {
        tbTemp.Text += "zoom";
    }

它并不美丽,但是,这是我能做到的最好的。

Okay, it's not pretty, but I have the same problem and I came up with a workaround of sorts that kicks in when you release your fingers from the screen. I instantiate a boolean:

         bool noPin = false;

I then use this to determine whether zoom or pan is being done by the user (these fire between the MouseLeftButtonDown and MouseLeftButtonUp events). On the Up event, I then check whether the user was zooming or panning and, if not, place my pushpin.

    private void mHome_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        noPin = false;
    }

    private void mHome_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        if (!noPin)
            PlacePushPin();
    }

    private void mHome_MapPan(object sender, MapDragEventArgs e)
    {
        tbTemp.Text += "pan";
    }

    private void mHome_MapZoom(object sender, MapZoomEventArgs e)
    {
        tbTemp.Text += "zoom";
    }

It's not beautiful but, well, it was the best I could manage.

淡莣 2024-10-03 19:29:03

如果您仍然遇到问题,请弄清楚这一点。

MouseLeftButtonUp 和 MouseLeftButtonDown 事件有一个 GetPosition 方法,该方法将返回您要查找的点

 private void MapMain_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {

        Point p = e.GetPosition(this.MapMain);
        GeoCoordinate geo = new GeoCoordinate();
        geo = MapMain.ViewportPointToLocation(p);
        MapMain.ZoomLevel = 17;
        MapMain.Center = geo;
        //---create a new pushpin---
        Pushpin pin = new Pushpin();

        //---set the location for the pushpin---
        pin.Location = geo;

        //---add the pushpin to the map---
        MapMain.Children.Add(pin);
    }

Just figured this out if you are still having problems.

The MouseLeftButtonUp and MouseLeftButtonDown Events have a GetPosition Method that will return the point your looking for

 private void MapMain_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {

        Point p = e.GetPosition(this.MapMain);
        GeoCoordinate geo = new GeoCoordinate();
        geo = MapMain.ViewportPointToLocation(p);
        MapMain.ZoomLevel = 17;
        MapMain.Center = geo;
        //---create a new pushpin---
        Pushpin pin = new Pushpin();

        //---set the location for the pushpin---
        pin.Location = geo;

        //---add the pushpin to the map---
        MapMain.Children.Add(pin);
    }
慕巷 2024-10-03 19:29:03

除非我错误地阅读了您的问题,否则这似乎正是您正在寻找的:

Silverlight - 通过 C# 将图钉添加到 Bing 地图

Unless I'm reading your question wrong, this seems to be exactly what you're looking for:

Silverlight - Add Pushpin to Bing Maps via C#

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