Loading KMZ file from app not displaying

1355
7
Jump to solution
07-07-2021 02:51 PM
too_hoppy
New Contributor

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);
}
}

}
}

 

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

You could try awaiting the async load on the KmlDataset or KmlLayer (depending on the approach you're taking) and check the load status, noting that load may return an exception is there's an error. Also try the SceneView LayerViewStateChanged event to identify layer-related drawing activity (in/out of scale, errors, etc).

 

View solution in original post

0 Kudos
7 Replies
xiazhen
New Contributor

I have also meet the problem,.you can copy tif into smart phone, run and dispaly the image.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

You could try awaiting the async load on the KmlDataset or KmlLayer (depending on the approach you're taking) and check the load status, noting that load may return an exception is there's an error. Also try the SceneView LayerViewStateChanged event to identify layer-related drawing activity (in/out of scale, errors, etc).

 

0 Kudos
too_hoppy
New Contributor

Thank you for the suggestions. I will hold off on trying the tiff suggestion for now. I've attempted to use loadAsync on both the dataset as well as the layer, but apparently our esri/gis license does not allow for that and I get an 'Unlicensed feature' error. I can do a LoadAsync on the scene but that doesn't appear to help. 

I've also moved the kmz file to a different location in the file system and modified the sample DataManager from the ArcGIS samples project to make use of that location but that didn't work as well. I know the kmz file works because it opens up fine in the Google Earth app and I can retrieve the same file from a url and display it that way. Will continue searching for a solution. Thanks for the suggestions.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

If the load async throws an unlicensed error, that might indicate you've set a license but the license level is too low for this functionality. Try commenting out any licensing code for now and running in developer mode (you'll see a watermark on the scene view). This topic provides more info on licensing.

Also this topic provides detailed information about API calls that require a specific license level.

0 Kudos
too_hoppy
New Contributor

Thanks Michael! After commenting out the license and adding layer.LoadAsync, the kmz file displayed on the scene. Now to figure out the license needed to run that method.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor
0 Kudos
too_hoppy
New Contributor

You are correct. With license commented out and removing layer.LoadAsync, the kmz file displayed as well. So it was in the end a license issue. Thanks!

0 Kudos