Render multilayer symbols

View on GitHubSample viewer app

Show different kinds of multilayer symbols on a map.

Image of render multilayer symbols

Use case

Allows you to customize a graphic with a multilayer symbol. For example, you may want more customizable symbols than those that are provided with the API to display a unique representation of a landmark.

How to use the sample

The sample loads with multilayer symbols displayed for points, polylines, and polygons.

How it works

  1. Create multilayer symbols for each predefined 2D simple symbol style.
    • For multilayer point symbols, use the MultilayerPointSymbol constructor.
    • For multilayer polyline symbols, use the MultilayerPolylineSymbol constructor.
    • For multilayer polygon symbols, use the MultilayerPolygonSymbol constructor.
  2. Create Graphics by passing in a Geometry and the associated multilayer symbol.
  3. Add graphics to the graphics overlay with graphicsOverlay.getGraphics.add(graphic)

Relevant API

  • Graphic
  • GraphicsOverlay
  • MultilayerPointSymbol
  • MultilayerPolygonSymbol
  • MultilayerPolylineSymbol
  • PictureMarkerSymbolLayer
  • SolidFillSymbolLayer
  • SolidStrokeSymbolLayer
  • VectorMarkerSymbolLayer

Tags

graphic, marker, multilayer, picture, symbol

Sample Code

MainActivity.kt
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
/* Copyright 2022 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.rendermultilayersymbols

import android.graphics.BitmapFactory
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.lifecycleScope
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.Color
import com.arcgismaps.geometry.Envelope
import com.arcgismaps.geometry.Geometry
import com.arcgismaps.geometry.Point
import com.arcgismaps.geometry.PolygonBuilder
import com.arcgismaps.geometry.PolylineBuilder
import com.arcgismaps.geometry.SpatialReference
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.symbology.DashGeometricEffect
import com.arcgismaps.mapping.symbology.HatchFillSymbolLayer
import com.arcgismaps.mapping.symbology.HorizontalAlignment
import com.arcgismaps.mapping.symbology.MultilayerPointSymbol
import com.arcgismaps.mapping.symbology.MultilayerPolygonSymbol
import com.arcgismaps.mapping.symbology.MultilayerPolylineSymbol
import com.arcgismaps.mapping.symbology.MultilayerSymbol
import com.arcgismaps.mapping.symbology.PictureMarkerSymbolLayer
import com.arcgismaps.mapping.symbology.SolidFillSymbolLayer
import com.arcgismaps.mapping.symbology.SolidStrokeSymbolLayer
import com.arcgismaps.mapping.symbology.StrokeSymbolLayerCapStyle
import com.arcgismaps.mapping.symbology.SymbolAnchor
import com.arcgismaps.mapping.symbology.SymbolAnchorPlacementMode
import com.arcgismaps.mapping.symbology.SymbolLayer
import com.arcgismaps.mapping.symbology.TextSymbol
import com.arcgismaps.mapping.symbology.VectorMarkerSymbolElement
import com.arcgismaps.mapping.symbology.VectorMarkerSymbolLayer
import com.arcgismaps.mapping.symbology.VerticalAlignment
import com.arcgismaps.mapping.view.Graphic
import com.arcgismaps.mapping.view.GraphicsOverlay
import com.esri.arcgismaps.sample.rendermultilayersymbols.databinding.ActivityMainBinding
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.launch

private val Color.Companion.blue: Color
    get() {
        return fromRgba(0, 0, 255, 255)
    }

private val Color.Companion.yellow: Color
    get() {
        return fromRgba(255, 255, 0, 255)
    }

private val Color.Companion.magenta: Color
    get() {
        return fromRgba(255, 0, 255, 255)
    }

// define offset used to keep a consistent distance between symbols in the same column
private const val OFFSET = 20.0

class MainActivity : AppCompatActivity() {

    // set up data binding for the activity
    private val activityMainBinding: ActivityMainBinding by lazy {
        DataBindingUtil.setContentView(this, R.layout.activity_main)
    }

    private val mapView by lazy {
        activityMainBinding.mapView
    }

    // define the graphics overlay to add the multilayer symbols
    private var graphicsOverlay: GraphicsOverlay = GraphicsOverlay()

    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.API_KEY)
        lifecycle.addObserver(mapView)

        mapView.apply {
            // set the map to be displayed in the layout's map view
            mapView.map = ArcGISMap(BasemapStyle.ArcGISLightGray)
            // add the graphic overlay to the map view
            graphicsOverlays.add(graphicsOverlay)
        }

        // create labels to go above each category of graphic
        addTextGraphics()

        // create picture marker symbols, from URI or local cache
        addImageGraphics()

        // add graphics with simple vector marker symbol elements (MultilayerPoint Simple Markers on app UI)
        val solidFillSymbolLayer = SolidFillSymbolLayer(Color.red)
        val multilayerPolygonSymbol = MultilayerPolygonSymbol(listOf(solidFillSymbolLayer))
        val solidStrokeSymbolLayer =
            SolidStrokeSymbolLayer(1.0, Color.red, listOf(DashGeometricEffect()))
        val multilayerPolylineSymbol = MultilayerPolylineSymbol(listOf(solidStrokeSymbolLayer))

        // define vector element for a diamond, triangle and cross
        val diamondGeometry =
            Geometry.fromJsonOrNull("{\"rings\":[[[0.0,2.5],[2.5,0.0],[0.0,-2.5],[-2.5,0.0],[0.0,2.5]]]}")
        val triangleGeometry =
            Geometry.fromJsonOrNull("{\"rings\":[[[0.0,5.0],[5,-5.0],[-5,-5.0],[0.0,5.0]]]}")
        val crossGeometry =
            Geometry.fromJsonOrNull("{\"paths\":[[[-1,1],[0,0],[1,-1]],[[1,1],[0,0],[-1,-1]]]}")

        if (diamondGeometry == null || triangleGeometry == null || crossGeometry == null) {
            showError("Error reading geometry from json")
            return
        }

        // add red diamond graphic
        addGraphicsWithVectorMarkerSymbolElements(
            multilayerPolygonSymbol, diamondGeometry, 0.0
        )
        // add red triangle graphic
        addGraphicsWithVectorMarkerSymbolElements(
            multilayerPolygonSymbol, triangleGeometry, OFFSET
        )
        // add red cross graphic
        addGraphicsWithVectorMarkerSymbolElements(
            multilayerPolylineSymbol, crossGeometry, 2 * OFFSET
        )

        // create line marker symbols with short dash dot dot
        addLineGraphicsWithMarkerSymbols(
            listOf(4.0, 6.0, 0.5, 6.0, 0.5, 6.0), 0.0
        )
        // create line marker symbol with short dash
        addLineGraphicsWithMarkerSymbols(
            listOf(4.0, 6.0), OFFSET
        )
        // create line marker symbol with dash dot dot
        addLineGraphicsWithMarkerSymbols(
            listOf(7.0, 9.0, 0.5, 9.0), 2 * OFFSET
        )

        // create polygon marker symbols
        // cross-hatched diagonal lines
        addPolygonGraphicsWithMarkerSymbols(
            listOf(-45.0, 45.0), 0.0
        )
        // hatched diagonal lines
        addPolygonGraphicsWithMarkerSymbols(
            listOf(-45.0), OFFSET
        )
        // hatched vertical lines
        addPolygonGraphicsWithMarkerSymbols(
            listOf(90.0), 2 * OFFSET
        )

        // define vector element for a hexagon which will be used as the basis of a complex point
        val complexPointGeometry =
            Geometry.fromJsonOrNull("{\"rings\":[[[-2.89,5.0],[2.89,5.0],[5.77,0.0],[2.89,-5.0],[-2.89,-5.0],[-5.77,0.0],[-2.89,5.0]]]}")

        // create the more complex multilayer graphics: a point, polygon, and polyline
        complexPointGeometry?.let { addComplexPoint(it) }
        addComplexPolygon()
        addComplexPolyline()
    }

    /**
     * Creates the label graphics to be displayed above each category of symbol,
     * and adds them to the graphics overlay.
     */
    private fun addTextGraphics() {
        graphicsOverlay.graphics.addAll(
            listOf(
                Graphic(
                    Point(-150.0, 50.0, SpatialReference.wgs84()),
                    getTextSymbol("MultilayerPoint\nSimple Markers")
                ), Graphic(
                    Point(-80.0, 50.0, SpatialReference.wgs84()),
                    getTextSymbol("MultilayerPoint\nPicture Markers")
                ), Graphic(
                    Point(0.0, 50.0, SpatialReference.wgs84()),
                    getTextSymbol("Multilayer\nPolyline")
                ), Graphic(
                    Point(65.0, 50.0, SpatialReference.wgs84()),
                    getTextSymbol("Multilayer\nPolygon")
                ), Graphic(
                    Point(130.0, 50.0, SpatialReference.wgs84()),
                    getTextSymbol("Multilayer\nComplex Symbols")
                )
            )
        )
    }

    /**
     * @return the TextSymbol with the [text] to be displayed on the map.
     */
    private fun getTextSymbol(text: String): TextSymbol {
        val textSymbol = TextSymbol(
            text, Color.black, 10F, HorizontalAlignment.Center, VerticalAlignment.Middle
        )
        // give the text symbol a white background
        textSymbol.backgroundColor = Color.white
        return textSymbol
    }

    /**
     * Create picture marker symbols from online URI and local cache.
     */
    private fun addImageGraphics() {
        // URI of image to display
        val blueTentImageURI = "https://static.arcgis.com/images/Symbols/OutdoorRecreation/Camping.png"
        // load the PictureMarkerSymbolLayer using the image URI
        val pictureMarkerFromUri = PictureMarkerSymbolLayer(blueTentImageURI)
        // add loaded layer to the map
        addGraphicFromPictureMarkerSymbolLayer(pictureMarkerFromUri, 0.0)
        // load blue pin from as a bitmap
        val bitmap = BitmapFactory.decodeResource(resources, R.drawable.blue_pin)
        // load the PictureMarkerSymbolLayer using the bitmap drawable
        val pictureMarkerFromCache = PictureMarkerSymbolLayer.createWithImage(BitmapDrawable(resources, bitmap))
        // add loaded layer to the map
        addGraphicFromPictureMarkerSymbolLayer(pictureMarkerFromCache, 40.0)
    }

    /**
     * Loads a picture marker symbol layer and after it has loaded, creates a new multilayer point symbol from it.
     * A graphic is created from the multilayer point symbol and added to the graphics overlay.
     *
     * The [pictureMarkerSymbolLayer] to be loaded.
     * The [offset] value used to keep a consistent distance between symbols in the same column.
     */
    private fun addGraphicFromPictureMarkerSymbolLayer(
        pictureMarkerSymbolLayer: PictureMarkerSymbolLayer, offset: Double
    ) = lifecycleScope.launch {
        // wait for the picture marker symbol layer to load and check it has loaded
        pictureMarkerSymbolLayer.load().getOrElse {
            showError("Picture marker symbol layer failed to load: ${it.message}")
        }
        // set the size of the layer and create a new multilayer point symbol from it
        pictureMarkerSymbolLayer.size = 40.0
        val multilayerPointSymbol = MultilayerPointSymbol(listOf(pictureMarkerSymbolLayer))
        // create location for the symbol
        val point = Point(-80.0, 20.0 - offset, SpatialReference.wgs84())

        // create graphic with the location and symbol and add it to the graphics overlay
        val graphic = Graphic(point, multilayerPointSymbol)
        graphicsOverlay.graphics.add(graphic)
    }

    /**
     * Adds new graphics constructed from multilayer point symbols.
     *
     * The [multilayerSymbol] to construct the vector marker symbol element with.
     * The input [geometry] for the vector marker symbol element.
     * [offset] the value used to keep a consistent distance between symbols in the same column.
     */
    private fun addGraphicsWithVectorMarkerSymbolElements(
        multilayerSymbol: MultilayerSymbol, geometry: Geometry, offset: Double
    ) {
        // define a vector element and create a new multilayer point symbol from it
        val vectorMarkerSymbolElement = VectorMarkerSymbolElement(geometry, multilayerSymbol)
        val vectorMarkerSymbolLayer = VectorMarkerSymbolLayer(listOf(vectorMarkerSymbolElement))
        val multilayerPointSymbol = MultilayerPointSymbol(listOf(vectorMarkerSymbolLayer))

        // create point graphic using the symbol and add it to the graphics overlay
        val graphic =
            Graphic(Point(-150.0, 20 - offset, SpatialReference.wgs84()), multilayerPointSymbol)
        graphicsOverlay.graphics.add(graphic)
    }

    /**
     * Adds new graphics constructed from multilayer polyline symbols.
     *
     * The pattern of [dashSpacing] dots/dashes used by the line and
     * [offset] the value used to keep a consistent distance between symbols in the same column.
     */
    private fun addLineGraphicsWithMarkerSymbols(dashSpacing: List<Double>, offset: Double) {
        // create a dash effect from the provided values
        val dashGeometricEffect = DashGeometricEffect(dashSpacing)
        // create stroke used by line symbols
        val solidStrokeSymbolLayer = SolidStrokeSymbolLayer(
            3.0, Color.red, listOf(dashGeometricEffect)
        ).apply {
            capStyle = StrokeSymbolLayerCapStyle.Round
        }
        // create a polyline for the multilayer polyline symbol
        val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
            addPoint(Point(-30.0, 20 - offset))
            addPoint(Point(30.0, 20 - offset))
        }
        // create a multilayer polyline symbol from the solidStrokeSymbolLayer
        val multilayerPolylineSymbol = MultilayerPolylineSymbol(listOf(solidStrokeSymbolLayer))
        // create a polyline graphic with geometry using the symbol created above, and add it to the graphics overlay
        graphicsOverlay.graphics.add(
            Graphic(
                polylineBuilder.toGeometry(), multilayerPolylineSymbol
            )
        )
    }

    /**
     * Adds new graphics constructed from multilayer polygon symbols.
     *
     * Takes a list containing the [angles] at which to draw fill lines within the polygon and
     * [offset] the value used to keep a consistent distance between symbols in the same column.
     */
    private fun addPolygonGraphicsWithMarkerSymbols(angles: List<Double>, offset: Double) {
        val polygonBuilder = PolygonBuilder(SpatialReference.wgs84()) {
            addPoint(Point(60.0, 25 - offset))
            addPoint(Point(70.0, 25 - offset))
            addPoint(Point(70.0, 20 - offset))
            addPoint(Point(60.0, 20 - offset))
        }

        // create a stroke symbol layer to be used by patterns
        val strokeForHatches = SolidStrokeSymbolLayer(2.0, Color.red, listOf(DashGeometricEffect()))

        // create a stroke symbol layer to be used as an outline for aforementioned patterns
        val strokeForOutline =
            SolidStrokeSymbolLayer(1.0, Color.black, listOf(DashGeometricEffect()))

        // create a list to hold all necessary symbol layers - at least one for patterns and one for an outline at the end
        val symbolLayerList = mutableListOf<SymbolLayer>()

        // for each angle, create a symbol layer using the pattern stroke, with hatched lines at the given angle
        for (i in angles.indices) {
            val hatchFillSymbolLayer = HatchFillSymbolLayer(
                MultilayerPolylineSymbol(listOf(strokeForHatches)), angles[i]
            )
            // define separation distance for lines and add them to the symbol layer list
            hatchFillSymbolLayer.separation = 9.0
            symbolLayerList.add(hatchFillSymbolLayer)
        }

        // assign the outline layer to the last element of the symbol layer list
        symbolLayerList.add(strokeForOutline)
        // create a multilayer polygon symbol from the symbol layer list
        val multilayerPolygonSymbol =
            MultilayerPolygonSymbol(symbolLayerList)
        // create a polygon graphic with geometry using the symbol created above, and add it to the graphics overlay
        val graphic = Graphic(polygonBuilder.toGeometry(), multilayerPolygonSymbol)
        graphicsOverlay.graphics.add(graphic)
    }

    /**
     * Creates a complex point from multiple symbol layers and a provided geometry.
     * @param complexPointGeometry a base geometry upon which other symbol layers are drawn.
     */
    private fun addComplexPoint(complexPointGeometry: Geometry) {
        // create marker layers for complex point
        val orangeSquareVectorMarkerLayer: VectorMarkerSymbolLayer =
            getLayerForComplexPoint(Color.cyan, Color.blue, 11.0)
        val blackSquareVectorMarkerLayer: VectorMarkerSymbolLayer =
            getLayerForComplexPoint(Color.black, Color.cyan, 6.0)
        val purpleSquareVectorMarkerLayer: VectorMarkerSymbolLayer = getLayerForComplexPoint(
            Color.transparent, Color.magenta, 14.0
        )

        // set anchors for marker layers
        orangeSquareVectorMarkerLayer.anchor =
            SymbolAnchor(-4.0, -6.0, SymbolAnchorPlacementMode.Absolute)
        blackSquareVectorMarkerLayer.anchor =
            SymbolAnchor(2.0, 1.0, SymbolAnchorPlacementMode.Absolute)
        purpleSquareVectorMarkerLayer.anchor =
            SymbolAnchor(4.0, 2.0, SymbolAnchorPlacementMode.Absolute)

        // create a yellow hexagon with a black outline
        val yellowFillLayer = SolidFillSymbolLayer(Color.yellow)
        val blackOutline = SolidStrokeSymbolLayer(2.0, Color.black, listOf(DashGeometricEffect()))
        val hexagonVectorElement = VectorMarkerSymbolElement(
            complexPointGeometry, MultilayerPolylineSymbol(listOf(yellowFillLayer, blackOutline))
        )
        val hexagonVectorMarkerLayer = VectorMarkerSymbolLayer(listOf(hexagonVectorElement)).apply {
            size = 35.0
        }

        // create the multilayer point symbol
        val multilayerPointSymbol = MultilayerPointSymbol(
            listOf(
                hexagonVectorMarkerLayer,
                orangeSquareVectorMarkerLayer,
                blackSquareVectorMarkerLayer,
                purpleSquareVectorMarkerLayer
            )
        )

        // create the multilayer point graphic using the symbols created above
        val complexPointGraphic =
            Graphic(Point(130.0, 20.0, SpatialReference.wgs84()), multilayerPointSymbol)
        graphicsOverlay.graphics.add(complexPointGraphic)
    }

    /**
     * Creates a symbol layer for use in the composition of a complex point
     * using [fillColor], [outlineColor] as colors and the [size] of the symbol
     * Then return a [VectorMarkerSymbolLayer] of the created symbol.
     */
    private fun getLayerForComplexPoint(
        fillColor: Color, outlineColor: Color, size: Double
    ): VectorMarkerSymbolLayer {
        // create the fill layer and outline
        val fillLayer = SolidFillSymbolLayer(fillColor)
        val outline = SolidStrokeSymbolLayer(
            2.0, outlineColor, listOf(DashGeometricEffect())
        )
        // create a geometry from an envelope
        val geometry = Envelope(
            Point(-0.5, -0.5, SpatialReference.wgs84()), Point(0.5, 0.5, SpatialReference.wgs84())
        )
        //create a symbol element using the geometry, fill layer, and outline
        val vectorMarkerSymbolElement = VectorMarkerSymbolElement(
            geometry, MultilayerPolygonSymbol(listOf(fillLayer, outline))
        )
        // create a symbol layer containing just the above symbol element, set its size, and return it
        val vectorMarkerSymbolLayer =
            VectorMarkerSymbolLayer(listOf(vectorMarkerSymbolElement)).apply {
                this.size = size
            }
        return vectorMarkerSymbolLayer
    }

    /**
     * Adds a complex polygon generated with multiple symbol layers.
     */
    private fun addComplexPolygon() {
        // create the multilayer polygon symbol
        val multilayerPolygonSymbol = MultilayerPolygonSymbol(getLayersForComplexPolys(true))
        // create the polygon
        val polygonBuilder = PolygonBuilder(SpatialReference.wgs84()) {
            addPoint(Point(120.0, 0.0))
            addPoint(Point(140.0, 0.0))
            addPoint(Point(140.0, -10.0))
            addPoint(Point(120.0, -10.0))
        }
        // create a multilayer polygon graphic with geometry using the symbols
        // created above and add it to the graphics overlay
        graphicsOverlay.graphics.add(
            Graphic(
                polygonBuilder.toGeometry(), multilayerPolygonSymbol
            )
        )
    }

    /**
     * Adds a complex polyline generated with multiple symbol layers.
     */
    private fun addComplexPolyline() {
        // create the multilayer polyline symbol
        val multilayerPolylineSymbol = MultilayerPolylineSymbol(getLayersForComplexPolys(false))
        val polylineBuilder = PolylineBuilder(SpatialReference.wgs84()) {
            addPoint(Point(120.0, -25.0))
            addPoint(Point(140.0, -25.0))
        }
        // create the multilayer polyline graphic with geometry using the symbols created above and add it to the graphics overlay
        graphicsOverlay.graphics.add(
            Graphic(
                polylineBuilder.toGeometry(), multilayerPolylineSymbol
            )
        )
    }

    /**
     * Generates and returns the symbol layers used by the addComplexPolygon and addComplexPolyline methods.
     * [includeRedFill] indicates whether to include the red fill needed by the complex polygon.
     * @return a list of symbol layers including the necessary effects.
     */
    private fun getLayersForComplexPolys(includeRedFill: Boolean): List<SymbolLayer> {
        // create a black dash effect
        val blackDashes = SolidStrokeSymbolLayer(
            1.0, Color.black, listOf(DashGeometricEffect(listOf(5.0, 3.0)))
        ).apply {
            capStyle = StrokeSymbolLayerCapStyle.Square
        }

        // create a black outline
        val blackOutline = SolidStrokeSymbolLayer(
            7.0, Color.black, listOf(DashGeometricEffect())
        ).apply {
            capStyle = StrokeSymbolLayerCapStyle.Round
        }

        // create a yellow stroke inside
        val yellowStroke = SolidStrokeSymbolLayer(
            5.0, Color.yellow, listOf(DashGeometricEffect())
        ).apply {
            capStyle = StrokeSymbolLayerCapStyle.Round
        }

        return if (includeRedFill) {
            // create a red filling for the polygon
            val redFillLayer = SolidFillSymbolLayer(Color.red)
            listOf(redFillLayer, blackOutline, yellowStroke, blackDashes)
        } else {
            listOf(blackOutline, yellowStroke, blackDashes)
        }
    }

    private fun showError(message: String) {
        Log.e(localClassName, message)
        Snackbar.make(mapView, message, Snackbar.LENGTH_SHORT).show()
    }
}

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