如何利用Microsoft Rx Framework在WinRT / Windows 8中有效地实现Bing Map。 [英] How I can make use of Microsoft Rx Framework to implement Bing Map effectively in WinRT / Windows 8.

查看:86
本文介绍了如何利用Microsoft Rx Framework在WinRT / Windows 8中有效地实现Bing Map。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的电子商务应用程序中,我需要在Bing地图中绘制我附近的商店,而我的另一个要求是在缩放和调整地图时我需要根据地图中心更新我的商店。因此,为了实现这一点,我主要选择传统的
编码方式。步骤如下:

In my e-commerce application I need to plot my nearby stores in Bing map, And my another requirement is during the time of zooming and paning the map I need to update my stores based on the map centre. So for implementing this I primarily choose the traditional way of coding. The steps are given below.


  1. 首次启动我将发送位置的api请求,并将在地图上绘制商店。
  2. In地图ViewChanged事件我将根据地图当前商店发送附近商店的后续请求。

因此在此实施过程中,我在单个api请求中获得约400个商店。我会在地图上绘制这个。但是当我缩放或平移地图时,它会同时发送多个请求并尝试更新UI上的图钉,最终它会阻止
UI和Map在我的应用程序中表现得非常糟糕。

So during this implementation, I am getting around 400 stores in single api request. And I will plot this on map. But when I zoom or pan the map it sends several requests simultaneously and try to update the pushpins on UI , eventually it will block the UI and Map behaves horribly in my app.

在Google搜索过程中,我发现了很多关于使用Microsoft Rx框架实现类似功能的建议。但没有得到任何正确的代码示例来实现我的目标。任何人都可以帮助我或指导我解决我的问题。

During the Google search I found many suggestions regarding using Microsoft Rx framework to implement similar functionality. But didn’t get any proper code samples to achieve my goal. Can anyone please help me or guide me to solve my issue.

请记住,我需要在一次请求中在地图上平均绘制400个商店。

Remember I need to plot on an average of 400 stores in map on a single request.

问候,

Stez。    

推荐答案

Hi Stez,

Hi Stez,

Throttle 可用于忽略在特定距离内发生的
ViewChanged 事件。 这包括用户正在平移或缩放的情况,并且地图正在筹集大量
ViewChanged 事件。  节流仅对紧密事件序列中的最后一个事件做出反应。

Throttle can be used to ignore ViewChanged events that occur within a certain proximity.  This covers the case whereby the user is panning or zooming and the map is raising lots of ViewChanged events.  Throttle only reacts to the last event in a close sequence of events.

您可能还想使用
TakeUntil

切换
以忽略尚未返回的请求,同时接收
ViewChanged 活动。 这包括用户完成平移或缩放,等待一段时间然后再开始平移或缩放的情况。 如果原始请求仍在进行中,那么 TakeUntil / 切换
将忽略其响应,因为它已经过时。

You'll also probably want to use TakeUntil or Switch in your query to ignore requests that haven't returned yet while simultaneously receiving ViewChanged events.  This covers the case whereby the user finishes panning or zooming, waits for a bit, then begins panning or zooming again.  If the original request is still in flight, then TakeUntil/Switch will ignore its response since it's already outdated.

例如:(未经测试

IObservable<Foo> viewChanges = GetViewChangedAsObservable();

viewChanges
	.Throttle(TimeSpan.FromSeconds(1))
	.Select(foo => SendRequestAsObservable(foo))
	.Switch()
	.ObserveOnDispatcher()
	.Subscribe(UpdatePins);

您可以使用节流期间,直到您获得该行为你喜欢。  缩短期限会产生更实时的视图,当然这取决于服务响应的速度,而用户正在平移/缩放
。 将句点设置得更大可以防止重叠请求。  假设服务请求通常不到1秒,则使用1秒可能是合理的。 虽然如果您想要更高的准确性,那么
测试您的应用程序在生产环境中以确定最合适的值。

You can play around with the Throttle period until you get the behavior you like.  Making the period smaller will result in a more real-time view, though of course it depends on how fast the service responds while the user is panning/zooming.  Making the period larger will prevent overlapping requests.  It's probably reasonable to use 1 second, assuming that the service request generally takes under 1 second.  Though if you want more accuracy, then test your application in a production environment to determine the most appropriate value.

SendRequestAsObservable 应该简单地发送请求。 如果您使用的是
async API,则只需使用 ToObservable 进行转换。

SendRequestAsObservable should simply send the request.  If you're using an async API, then simply convert it using ToObservable.

例如:

IObservable<PinCollection> SendRequestAsObservable(Foo foo)
{
	var service = new PinService();
	return service.GetPinsAsync(foo).ToObservable().Finally(service.Dispose);
}

- 戴夫


这篇关于如何利用Microsoft Rx Framework在WinRT / Windows 8中有效地实现Bing Map。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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