WIndows UWP Zoom Extent on tpk map layer

623
4
Jump to solution
01-26-2022 05:27 PM
jameljoseph
New Contributor II

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 Layer

esriMap.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.

0 Kudos
1 Solution

Accepted Solutions
NathanCastle1
Esri Contributor

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

 

View solution in original post

0 Kudos
4 Replies
NathanCastle1
Esri Contributor

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

 

0 Kudos
jameljoseph
New Contributor II

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?

0 Kudos
NathanCastle1
Esri Contributor

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/ 

 

 

0 Kudos
jameljoseph
New Contributor II

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.

0 Kudos