Skip to Content
ExamplesTemps Draw Range

MapsGL Android - Adjusting temperature draw range in real time

A draw range limits which values a sample layer paints at all. Values outside it are left transparent, not clamped to the end colours of the scale, so narrowing it isolates a band of interest — only freezing temperatures, say — without touching the colour scale. This example sets the range for the temperatures layer from two sliders.

It is the Android port of the MapsGL JS Adjusting temperature draw range in real time example. The complete activity ships in the MapsGL Android SDK demo  as AdjustDrawRangeActivity.

Temperatures over eastern North America drawn only between the Min and Max slider values, with the base map showing where it is warmer

Set the range in the data’s units

The range is sample.drawRange on the layer’s paint:

val config = WeatherService.Temperatures(controller.service) val low = minOf(lowerF, upperF) val high = maxOf(lowerF, upperF) (config.layer.paint as SampleLayerPaint).sample.drawRange = celsius(low)..celsius(high) controller.addWeatherLayer(config)

The sliders read in Fahrenheit because that is what the map displays, but the range is set in Celsius. A draw range is always in the data’s own units, and every MapsGL dataset is metric.

Both sliders span the same fixed −60 °F to 120 °F track. Limiting one by the other’s current value would rescale its track whenever the other moved, so the same thumb position would mean a different temperature from one drag to the next. The cost is that the two can be dragged past each other, which is why the pair is ordered with minOf and maxOf rather than trusted.

Re-add the layer rather than update it

The JS example calls setPaintProperty('sample.drawRange.min', …) on each slider move. The Android demo removes the temperatures layer and adds it again with the new range:

private fun reAddTemperatures() = reAddLayer(LayerCode.TEMPERATURES) { addTemperatures(controller) }

Paint is captured when the layer is built, so changing drawRange on a layer that is already on the map has no effect on its own — and setPaintProperty does not take a draw range path; on sample layers it handles sample.colorscale. Re-adding always picks up the new value.

Re-adding is not free: the layer re-registers and re-reads its cached tiles. So the sliders update their labels as they move, and only apply the range when the finger lifts.

Leaving one end open

Both ends are set here because both sliders are. To clip only one side, use BoundedRange from com.xweather.mapsgl.types.math_type:

paint.sample.drawRange = BoundedRange.atMost(0.0) // freezing and below paint.sample.drawRange = BoundedRange.atLeast(32.2) // 90 °F and above

The open end is filled in from the layer’s own data range, which is the counterpart of setting only min or only max in JS. A plain ClosedRange can do the same only by naming an arbitrary floor or ceiling.

© 2026 Xweather (opens in a new tab)Terms of Service (opens in a new tab)Privacy Policy (opens in a new tab)