c# - 为 Android 刷新地图加载
问题描述
我正在开发一个用户必须发现地方的应用程序。我正在使用它来显示地图上未发现地点的区域: https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map/circle-map-overlay
但后来随着应用程序功能的增长,它不再运行良好。这是我的github的链接。 https://github.com/jakuboles/TDKInz2020/tree/master/TDK
用户登录后,TDK.Android.CustomMapRenderer.OnElementChanged 函数在 TDK.MainPage.xaml.cs.DisplayInMap 之前被调用的速度更快,我在其中设置了哪些地方应该显示为已发现,哪些为未发现。结果,现在应用程序始终位于 TDK.Android.CustomMapRenderer.OnElementChanged 第 36 行位置列表始终为空,并且调用 OnMapReady 绘制圆圈列表为空。
当 DisplayInMap 将位置分配给列表时,是否有某种方法可以再次调用 OnElementChanged?或者让 OnElementChanged 稍后运行,在 DisplayInMap 之后会设置列表。
很抱歉,如果这是一个复杂的描述;不知道如何正确描述。
这是我的 Android 渲染器:
using Android.Content;
using Android.Gms.Maps.Model;
using Java.Lang;
using MapOverlay;
using MapOverlay.Droid;
using System.Collections.Generic;
using TDK.MapsCustoms;
using Xamarin.Forms;
using Xamarin.Forms.Maps.Android;
[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace MapOverlay.Droid
{
public class CustomMapRenderer : MapRenderer
{
List<CustomCircle> circles;
public CustomMapRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.Maps.Map> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
}
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
circles = formsMap.CircleList;
}
}
protected override void OnMapReady(Android.Gms.Maps.GoogleMap map)
{
base.OnMapReady(map);
foreach (var circle in circles)
{
var circleOptions = new CircleOptions();
circleOptions.InvokeCenter(new LatLng(circle.Position.Latitude, circle.Position.Longitude));
circleOptions.InvokeRadius(circle.Radius);
circleOptions.InvokeFillColor(0X66FF0000);
circleOptions.InvokeStrokeColor(0X66FF0000);
circleOptions.InvokeStrokeWidth(0);
NativeMap.AddCircle(circleOptions);
}
}
}
}
解决方案
移动线
circles = formsMap.CircleList;
从OnElementChanged
到OnMapReady
推荐阅读
- python - 如何使用 while 循环来检测列表中是否已提供客户 ID?
- html - pdf文件无法从网页下载
- flutter - 颤振安装
- python - 为什么`filter`适用于一个列表而不适用于其他给出“具有多个元素的数组的真值是不明确的。”?
- list - 迁移时忽略列表项
- python-3.x - 从另一个项目导入模型
- python - 使用 Flask 在 Web 上提供 Windows CLI 脚本:如何实时更新输出?以及如何链接输入?
- angular - Firefox 中的角度元素“this.ngElementStrategy 未定义”
- java - 如何从 GitHub 发布 Android 库?
- php - Visual Studio Code - PHPCS 扩展 - 权限被拒绝