Hello,
So I have a project I inherited and I want to build a zoom extent button for each TPK that is loaded. I have created the zoom button next to the delete button for each loaded TPK and the delete option works but the zoom extent does not. I was wondering if I could get a little help because I cannot seem to get the zoom extent property. Below is the code:
public void ZoomToLayer(bool fromSelection)
{if (esriMap != null && _selectedLayer != null && fromSelection)
{
// Get selected layer
MapPageLayers subFile = (MapPageLayers)_selectedLayer;
string localLayerPath = Path.Combine(accessData.ProjectPath, subFile.LayerName);//For tpks
if (!subFile.LayerName.Contains("sql"))
{
Layer foundLayer = null;// Find the layer from the image layer
foreach (Layer l in esriMap.AllLayers)
{
if (l.Name == subFile.LayerName.Split('.')[0])
{
foundLayer = l;
break;
}
}if (foundLayer != null)
{
//Zoom to extent of LayeresriMap.Basemap.Item.Extent = foundLayer.FullExtent;
}
//Reset layer and layer flyout
_selectedLayer = string.Empty;
}else
{//Zoom to extent of Layer
esriMap.Basemap.Item.Extent = foundLayer.FullExtent;
//Reset layer and layer flyout
_selectedLayer = string.Empty;
}
}
}
}
Now This code works for deleting a tpk map layer but I tried to get the zoom extent feature of the layer and cannot because I am not an expert coder at all. Does anyone know how to do this? The code in red is the code that gives me issues.
Solved! Go to Solution.
Hello,
Changing the extent of the basemap's item won't directly affect the view. The extent on an item is used as metadata for other parts of the ArcGIS system (e.g. searching a Portal/ArcGIS Online).
You should be able to set the viewpoint on the MapView that is being used to show esriMap with something like the following:
esriMapView.SetViewpoint(new Viewpoint(foundLayer.FullExtent));
Hello,
Changing the extent of the basemap's item won't directly affect the view. The extent on an item is used as metadata for other parts of the ArcGIS system (e.g. searching a Portal/ArcGIS Online).
You should be able to set the viewpoint on the MapView that is being used to show esriMap with something like the following:
esriMapView.SetViewpoint(new Viewpoint(foundLayer.FullExtent));
Ok thank you Nathan. I put that code in and it says the map doesn't contain a definition for SetViewPoint. I guess I have to define ViewPoint somewhere?
The Map and the MapView are two separate objects. MapView is the UI component that displays the content, and the Map defines what is to be displayed.
The code you shared references the Map, but you can only control navigation from the MapView. Typically the MapView will be defined in XAML somewhere, but it doesn't have to be.
The following tutorial might be helpful, because it shows a common design pattern and the map/mapview separation: https://developers.arcgis.com/net/maps-2d/tutorials/display-a-map/
I believe I found it:
<esriUI:MapView x:Name="myMapView" Tapped="{x:Bind Path=ViewModel.myMapView_IdentifyFeature}" IsDoubleTapEnabled="True"/>
Now When I put this in My ViewModel file I get an error:
myMapView.SetViewpoint(new Viewpoint(foundLayer.FullExtent));
Says myMapView does not exist in current context.