View on GitHub Sample viewer app

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

Image of apply style to WMS layer

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. Click 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 WmsLayer(url, names).
  2. When the layer is done loading, get it’s list of style strings using wmsLayer.layerInfos.firstOrNull()?.styles.
  3. Set one of the styles using wmsSublayer.currentStyle = styleString.

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

MainActivity.kt MainActivity.kt ApplyStyleToWMSLayerViewModel.kt ApplyStyleToWMSLayerScreen.kt
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.applystyletowmslayer
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.applystyletowmslayer.screens.ApplyStyleToWmsLayerScreen
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
setContent {
SampleAppTheme {
ApplyStyleToWMSLayerApp()
}
}
}
@Composable
private fun ApplyStyleToWMSLayerApp() {
Surface(color = MaterialTheme.colorScheme.background) {
ApplyStyleToWmsLayerScreen(
sampleName = getString(R.string.apply_style_to_wms_layer_app_name)
)
}
}
}