[英]How to Cluster Xamarin.Forms.GoogleMaps Pin in PCL Project
Since I am doing a map based cross-platform project on Xamarin, And I'm stuck to the point where I need to cluster markers when zooming out. 由于我正在Xamarin上进行基于地图的跨平台项目,因此我被困在缩小时需要对标记进行聚类的地步。 things I had tried:
我尝试过的事情:
I know I can achieve it with that with custom map renderer, but I cant do that coz. 我知道我可以使用自定义地图渲染器来实现,但是我做不到。 a lot of code related to map is already written, I don't want to rewrite a Code.
已经编写了许多与地图有关的代码,我不想重写代码。 So Is there any possibility that I can get a native instance of the map that I can use on dependency service.
那么,是否有可能我可以在依赖服务上使用地图的本机实例。
I created CustomRenderer For Map without creating a customMap class at PCL (inherit Map class) the code is below. 我创建了CustomRenderer For Map,而没有在PCL(继承Map类)上创建customMap类,代码如下。 but it's not get triggered.
但不会被触发。 What wrong I am doing here...
我在这里做什么错...
custom renderer code: 自定义渲染器代码:
[assembly: ExportRenderer(typeof(Map), typeof(MarkerClusterRenderer))]
namespace SamplingApp.Droid.CustomRenderers
{
public class MarkerClusterRenderer : MapRenderer
{
ClusterManager _clusterManager;
protected override void OnMarkerCreated(Pin outerItem, Marker innerItem)
{
base.OnMarkerCreated(outerItem, innerItem);
AddToMarkerCluster();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
}
protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
{
base.OnElementChanged(e);
}
public void AddToMarkerCluster()
{
_clusterManager = new ClusterManager(Android.App.Application.Context, NativeMap);
//[do other things here]
}
}
}
since I am is new to xamarin. 因为我是xamarin的新手。 little guidance is appreciated.
很少的指导表示赞赏。 am I in the right direction?
我的方向正确吗?
Thank you in advance. 先感谢您。 and sorry for my English.
对不起,我的英语。
I created CustomRenderer For Map without creating a customMap class at PCL (inherit Map class) the code is below.
我创建了CustomRenderer For Map,而没有在PCL(继承Map类)上创建customMap类,代码如下。 but it's not get triggered.
但不会被触发。 What wrong I am doing here...
我在这里做什么错...
If you want to customize the map, you need to create a custom class for map control in PCL: 如果要自定义地图,则需要为PCL中的地图控件创建自定义类:
public class CustomMap:Map
{
}
And use it in xaml: 并在xaml中使用它:
<local:CustomMap WidthRequest="320" HeightRequest="200"
x:Name="MyMap"
IsShowingUser="true"
MapType="Hybrid"/>
And renderer: 和渲染器:
[assembly:ExportRenderer(typeof(SamplingApp.CustomMap),
typeof(MarkerClusterRenderer))]
namespace SamplingApp.Droid.CustomRenderers
{
public class MarkerClusterRenderer:MapRenderer
{
...
Then, your renderer's codes will be triggered correctly. 然后,渲染器的代码将被正确触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.