Phone 7 Bing 地图控件 - 点击时添加图钉
我正在使用最新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,这不太漂亮,但我也遇到了同样的问题,我想出了一种解决方法,当您从屏幕上松开手指时,该解决方法就会起作用。我实例化一个布尔值:
然后用它来确定用户是否正在执行缩放或平移(这些在 MouseLeftButtonDown 和 MouseLeftButtonUp 事件之间触发)。在向上事件中,我然后检查用户是否正在缩放或平移,如果没有,则放置我的图钉。
它并不美丽,但是,这是我能做到的最好的。
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:
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.
It's not beautiful but, well, it was the best I could manage.
如果您仍然遇到问题,请弄清楚这一点。
MouseLeftButtonUp 和 MouseLeftButtonDown 事件有一个 GetPosition 方法,该方法将返回您要查找的点
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
除非我错误地阅读了您的问题,否则这似乎正是您正在寻找的:
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#