|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, MapTiler |
| 3 | + * All rights reserved. |
| 4 | + * SPDX-License-Identifier: BSD 3-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +package com.maptiler.maptilersdk.map.style.layer.raster |
| 8 | + |
| 9 | +import com.maptiler.maptilersdk.map.style.layer.MTLayer |
| 10 | +import com.maptiler.maptilersdk.map.style.layer.MTLayerType |
| 11 | +import com.maptiler.maptilersdk.map.style.layer.MTLayerVisibility |
| 12 | +import kotlinx.serialization.SerialName |
| 13 | +import kotlinx.serialization.Serializable |
| 14 | + |
| 15 | +/** |
| 16 | + * The raster style layer that renders raster map textures such as satellite imagery. |
| 17 | + * |
| 18 | + * Supports paint properties like brightness, contrast, fade duration, hue rotation, |
| 19 | + * opacity, resampling and saturation, and a layout visibility flag. |
| 20 | + */ |
| 21 | +@Serializable |
| 22 | +class MTRasterLayer : MTLayer { |
| 23 | + /** |
| 24 | + * Unique layer identifier. |
| 25 | + */ |
| 26 | + @SerialName("id") |
| 27 | + override var identifier: String |
| 28 | + |
| 29 | + /** |
| 30 | + * Type of the layer. |
| 31 | + */ |
| 32 | + override var type: MTLayerType = MTLayerType.RASTER |
| 33 | + private set |
| 34 | + |
| 35 | + /** |
| 36 | + * Identifier of the source to be used for this layer. |
| 37 | + */ |
| 38 | + @SerialName("source") |
| 39 | + override var sourceIdentifier: String |
| 40 | + |
| 41 | + /** |
| 42 | + * The maximum zoom level for the layer. |
| 43 | + * Optional number between 0 and 24. At zoom levels equal to or greater than the maxzoom, |
| 44 | + * the layer will be hidden. |
| 45 | + */ |
| 46 | + @SerialName("maxzoom") |
| 47 | + override var maxZoom: Double? = null |
| 48 | + |
| 49 | + /** |
| 50 | + * The minimum zoom level for the layer. |
| 51 | + * Optional number between 0 and 24. At zoom levels less than the minzoom, |
| 52 | + * the layer will be hidden. |
| 53 | + */ |
| 54 | + @SerialName("minzoom") |
| 55 | + override var minZoom: Double? = null |
| 56 | + |
| 57 | + /** |
| 58 | + * Layer to use from a vector tile source. Not used for raster sources. |
| 59 | + */ |
| 60 | + @SerialName("source-layer") |
| 61 | + override var sourceLayer: String? = null |
| 62 | + |
| 63 | + /** |
| 64 | + * Increase or reduce the brightness of the image. The value is the maximum brightness. |
| 65 | + * Optional number between 0 and 1 inclusive. Defaults to 1. |
| 66 | + */ |
| 67 | + var brightnessMax: Double? |
| 68 | + get() = _paint.brightnessMax ?: 1.0 |
| 69 | + set(value) { |
| 70 | + _paint.brightnessMax = value |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Increase or reduce the brightness of the image. The value is the minimum brightness. |
| 75 | + * Optional number between 0 and 1 inclusive. Defaults to 0. |
| 76 | + */ |
| 77 | + var brightnessMin: Double? |
| 78 | + get() = _paint.brightnessMin ?: 0.0 |
| 79 | + set(value) { |
| 80 | + _paint.brightnessMin = value |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Increase or reduce the contrast of the image. |
| 85 | + * Optional number between -1 and 1 inclusive. Defaults to 0. |
| 86 | + */ |
| 87 | + var contrast: Double? |
| 88 | + get() = _paint.contrast ?: 0.0 |
| 89 | + set(value) { |
| 90 | + _paint.contrast = value |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Fade duration when a new tile is added. |
| 95 | + * Optional number greater than or equal to 0. Units in milliseconds. Defaults to 300. |
| 96 | + */ |
| 97 | + var fadeDuration: Double? |
| 98 | + get() = _paint.fadeDuration ?: 300.0 |
| 99 | + set(value) { |
| 100 | + _paint.fadeDuration = value |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Rotates hues around the color wheel. Units in degrees. Defaults to 0. |
| 105 | + */ |
| 106 | + var hueRotate: Double? |
| 107 | + get() = _paint.hueRotate ?: 0.0 |
| 108 | + set(value) { |
| 109 | + _paint.hueRotate = value |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * The opacity at which the image will be drawn. Optional number between 0 and 1 inclusive. Defaults to 1. |
| 114 | + */ |
| 115 | + var opacity: Double? |
| 116 | + get() = _paint.opacity ?: 1.0 |
| 117 | + set(value) { |
| 118 | + _paint.opacity = value |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * The resampling/interpolation method to use for overscaling. Defaults to LINEAR. |
| 123 | + */ |
| 124 | + var resampling: MTRasterResampling? |
| 125 | + get() = _paint.resampling ?: MTRasterResampling.LINEAR |
| 126 | + set(value) { |
| 127 | + _paint.resampling = value |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Increase or reduce the saturation of the image. Optional number between -1 and 1 inclusive. Defaults to 0. |
| 132 | + */ |
| 133 | + var saturation: Double? |
| 134 | + get() = _paint.saturation ?: 0.0 |
| 135 | + set(value) { |
| 136 | + _paint.saturation = value |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * Enum controlling whether this layer is displayed. |
| 141 | + */ |
| 142 | + var visibility: MTLayerVisibility |
| 143 | + get() = MTLayerVisibility.from(_layout.visibility) ?: MTLayerVisibility.VISIBLE |
| 144 | + set(value) { |
| 145 | + _layout.visibility = value |
| 146 | + } |
| 147 | + |
| 148 | + @Suppress("PropertyName") |
| 149 | + @SerialName("layout") |
| 150 | + private var _layout: MTRasterLayout = MTRasterLayout() |
| 151 | + |
| 152 | + @Suppress("PropertyName") |
| 153 | + @SerialName("paint") |
| 154 | + private var _paint: MTRasterPaint = MTRasterPaint() |
| 155 | + |
| 156 | + constructor( |
| 157 | + identifier: String, |
| 158 | + sourceIdentifier: String, |
| 159 | + ) { |
| 160 | + this.identifier = identifier |
| 161 | + this.sourceIdentifier = sourceIdentifier |
| 162 | + |
| 163 | + this._layout = MTRasterLayout(visibility = visibility) |
| 164 | + this._paint = |
| 165 | + MTRasterPaint( |
| 166 | + brightnessMax = brightnessMax, |
| 167 | + brightnessMin = brightnessMin, |
| 168 | + contrast = contrast, |
| 169 | + fadeDuration = fadeDuration, |
| 170 | + hueRotate = hueRotate, |
| 171 | + opacity = opacity, |
| 172 | + resampling = resampling, |
| 173 | + saturation = saturation, |
| 174 | + ) |
| 175 | + } |
| 176 | + |
| 177 | + constructor( |
| 178 | + identifier: String, |
| 179 | + sourceIdentifier: String, |
| 180 | + maxZoom: Double, |
| 181 | + minZoom: Double, |
| 182 | + sourceLayer: String, |
| 183 | + ) { |
| 184 | + this.identifier = identifier |
| 185 | + this.sourceIdentifier = sourceIdentifier |
| 186 | + this.maxZoom = maxZoom |
| 187 | + this.minZoom = minZoom |
| 188 | + this.sourceLayer = sourceLayer |
| 189 | + |
| 190 | + this._layout = MTRasterLayout(visibility = visibility) |
| 191 | + this._paint = |
| 192 | + MTRasterPaint( |
| 193 | + brightnessMax = brightnessMax, |
| 194 | + brightnessMin = brightnessMin, |
| 195 | + contrast = contrast, |
| 196 | + fadeDuration = fadeDuration, |
| 197 | + hueRotate = hueRotate, |
| 198 | + opacity = opacity, |
| 199 | + resampling = resampling, |
| 200 | + saturation = saturation, |
| 201 | + ) |
| 202 | + } |
| 203 | + |
| 204 | + constructor( |
| 205 | + identifier: String, |
| 206 | + type: MTLayerType, |
| 207 | + sourceIdentifier: String, |
| 208 | + maxZoom: Double?, |
| 209 | + minZoom: Double?, |
| 210 | + sourceLayer: String?, |
| 211 | + brightnessMax: Double?, |
| 212 | + brightnessMin: Double?, |
| 213 | + contrast: Double?, |
| 214 | + fadeDuration: Double?, |
| 215 | + hueRotate: Double?, |
| 216 | + opacity: Double?, |
| 217 | + resampling: MTRasterResampling?, |
| 218 | + saturation: Double?, |
| 219 | + visibility: MTLayerVisibility, |
| 220 | + ) { |
| 221 | + this.identifier = identifier |
| 222 | + this.type = type |
| 223 | + this.sourceIdentifier = sourceIdentifier |
| 224 | + this.maxZoom = maxZoom |
| 225 | + this.minZoom = minZoom |
| 226 | + this.sourceLayer = sourceLayer |
| 227 | + this.brightnessMax = brightnessMax |
| 228 | + this.brightnessMin = brightnessMin |
| 229 | + this.contrast = contrast |
| 230 | + this.fadeDuration = fadeDuration |
| 231 | + this.hueRotate = hueRotate |
| 232 | + this.opacity = opacity |
| 233 | + this.resampling = resampling |
| 234 | + this.saturation = saturation |
| 235 | + this.visibility = visibility |
| 236 | + |
| 237 | + this._layout = |
| 238 | + MTRasterLayout( |
| 239 | + visibility = visibility, |
| 240 | + ) |
| 241 | + this._paint = |
| 242 | + MTRasterPaint( |
| 243 | + brightnessMax = brightnessMax, |
| 244 | + brightnessMin = brightnessMin, |
| 245 | + contrast = contrast, |
| 246 | + fadeDuration = fadeDuration, |
| 247 | + hueRotate = hueRotate, |
| 248 | + opacity = opacity, |
| 249 | + resampling = resampling, |
| 250 | + saturation = saturation, |
| 251 | + ) |
| 252 | + } |
| 253 | +} |
| 254 | + |
| 255 | +@Serializable |
| 256 | +internal data class MTRasterLayout( |
| 257 | + var visibility: MTLayerVisibility = MTLayerVisibility.VISIBLE, |
| 258 | +) |
| 259 | + |
| 260 | +@Serializable |
| 261 | +internal data class MTRasterPaint( |
| 262 | + @SerialName("raster-brightness-max") |
| 263 | + var brightnessMax: Double? = 1.0, |
| 264 | + @SerialName("raster-brightness-min") |
| 265 | + var brightnessMin: Double? = 0.0, |
| 266 | + @SerialName("raster-contrast") |
| 267 | + var contrast: Double? = 0.0, |
| 268 | + @SerialName("raster-fade-duration") |
| 269 | + var fadeDuration: Double? = 300.0, |
| 270 | + @SerialName("raster-hue-rotate") |
| 271 | + var hueRotate: Double? = 0.0, |
| 272 | + @SerialName("raster-opacity") |
| 273 | + var opacity: Double? = 1.0, |
| 274 | + @SerialName("raster-resampling") |
| 275 | + var resampling: MTRasterResampling? = MTRasterResampling.LINEAR, |
| 276 | + @SerialName("raster-saturation") |
| 277 | + var saturation: Double? = 0.0, |
| 278 | +) |
| 279 | + |
| 280 | +/** |
| 281 | + * The resampling/interpolation method to use for overscaling, also known as texture magnification filter. |
| 282 | + */ |
| 283 | +@Serializable |
| 284 | +enum class MTRasterResampling { |
| 285 | + @SerialName("linear") |
| 286 | + LINEAR, |
| 287 | + |
| 288 | + @SerialName("nearest") |
| 289 | + NEAREST, |
| 290 | +} |
0 commit comments