I'm attempting to load a KMZ file which has been stored locally in my app. It is not displaying. I'm using the code from GitHub, specifically KmlViewer and that works fine when I click on its local file. I'm running on an iOS Simulator. The code finds the file in the filesystem fine. Code below. Any suggestions on if I'm missing something. I switched to KmlDataset (which works on KlmViewer) but that didn't seem to fix the issue.
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Esri.ArcGISRuntime.Xamarin.Forms;
using System;
using txparks.Data.ViewModel;
using txparks.DS;
using txparks.Utility;
using Xamarin.Forms;
namespace txparks.Views.Downloads
{
public partial class DisplayKml : ContentPage
{
private string TAG { get => this.GetType().Name; }
private readonly Envelope _usEnvelope = new Envelope(-144.619561355187, 18.0328662832097, -66.0903762761083, 67.6390975806745, SpatialReferences.Wgs84);
DisplayKmlVM viewModel;
public DisplayKml()
{
InitializeComponent();
Initialize();
}
protected override void OnAppearing()
{
base.OnAppearing();
//Test2();
Setup();
}
void Initialize()
{
Logger.Debug(TAG, GeneralUtil.GetCallerName());
MySceneView.Scene = new Scene(Basemap.CreateImageryWithLabels());
}
protected override void OnBindingContextChanged()
{
Logger.Debug(TAG, GeneralUtil.GetCallerName());
base.OnBindingContextChanged();
viewModel = (DisplayKmlVM)base.BindingContext;
}
async void Test1()
{
KmlLayer layer = new KmlLayer(new Uri("https://www.wpc.ncep.noaa.gov/kml/noaa_chart/WPC_Day1_SigWx.kml"));
MySceneView.Scene.OperationalLayers.Add(layer);
await MySceneView.SetViewpointAsync(new Viewpoint(viewModel.Envelope));
}
async void Test2()
{
KmlLayer layer = new KmlLayer(new Uri("https://tpwd.texas.gov/spdest/parkinfo/maps/gis/kmz/abilene_sp_trails.kmz"));
//Logger.DebugMedium(TAG, "layer load status: {0}", layer.LoadStatus);
MySceneView.Scene.OperationalLayers.Add(layer);
await MySceneView.SetViewpointAsync(new Viewpoint(viewModel.Envelope));
}
void Refresh(object sender, EventArgs e)
{
Logger.Info(TAG, GeneralUtil.GetCallerName());
Setup();
}
async void Setup()
{
Logger.Info(TAG, GeneralUtil.GetCallerName());
var filePath = viewModel.Uri;
var isExists = DependencyService.Get<IFileService>().FileExists(filePath);
Logger.DebugLow(TAG, "uri exists: {0} | {1}", isExists, filePath);
try
{
MySceneView.Scene.OperationalLayers.Clear();
KmlDataset dataset = new KmlDataset(new Uri(filePath));
Logger.DebugLow(TAG, "dataset status: {0}", dataset.LoadStatus);
Logger.DebugLow(TAG, "dataset error: {0}", dataset.LoadError);
Logger.DebugLow(TAG, "dataset source: {0}", dataset.Source);
KmlLayer layer = new KmlLayer(dataset);
//KmlLayer layer = new KmlLayer(new Uri(filePath));
MySceneView.Scene.OperationalLayers.Add(layer);
await MySceneView.SetViewpointAsync(new Viewpoint(viewModel.Envelope));
}
catch (Exception ex)
{
Logger.Error(TAG, "Setup error: {0}", ex);
}
}
}
}