Combine multiple symbols from a mobile style file into a single symbol.
Use case
You may choose to display individual elements of a dataset like a water infrastructure network (such as valves, nodes, or endpoints) with the same basic shape, but wish to modify characteristics of elements according to some technical specifications. Multilayer symbols lets you add or remove components or modify the colors to create advanced symbol styles.
How to use the sample
Select a symbol and a color from each of the category lists to create an emoji. A preview of the symbol is updated as selections are made. The size of the symbol can be set using the slider. Tap the map to create a point graphic using the customized emoji symbol, and tap "Reset" to clear all graphics from the display.
How it works
- On startup, read a mobile style file using
SymbolStyle.OpenAsync
. - Get a list of all symbols in the style by calling
SearchSymbolsAsync
with the default search parameters. - Iterate the list of
SymbolStyleSearchResult
and add symbols to list boxes according to their category. Display a preview of each symbol withCreateSwatchAsync
. - When symbol selections change, create a new multilayer symbol by passing the keys for the selected symbols into
GetSymbolAsync
. Color lock all symbol layers except the base layer and update the current symbol preview image. - Create graphics symbolized with the current symbol when the user taps the map view.
Relevant API
- MultilayerPointSymbol
- MultilayerSymbol.CreateSwatchAsync
- SymbolLayer
- SymbolStyle
- SymbolStyle.GetSymbolAsync
- SymbolStyleSearchParameters
Offline data
About the data
The mobile style file used in this sample was created using ArcGIS Pro, and is hosted on ArcGIS Online. It contains symbol layers that can be combined to create emojis.
Additional information
While each of these symbols can be created from scratch, a more convenient workflow is to author them using ArcGIS Pro and store them in a mobile style file (.stylx). ArcGIS Runtime can read symbols from a mobile style, and you can modify and combine them as needed in your app.
Tags
advanced symbology, mobile style, multilayer, stylx
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.SymbolsFromMobileStyle.SymbolsFromMobileStyle"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<esriUI:MapView x:Name="MyMapView" Grid.Row="0" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Clicked="ChooseSymbolButtonClicked"
Text="Choose symbol" />
<Button Grid.Column="1"
Clicked="ClearGraphicsButtonClicked"
Text="Clear" />
</Grid>
<Grid x:Name="SelectSymbolGrid"
Grid.Row="0"
Margin="10"
BackgroundColor="White"
HorizontalOptions="Center"
IsVisible="True"
MinimumHeightRequest="300"
MinimumWidthRequest="300"
VerticalOptions="Start">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="100" />
<RowDefinition Height="75" />
<RowDefinition Height="30" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Margin="10,10,0,0"
HorizontalOptions="Center"
Text="Eyes"
TextColor="Gray"
VerticalOptions="Center" />
<ListView x:Name="EyesListView"
Grid.Row="1"
Grid.Column="0"
Margin="10,0,0,0"
HorizontalOptions="Center"
HorizontalScrollBarVisibility="Never"
ItemSelected="SymbolLayerSelected"
VerticalOptions="Center"
VerticalScrollBarVisibility="Never">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell ImageSource="{Binding ImageSrc}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Grid.Row="0"
Grid.Column="1"
Margin="10,10,0,0"
HorizontalOptions="Center"
Text="Mouth"
TextColor="Gray"
VerticalOptions="Center" />
<ListView x:Name="MouthListView"
Grid.Row="1"
Grid.Column="1"
HorizontalOptions="Center"
HorizontalScrollBarVisibility="Never"
ItemSelected="SymbolLayerSelected"
VerticalOptions="Center"
VerticalScrollBarVisibility="Never">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell ImageSource="{Binding ImageSrc}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Grid.Row="0"
Grid.Column="2"
Margin="10,10,0,0"
HorizontalOptions="Center"
Text="Hat"
TextColor="Gray"
VerticalOptions="Center" />
<ListView x:Name="HatListView"
Grid.Row="1"
Grid.Column="2"
HorizontalOptions="Center"
HorizontalScrollBarVisibility="Never"
ItemSelected="SymbolLayerSelected"
VerticalOptions="Center"
VerticalScrollBarVisibility="Never">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell ImageSource="{Binding ImageSrc}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView x:Name="ColorListView"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="10"
HeightRequest="75"
HorizontalOptions="Center"
ItemSelected="SymbolLayerSelected"
VerticalOptions="Center"
WidthRequest="300">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="20">
<Label BackgroundColor="{Binding}" Text="{Binding}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Slider x:Name="SizeSlider"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="10,0"
Maximum="60"
MaximumTrackColor="CadetBlue"
Minimum="8"
MinimumTrackColor="CadetBlue"
Value="20" />
<Label Grid.Row="3"
Grid.Column="2"
HorizontalOptions="Start"
Text="{Binding Source={x:Reference SizeSlider}, Path=Value, StringFormat='Size: {0:0#}'}"
TextColor="Black"
VerticalOptions="Center" />
<Image x:Name="SymbolPreviewImage"
Grid.Row="4"
Grid.Column="1"
Margin="10"
HeightRequest="80"
WidthRequest="80" />
</Grid>
</Grid>
</ContentPage>