Take a web map offline with additional options for each layer.
Use case
When taking a web map offline, you may adjust the data (such as layers or tiles) that is downloaded by using custom parameter overrides. This can be used to reduce the extent of the map or the download size of the offline map. It can also be used to highlight specific data by removing irrelevant data. Additionally, this workflow allows you to take features offline that don't have a geometry - for example, features whose attributes have been populated in the office, but still need a site survey for their geometry.
How to use the sample
Modify the overrides parameters:
- Use the min/max scale input fields to adjust the level IDs to be taken offline for the streets basemap.
- Use the extent buffer distance input field to set the buffer radius for the streets basemap.
- Check the checkboxes for the feature operational layers you want to include in the offline map.
- Use the min hydrant flow rate input field to only download features with a flow rate higher than this value.
- Select the "Water Pipes" checkbox if you want to crop the water pipe features to the extent of the map.
After you have set up the overrides to your liking, click the "Generate offline map" button to start the download. A progress bar will display. Click the "Cancel" button if you want to stop the download. When the download is complete, the view will display the offline map. Pan around to see that it is cropped to the download area's extent.
How it works
- Load a web map from a
PortalItem
. Authenticate with the portal if required. - Create an
OfflineMapTask
with the map. - Generate default task parameters using the extent area you want to download with
offlineMapTask.CreateDefaultGenerateOfflineMapParametersAsync(extent)
. - Generate additional "override" parameters using the default parameters with
offlineMapTask.CreateGenerateOfflineMapParameterOverridesAsync(parameters)
. - For the basemap:
- Get the parameters
OfflineMapParametersKey
for the basemap layer. - Get the
ExportTileCacheParameters
for the basemap layer withoverrides.ExportTileCacheParameters[basemapParamKey]
. - Set the level IDs you want to download with
exportTileCacheParametersLevelIDs().Add(levelID)
. - To buffer the extent, set the
exportTileCacheParameters.AreaOfInterest
property. B uffered geometry can be calculated with theGeometryEngine
.
- Get the parameters
- To remove operational layers from the download:
- Create a
OfflineParametersKey
with the operational layer. - Get the generate geodatabase layer options using the key with
List<GenerateLayerOption> layerOptions = overrides.GenerateGeodatabaseParameters[key].LayerOptions;
- Loop through each
GenerateLayerOption
in the the list, and remove it if the layer option's ID matches the layer's ID.
- Create a
- To filter the features downloaded in an operational layer:
- Get the layer options for the operational layer using the directions in step 6.
- Loop through the layer options. If the option
LayerID
matches the layer's ID, set the filter clause withlayerOption.WhereClause
property and set the query option withlayerOption.QueryOption
property.
- To not crop a layer's features to the extent of the offline map (default is true):
- Set the
layerOption.UseGeometry
property tofalse
.
- Set the
- Create a
GenerateOfflineMapJob
withofflineMapTask.GenerateOfflineMap(parameters, downloadPath, overrides)
. - Get a reference to the offline map with
job.GetResultAsync()
Relevant API
- ExportTileCacheParameters
- GenerateGeodatabaseParameters
- GenerateLayerOption
- GenerateOfflineMapJob
- GenerateOfflineMapParameterOverrides
- GenerateOfflineMapParameters
- GenerateOfflineMapResult
- OfflineMapParametersKey
- OfflineMapTask
Additional information
For applications where you just need to take all layers offline, use the standard workflow (using only GenerateOfflineMapParameters
). For a simple example of how you take a map offline, please consult the "Generate offline map" sample.
Tags
adjust, download, extent, filter, LOD, offline, override, parameters, reduce, scale range, setting
Sample Code
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.GenerateOfflineMapWithOverrides.GenerateOfflineMapWithOverrides"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Border x:Name="TakeOfflineArea" Style="{StaticResource BorderStyle}">
<Grid ColumnSpacing="5" RowSpacing="5">
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="0,0,0,5" />
</Style>
<Style TargetType="TextBox">
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="0,0,0,5" />
</Style>
<Style TargetType="Slider">
<Setter Property="Margin" Value="0,-8,0,0" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
FontWeight="SemiBold"
Text="Adjust the basemap" />
<TextBlock Grid.Row="1"
Grid.Column="0"
Text="Min scale:" />
<Slider x:Name="MinScaleEntry"
Grid.Row="1"
Grid.Column="1"
Maximum="23"
Minimum="0"
SnapsTo="StepValues"
StepFrequency="1"
Value="0" />
<TextBlock Grid.Row="1"
Grid.Column="2"
Text="{Binding ElementName=MinScaleEntry, Path=Value}" />
<TextBlock Grid.Row="2"
Grid.Column="0"
Text="Max scale:" />
<Slider x:Name="MaxScaleEntry"
Grid.Row="2"
Grid.Column="1"
Maximum="23"
Minimum="0"
SnapsTo="StepValues"
StepFrequency="1"
Value="23" />
<TextBlock Grid.Row="2"
Grid.Column="2"
Text="{Binding ElementName=MaxScaleEntry, Path=Value}" />
<TextBlock Grid.Row="3"
Grid.Column="0"
Text="Extent buffer distance (m):" />
<Slider x:Name="ExtentBufferEntry"
Grid.Row="3"
Grid.Column="1"
Maximum="500"
Minimum="0"
SnapsTo="StepValues"
StepFrequency="1"
Value="250" />
<TextBlock Grid.Row="3"
Grid.Column="2"
Text="{Binding ElementName=ExtentBufferEntry, Path=Value}" />
<TextBlock Grid.Row="4"
Grid.Column="0"
FontWeight="SemiBold"
Text="Choose layers" />
<CheckBox x:Name="SysValvesLayerCheckbox"
Grid.Row="5"
Grid.Column="0"
Content="System Valves"
IsChecked="True" />
<CheckBox x:Name="ServiceConnCheckbox"
Grid.Row="6"
Grid.Column="0"
Content="Service Connections" />
<TextBlock Grid.Row="7"
Grid.Column="0"
FontWeight="SemiBold"
Text="Apply a feature layer filer" />
<TextBlock Grid.Row="8"
Grid.Column="0"
VerticalAlignment="Center"
Text="Min Hydrant Flow Rate (GPM):" />
<Slider x:Name="FlowRateFilterEntry"
Grid.Row="8"
Grid.Column="1"
Margin="0,8,0,0"
Maximum="999"
Minimum="0"
SnapsTo="StepValues"
StepFrequency="1"
Value="500" />
<TextBlock Grid.Row="8"
Grid.Column="2"
MinWidth="25"
VerticalAlignment="Center"
Text="{Binding ElementName=FlowRateFilterEntry, Path=Value}" />
<TextBlock Grid.Row="9"
Grid.Column="0"
FontWeight="SemiBold"
Text="Crop layer to extent" />
<CheckBox x:Name="CropLayerCheckbox"
Grid.Row="10"
Grid.Column="0"
Content="Water pipes"
IsChecked="True" />
<Button Grid.Row="11"
Grid.Column="0"
Grid.ColumnSpan="3"
HorizontalAlignment="Stretch"
Click="TakeMapOfflineButton_Click"
Content="Take map offline"
IsEnabled="True" />
</Grid>
</Border>
<Border x:Name="MessageArea"
Width="450"
Margin="30"
Padding="5"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="White"
BorderBrush="Black"
BorderThickness="1"
Visibility="Collapsed">
<StackPanel>
<TextBlock Margin="10"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontWeight="Bold"
Text="Map is offline!" />
</StackPanel>
</Border>
<Grid x:Name="BusyIndicator"
Background="#807f7f7f"
Visibility="Collapsed">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<TextBlock Margin="10"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="18"
Foreground="White">
<Run Text="Generating offline map... " />
<Run x:Name="Percentage" Text="" />
</TextBlock>
<ProgressBar x:Name="ProgressBar"
Grid.Row="1"
Width="100"
Height="10"
Margin="0,0,0,10"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="True"
Maximum="100"
Minimum="0" />
<Button Grid.Row="2"
Width="100"
HorizontalAlignment="Center"
Click="CancelJobButton_Click"
Content="Cancel" />
</Grid>
</Grid>
<Grid x:Name="LoadingIndicator"
Background="#807f7f7f"
Visibility="Visible">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<TextBlock Margin="10"
FontSize="18"
Foreground="White"
Text="Loading online map..." />
<ProgressBar Grid.Row="1"
Width="100"
Height="10"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="True"
IsIndeterminate="True" />
</Grid>
</Grid>
</Grid>
</UserControl>