Style WMS layers

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Change the style of a Web Map Service (WMS) layer.

Image of style WMS layers

Use case

Layers hosted on WMS may have different pre-set styles available to apply to them. Swapping between these styles can help during visual examination of the data. For example, increasing the contrast of satellite images can help in identifying urban and agricultural areas within forested areas.

How to use the sample

Once the layer loads, the toggle button will be enabled. Tap it to toggle between the first and second styles of the WMS layer.

How it works

  1. Create a WmsLayer specifying the URL of the service and the layer names you want new WmsLayer(url, names).
  2. When the layer is done loading, get it's list of style strings using wmsLayer.Sublayers[0].SublayerInfo.Styles.
  3. Set one of the styles using the wmsLayer.Sublayers[0].CurrentStyle property.

Relevant API

  • WmsLayer
  • WmsSublayer
  • WmsSublayerInfo

About the data

This sample uses a public service managed by the State of Minnesota and provides composite imagery for the state and the surrounding areas.

Tags

imagery, styles, visualization, WMS

Sample Code

StyleWmsLayer.xamlStyleWmsLayer.xamlStyleWmsLayer.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.StyleWmsLayer.StyleWmsLayer"
             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 Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0"
               Grid.Column="0"
               Grid.ColumnSpan="2"
               HorizontalTextAlignment="Center"
               Text="Choose a style" />
        <Button x:Name="FirstStyleButton"
                Grid.Row="1"
                Grid.Column="0"
                Clicked="FirstStyleButton_Clicked"
                Text="Default" />
        <Button x:Name="SecondStyleButton"
                Grid.Row="1"
                Grid.Column="1"
                Clicked="SecondStyleButton_Clicked"
                Text="Contrast stretch" />
        <esriUI:MapView x:Name="MyMapView"
                        Grid.Row="2"
                        Grid.Column="0"
                        Grid.ColumnSpan="2" />
    </Grid>
</ContentPage>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.