[英]Add a JSON layer in a Button click - Xamarin.Forms
我是Xamarin.Forms
,我想在地圖上單擊按鈕時添加一個JSON層。 我怎樣才能做到這一點?
我正在使用Xamarin.Forms.GoogleMaps
創建地圖。
我嘗試使用添加JSON層的依賴項。我找到了一個解決方案的android,但我被困在ios上
這是我的代碼:
private void Close_Tapped(object sender, EventArgs e)
{
try
{
var _IIGeoJsonLayer = DependencyService.Get<IGeoJsonLayer>();
_IIGeoJsonLayer.AddLayerJson();
}
catch (Exception ex)
{
}
}
這是我的依賴服務:
public void AddLayerJson()
{
GoogleMap gmap =null;
GeoJsonLayer layer = new GeoJsonLayer(gmap, Resource.Raw.jsonFile, Android.App.Application.Context);
layer.AddLayerToMap();
}
CustomRenderer.CS
protected override void OnMapReady(GoogleMap map)
{
base.OnMapReady(map);
gmap = map;
KMLClass _class = new KMLClass(gmap);
}
Class.cs
public class KMLClass
{
public static GoogleMap gmap;
public KMLClass(GoogleMap map)
{
if(gmap==null)
{
if(map!=null)
{
gmap = map;
}
}
}
public void AddKML()
{
GeoJsonLayer layer = new GeoJsonLayer(gmap, Resource.Raw.jsonFile, Android.App.Application.Context);
layer.AddLayerToMap();
}
依賴類
public class JsonLayerAdd : IGeoJsonLayer
{
GoogleMap map = null;
public void AddLayerJson()
{
KMLClass _map = new KMLClass(map);
_map.AddKML();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.