windows-runtime – MapControl区分用户或程序中心更改
在WinRt / WP 8.1 MapControl中,如何通过滑动和程序化更改区分用户何时更改屏幕中心?
WinRt / WP 8.1 MapControl有一个CenterChanged事件(http://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.maps.mapcontrol.centerchanged.aspx),但是这并不提供有关导致中心更改的信息. 有没有其他方法可以知道用户是否更改了地图中心? / *为了提供更多上下文,我的具体情况如下: >如果找到gps位置,我想在地图上放一个点并将地图居中到那一点. 我可以通过比较gps位置和中心来解决这个问题,但是他的gps位置latLng是一个不同的类型&精度为Map.Center latLng.我更喜欢更简单,更少hacky的解决方案. 解决方法
我通过在调用等待的TrySetViewAsync之前将bool ignoreNextViewportChanges设置为true来解决此问题,并在异步操作完成后将其重置为false.
在事件处理程序中,我立即打破Routine然后ignoreNextViewportChanges仍然是真的. 所以最后看起来像: bool ignoreNextViewportChanges; public void HandleMapCenterChanged() { Map.CenterChanged += (sender,args) => { if(ignoreNextViewportChanges) return; //if you came here,the user has changed the location //store this information somewhere and skip SetCenter next time } } public async void SetCenter(BasicGeoposition center) { ignoreNextViewportChanges = true; await Map.TrySetViewAsync(new Geopoint(Center)); ignoreNextViewportChanges = false; } 如果您有可能并行调用SetCenter两次(以便SetCenter的最后一次调用尚未完成,但再次调用SetCenter),则可能需要使用计数器: int viewportChangesInProgressCounter; public void HandleMapCenterChanged() { Map.CenterChanged += (sender,args) => { if(viewportChangesInProgressCounter > 0) return; //if you came here,the user has changed the location //store this information somewhere and skip SetCenter next time } } public async void SetCenter(BasicGeoposition center) { viewportChangesInProgressCounter++; await Map.TrySetViewAsync(new Geopoint(Center)); viewportChangesInProgressCounter--; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 如何在Windows上从命令行播放音频文件?
- 尝试(并且失败)在Windows 10上的64位Ubuntu上运行Hello Wor
- .net – SocketAsyncEventArgs.Completed在Windows 8中不会
- windows10家庭版安装docker
- Windows鼠标右键菜单添加SublimeText打开选项
- Flutter开发环境配置-Windows
- Spyder接口图标非常小在Windows 10的高分辨率屏幕上
- 仅允许与Windows Azure VM的本地网络连接?
- 恢复Windows 10自带的微软正黑字体
- 有人可以确认Microsoft Excel 2007内部如何表示数字吗?
- windows-xp – 分页池内存或非分页池内存?? (Win
- Windows – 从批处理文件在新窗口中启动进程
- Windows – 事件ID 9331 MSExchangeSA和事件ID 9
- windows-server-2008 – 经过MS Windows Server
- windows – 内存映射文件保留在物理内存中?
- 如何使用Windows搜索搜索Jar文件?
- MSDN Windows XP Professional x64 Edition with
- Windows – Tomcat 7的service.bat文件丢失
- .net – 如何在Windows窗体中禁用更新表单?
- windows-server-2008-r2 – 使用100%RAM的Windo