Skip to content

Commit

Permalink
Merge pull request #551 from Esri/ncastle/enc-cell-to-dataset
Browse files Browse the repository at this point in the history
Update the ENC samples to not use individual cells
  • Loading branch information
nCastle1 authored Oct 17, 2018
2 parents d763637 + 35bcc0f commit f13b218
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace ArcGISRuntime.Samples.SelectEncFeatures
{
[Activity]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("a490098c60f64d3bbac10ad131cc62c7")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("9d2987a825c646468b3ce7512fb76e2d")]
[ArcGISRuntime.Samples.Shared.Attributes.Sample(
"Select ENC features",
"Hydrography",
Expand Down Expand Up @@ -51,19 +51,39 @@ private async void Initialize()
_myMapView.Map = new Map(Basemap.CreateOceans());

// Get the path to the ENC Exchange Set
string encPath = GetEncPath();
string encPath = DataManager.GetDataFolder("9d2987a825c646468b3ce7512fb76e2d", "ExchangeSetwithoutUpdates", "ENC_ROOT", "CATALOG.031");

// Create the cell and layer
EncLayer encLayer = new EncLayer(new EncCell(encPath));
// Create the Exchange Set
// Note: this constructor takes an array of paths because so that update sets can be loaded alongside base data
EncExchangeSet myEncExchangeSet = new EncExchangeSet(encPath);

// Add the layer to the map
_myMapView.Map.OperationalLayers.Add(encLayer);
// Wait for the exchange set to load
await myEncExchangeSet.LoadAsync();

// Wait for the layer to load
await encLayer.LoadAsync();
// Store a list of data set extent's - will be used to zoom the mapview to the full extent of the Exchange Set
List<Envelope> dataSetExtents = new List<Envelope>();

// Add each data set as a layer
foreach (EncDataset myEncDataset in myEncExchangeSet.Datasets)
{
// Create the cell and layer
EncLayer myEncLayer = new EncLayer(new EncCell(myEncDataset));

// Add the layer to the map
_myMapView.Map.OperationalLayers.Add(myEncLayer);

// Wait for the layer to load
await myEncLayer.LoadAsync();

// Add the extent to the list of extents
dataSetExtents.Add(myEncLayer.FullExtent);
}

// Use the geometry engine to compute the full extent of the ENC Exchange Set
Envelope fullExtent = GeometryEngine.CombineExtents(dataSetExtents);

// Set the viewpoint
await _myMapView.SetViewpointAsync(new Viewpoint(encLayer.FullExtent));
_myMapView.SetViewpoint(new Viewpoint(fullExtent));

// Subscribe to tap events (in order to use them to identify and select features)
_myMapView.GeoViewTapped += MyMapView_GeoViewTapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ArcGISRuntime.Samples.SelectEncFeatures
"Hydrography",
"This sample demonstrates how to select an ENC feature.",
"This sample automatically downloads ENC data from ArcGIS Online before displaying the map.")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("a490098c60f64d3bbac10ad131cc62c7")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("9d2987a825c646468b3ce7512fb76e2d")]
public partial class SelectEncFeatures : ContentPage
{
public SelectEncFeatures()
Expand All @@ -43,19 +43,39 @@ private async void Initialize()
MyMapView.Map = new Map(Basemap.CreateOceans());

// Get the path to the ENC Exchange Set
string encPath = GetEncPath();
string encPath = DataManager.GetDataFolder("9d2987a825c646468b3ce7512fb76e2d", "ExchangeSetwithoutUpdates", "ENC_ROOT", "CATALOG.031");

// Create the cell and layer
EncLayer encLayer = new EncLayer(new EncCell(encPath));
// Create the Exchange Set
// Note: this constructor takes an array of paths because so that update sets can be loaded alongside base data
EncExchangeSet myEncExchangeSet = new EncExchangeSet(encPath);

// Add the layer to the map
MyMapView.Map.OperationalLayers.Add(encLayer);
// Wait for the exchange set to load
await myEncExchangeSet.LoadAsync();

// Wait for the layer to load
await encLayer.LoadAsync();
// Store a list of data set extent's - will be used to zoom the mapview to the full extent of the Exchange Set
List<Envelope> dataSetExtents = new List<Envelope>();

// Add each data set as a layer
foreach (EncDataset myEncDataset in myEncExchangeSet.Datasets)
{
// Create the cell and layer
EncLayer myEncLayer = new EncLayer(new EncCell(myEncDataset));

// Add the layer to the map
MyMapView.Map.OperationalLayers.Add(myEncLayer);

// Wait for the layer to load
await myEncLayer.LoadAsync();

// Add the extent to the list of extents
dataSetExtents.Add(myEncLayer.FullExtent);
}

// Use the geometry engine to compute the full extent of the ENC Exchange Set
Envelope fullExtent = GeometryEngine.CombineExtents(dataSetExtents);

// Set the viewpoint
await MyMapView.SetViewpointAsync(new Viewpoint(encLayer.FullExtent));
MyMapView.SetViewpoint(new Viewpoint(fullExtent));

// Subscribe to tap events (in order to use them to identify and select features)
MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ArcGISRuntime.UWP.Samples.SelectEncFeatures
"Hydrography",
"This sample demonstrates how to select an ENC feature.",
"This sample automatically downloads ENC data from ArcGIS Online before displaying the map.")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("a490098c60f64d3bbac10ad131cc62c7")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("9d2987a825c646468b3ce7512fb76e2d")]
public partial class SelectEncFeatures
{
public SelectEncFeatures()
Expand All @@ -41,19 +41,39 @@ private async void Initialize()
MyMapView.Map = new Map(Basemap.CreateOceans());

// Get the path to the ENC Exchange Set
string encPath = GetEncPath();
string encPath = DataManager.GetDataFolder("9d2987a825c646468b3ce7512fb76e2d", "ExchangeSetwithoutUpdates", "ENC_ROOT", "CATALOG.031");

// Create the cell and layer
EncLayer encLayer = new EncLayer(new EncCell(encPath));
// Create the Exchange Set
// Note: this constructor takes an array of paths because so that update sets can be loaded alongside base data
EncExchangeSet myEncExchangeSet = new EncExchangeSet(encPath);

// Add the layer to the map
MyMapView.Map.OperationalLayers.Add(encLayer);
// Wait for the exchange set to load
await myEncExchangeSet.LoadAsync();

// Wait for the layer to load
await encLayer.LoadAsync();
// Store a list of data set extent's - will be used to zoom the mapview to the full extent of the Exchange Set
List<Envelope> dataSetExtents = new List<Envelope>();

// Add each data set as a layer
foreach (EncDataset myEncDataset in myEncExchangeSet.Datasets)
{
// Create the cell and layer
EncLayer myEncLayer = new EncLayer(new EncCell(myEncDataset));

// Add the layer to the map
MyMapView.Map.OperationalLayers.Add(myEncLayer);

// Wait for the layer to load
await myEncLayer.LoadAsync();

// Add the extent to the list of extents
dataSetExtents.Add(myEncLayer.FullExtent);
}

// Use the geometry engine to compute the full extent of the ENC Exchange Set
Envelope fullExtent = GeometryEngine.CombineExtents(dataSetExtents);

// Set the viewpoint
await MyMapView.SetViewpointAsync(new Viewpoint(encLayer.FullExtent));
MyMapView.SetViewpoint(new Viewpoint(fullExtent));

// Subscribe to tap events (in order to use them to identify and select features)
MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
Expand Down Expand Up @@ -95,13 +115,13 @@ private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs
// Get the layer associated with this set of results
EncLayer containingLayer = (EncLayer)firstResult.LayerContent;

// Select the smallest (area) feature in the layer.
// Select the smallest (area) feature in the layer
EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First();

// Select the feature.
// Select the feature
containingLayer.SelectFeature(smallestFeature);

// Create the callout definition.
// Create the callout definition
CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description);

// Show the callout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ArcGISRuntime.WPF.Samples.SelectEncFeatures
"Hydrography",
"This sample demonstrates how to select an ENC feature.",
"This sample automatically downloads ENC data from ArcGIS Online before displaying the map.")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("a490098c60f64d3bbac10ad131cc62c7")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("9d2987a825c646468b3ce7512fb76e2d")]
public partial class SelectEncFeatures
{
public SelectEncFeatures()
Expand All @@ -36,31 +36,51 @@ public SelectEncFeatures()

private async void Initialize()
{
// Initialize the map with an oceans basemap
// Initialize the map with an oceans basemap.
MyMapView.Map = new Map(Basemap.CreateOceans());

// Get the path to the ENC Exchange Set
string encPath = GetEncPath();
// Get the path to the ENC Exchange Set.
string encPath = DataManager.GetDataFolder("9d2987a825c646468b3ce7512fb76e2d", "ExchangeSetwithoutUpdates", "ENC_ROOT", "CATALOG.031");

// Create the cell and layer.
EncLayer encLayer = new EncLayer(new EncCell(encPath));
// Create the Exchange Set.
// Note: this constructor takes an array of paths because so that update sets can be loaded alongside base data.
EncExchangeSet myEncExchangeSet = new EncExchangeSet(encPath);

// Add the layer to the map.
MyMapView.Map.OperationalLayers.Add(encLayer);
// Wait for the exchange set to load.
await myEncExchangeSet.LoadAsync();

// Wait for the layer to load.
await encLayer.LoadAsync();
// Store a list of data set extent's - will be used to zoom the mapview to the full extent of the Exchange Set.
List<Envelope> dataSetExtents = new List<Envelope>();

// Add each data set as a layer.
foreach (EncDataset myEncDataset in myEncExchangeSet.Datasets)
{
// Create the cell and layer.
EncLayer myEncLayer = new EncLayer(new EncCell(myEncDataset));

// Add the layer to the map.
MyMapView.Map.OperationalLayers.Add(myEncLayer);

// Wait for the layer to load.
await myEncLayer.LoadAsync();

// Add the extent to the list of extents.
dataSetExtents.Add(myEncLayer.FullExtent);
}

// Use the geometry engine to compute the full extent of the ENC Exchange Set.
Envelope fullExtent = GeometryEngine.CombineExtents(dataSetExtents);

// Set the viewpoint.
await MyMapView.SetViewpointAsync(new Viewpoint(encLayer.FullExtent));
MyMapView.SetViewpoint(new Viewpoint(fullExtent));

// Subscribe to tap events (in order to use them to identify and select features).
MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
}

private void ClearAllSelections()
{
// For each layer in the operational layers that is an ENC layer
// For each layer in the operational layers that is an ENC layer.
foreach (EncLayer layer in MyMapView.Map.OperationalLayers.OfType<EncLayer>())
{
// Clear the layer's selection.
Expand Down Expand Up @@ -106,10 +126,5 @@ private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.
// Show the callout.
MyMapView.ShowCalloutAt(e.Location, definition);
}

private static string GetEncPath()
{
return DataManager.GetDataFolder("a490098c60f64d3bbac10ad131cc62c7", "GB5X01NW.000");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace ArcGISRuntime.Samples.SelectEncFeatures
{
[Register("SelectEncFeatures")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("a490098c60f64d3bbac10ad131cc62c7")]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("9d2987a825c646468b3ce7512fb76e2d")]
[ArcGISRuntime.Samples.Shared.Attributes.Sample(
"Select ENC features",
"Hydrography",
Expand All @@ -44,19 +44,39 @@ private async void Initialize()
_myMapView.Map = new Map(Basemap.CreateOceans());

// Get the path to the ENC Exchange Set.
string encPath = DataManager.GetDataFolder("a490098c60f64d3bbac10ad131cc62c7", "GB5X01NW.000");
string encPath = DataManager.GetDataFolder("9d2987a825c646468b3ce7512fb76e2d", "ExchangeSetwithoutUpdates", "ENC_ROOT", "CATALOG.031");

// Create the cell and layer.
EncLayer encLayer = new EncLayer(new EncCell(encPath));
// Create the Exchange Set.
// Note: this constructor takes an array of paths because so that update sets can be loaded alongside base data.
EncExchangeSet myEncExchangeSet = new EncExchangeSet(encPath);

// Add the layer to the map.
_myMapView.Map.OperationalLayers.Add(encLayer);
// Wait for the exchange set to load.
await myEncExchangeSet.LoadAsync();

// Wait for the layer to load.
await encLayer.LoadAsync();
// Store a list of data set extent's - will be used to zoom the mapview to the full extent of the Exchange Set.
List<Envelope> dataSetExtents = new List<Envelope>();

// Set the viewpoint.
await _myMapView.SetViewpointAsync(new Viewpoint(encLayer.FullExtent));
// Add each data set as a layer.
foreach (EncDataset myEncDataset in myEncExchangeSet.Datasets)
{
// Create the cell and layer.
EncLayer myEncLayer = new EncLayer(new EncCell(myEncDataset));

// Add the layer to the map.
_myMapView.Map.OperationalLayers.Add(myEncLayer);

// Wait for the layer to load.
await myEncLayer.LoadAsync();

// Add the extent to the list of extents.
dataSetExtents.Add(myEncLayer.FullExtent);
}

// Use the geometry engine to compute the full extent of the ENC Exchange Set.
Envelope fullExtent = GeometryEngine.CombineExtents(dataSetExtents);

// Set the viewpoint
_myMapView.SetViewpoint(new Viewpoint(fullExtent));

// Subscribe to tap events (in order to use them to identify and select features).
_myMapView.GeoViewTapped += MyMapView_GeoViewTapped;
Expand Down

0 comments on commit f13b218

Please sign in to comment.