So I am doing some excercises in the DevLab from the ArcGIS developer platform. I did an excercise in which you load a layer from the ArcGIS Online portal. Their example code is the following (it works like a charm);
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Portal;
namespace LoadAnItemFromArcGISOnline
{
/// <summary>
/// Provides map data to an application
/// </summary>
public class MapViewModel : INotifyPropertyChanged
{
public MapViewModel()
{
InitializeMap();
}
private Map _map = new Map(Basemap.CreateTopographic());
/// <summary>
/// Gets or sets the map
/// </summary>
public Map Map
{
get { return _map; }
set { _map = value; OnPropertyChanged(); }
}
/// <summary>
/// Raises the <see cref="MapViewModel.PropertyChanged" /> event
/// </summary>
/// <param name="propertyName">The name of the property that has changed</param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var propertyChangedHandler = PropertyChanged;
if (propertyChangedHandler != null)
propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
private async void InitializeMap()
{
// Create a portal
ArcGISPortal portal = await ArcGISPortal.CreateAsync();
// Hold a portal item ID
String portalItemId = "883cedb8c9fe4524b64d47666ed234a7";
// Create the portal item
PortalItem portalItem = await PortalItem.CreateAsync(portal, portalItemId);
// Create the layer
FeatureLayer layer = new FeatureLayer(portalItem, 0);
// Ensure the layer is loaded
await layer.LoadAsync();
// Create the map with updated basemap and initial viewpoint
this.Map = new Map(Basemap.CreateTopographic()) { InitialViewpoint = new Viewpoint(layer.FullExtent) };
// Add the layer to the map
this.Map.OperationalLayers.Add(layer);
}
}
}
However, I wanted to try using a different layer. The layer I tried it with is a public layer created by the dutch government. It is a layer showing the heights of the netherlands. http://www.arcgis.com/home/webmap/viewer.html?webmap=4feca304f23847feae20eec8fec76fd8
So I simply replaced the ID of the tutorial with the ID from the Dutch layer and it gives me an error with the await layer.LoadAsync();
It sais the following:
Esri.ArcGISRuntime.ArcGISRuntimeException: 'Invalid response'
It does show a map with an esri basemap with a global extent. but the app is none responsive.
The entire excercise is done in Visual studio with ArcGIS runtime sdk for .net extension.
So what I'm thinking is that the dutch layer has a different coordinate system or maybe the layer has a maximum scale, or maybe the issue is that the data is raster. Does anyone has a tip/ know how to fix it, so that I can display this layer and maybe eventually more dutch layers?
1 Answer 1
Portal items
can contain multiple different types of content. Where in the example the item contains a Feature Service
(item represents a service endpoint that has trailhead features) and provides metadata to describe the content based on the common portal item metadata model.
The second item contains a webmap. Webmaps (or maps) are items that contain the full map definition including Basemaps
and Operational layers
. Compared to the item that only contains a single layer, maps can be describe/author the whole map.
So the reason why your code doesn't work is that you try to create a Feature Layer
from Map
. You can use PortalItemType
enum to check which type the item is.
if (portalItem.Type == PortalItemType.FeatureService)
{
// it's a feature service
// Create the layer
FeatureLayer layer = new FeatureLayer(portalItem, 0);
// Ensure the layer is loaded
await layer.LoadAsync();
// Create the map with updated basemap and initial viewpoint
Map = new Map(Basemap.CreateTopographic()) { InitialViewpoint = new Viewpoint(layer.FullExtent) };
Map.OperationalLayers.Add(layer);
}
if (portalItem.Type == PortalItemType.WebMap)
{
// Create map from a map definition
Map = new Map(portalItem);
}
Explore related questions
See similar questions with these tags.