@@ -57,15 +57,34 @@ import com.arcgismaps.mapping.view.GraphicsOverlay
5757import com.esri.arcgismaps.sample.rendermultilayersymbols.databinding.ActivityMainBinding
5858import com.google.android.material.snackbar.Snackbar
5959import kotlinx.coroutines.launch
60- import java.io.File
61- import java.io.FileOutputStream
62- import java.io.OutputStream
6360
61+ private val Color .Companion .blue: Color
62+ get() {
63+ return fromRgba(0 , 0 , 255 , 255 )
64+ }
65+
66+ private val Color .Companion .yellow: Color
67+ get() {
68+ return fromRgba(255 , 255 , 0 , 255 )
69+ }
70+
71+ private val Color .Companion .magenta: Color
72+ get() {
73+ return fromRgba(255 , 0 , 255 , 255 )
74+ }
75+
76+ private val Color .Companion .cyan: Color
77+ get() {
78+ return fromRgba(0 , 100 , 100 , 255 )
79+ }
6480
6581class MainActivity : AppCompatActivity () {
6682
6783 private val TAG = MainActivity ::class .java.simpleName
6884
85+ // define offset used to keep a consistent distance between symbols in the same column
86+ private val OFFSET = 20.0
87+
6988 // set up data binding for the activity
7089 private val activityMainBinding: ActivityMainBinding by lazy {
7190 DataBindingUtil .setContentView(this , R .layout.activity_main)
@@ -78,10 +97,6 @@ class MainActivity : AppCompatActivity() {
7897 // define the graphics overlay to add the multilayer symbols
7998 private var graphicsOverlay: GraphicsOverlay = GraphicsOverlay ()
8099
81- // define offset used to keep a consistent distance between symbols in the same column
82- private val offset = 20.0
83-
84-
85100 override fun onCreate (savedInstanceState : Bundle ? ) {
86101 super .onCreate(savedInstanceState)
87102
@@ -129,11 +144,11 @@ class MainActivity : AppCompatActivity() {
129144 )
130145 // add red triangle graphic
131146 addGraphicsWithVectorMarkerSymbolElements(
132- multilayerPolygonSymbol, triangleGeometry, offset
147+ multilayerPolygonSymbol, triangleGeometry, OFFSET
133148 )
134149 // add red cross graphic
135150 addGraphicsWithVectorMarkerSymbolElements(
136- multilayerPolylineSymbol, crossGeometry, 2 * offset
151+ multilayerPolylineSymbol, crossGeometry, 2 * OFFSET
137152 )
138153
139154 // create line marker symbols with short dash dot dot
@@ -142,11 +157,11 @@ class MainActivity : AppCompatActivity() {
142157 )
143158 // create line marker symbol with short dash
144159 addLineGraphicsWithMarkerSymbols(
145- listOf (4.0 , 6.0 ), offset
160+ listOf (4.0 , 6.0 ), OFFSET
146161 )
147162 // create line marker symbol with dash dot dot
148163 addLineGraphicsWithMarkerSymbols(
149- listOf (7.0 , 9.0 , 0.5 , 9.0 ), 2 * offset
164+ listOf (7.0 , 9.0 , 0.5 , 9.0 ), 2 * OFFSET
150165 )
151166
152167 // create polygon marker symbols
@@ -156,11 +171,11 @@ class MainActivity : AppCompatActivity() {
156171 )
157172 // hatched diagonal lines
158173 addPolygonGraphicsWithMarkerSymbols(
159- listOf (- 45.0 ), offset
174+ listOf (- 45.0 ), OFFSET
160175 )
161176 // hatched vertical lines
162177 addPolygonGraphicsWithMarkerSymbols(
163- listOf (90.0 ), 2 * offset
178+ listOf (90.0 ), 2 * OFFSET
164179 )
165180
166181 // define vector element for a hexagon which will be used as the basis of a complex point
@@ -213,7 +228,7 @@ class MainActivity : AppCompatActivity() {
213228 }
214229
215230 /* *
216- * Create picture marker symbols from online URI or local cache.
231+ * Create picture marker symbols from online URI and local cache.
217232 */
218233 private fun addImageGraphics () {
219234 // URI of image to display
@@ -305,7 +320,7 @@ class MainActivity : AppCompatActivity() {
305320 capStyle = StrokeSymbolLayerCapStyle .Round
306321 }
307322 // create a polyline for the multilayer polyline symbol
308- val polylineBuilder = PolylineBuilder (SpatialReference .wgs84()). apply {
323+ val polylineBuilder = PolylineBuilder (SpatialReference .wgs84()) {
309324 addPoint(Point (- 30.0 , 20 - offset))
310325 addPoint(Point (30.0 , 20 - offset))
311326 }
@@ -322,11 +337,11 @@ class MainActivity : AppCompatActivity() {
322337 /* *
323338 * Adds new graphics constructed from multilayer polygon symbols.
324339 *
325- * A list containing the [angles] at which to draw fill lines within the polygon and
340+ * Takes a list containing the [angles] at which to draw fill lines within the polygon and
326341 * [offset] the value used to keep a consistent distance between symbols in the same column.
327342 */
328343 private fun addPolygonGraphicsWithMarkerSymbols (angles : List <Double >, offset : Double ) {
329- val polygonBuilder = PolygonBuilder (SpatialReference .wgs84()). apply {
344+ val polygonBuilder = PolygonBuilder (SpatialReference .wgs84()) {
330345 addPoint(Point (60.0 , 25 - offset))
331346 addPoint(Point (70.0 , 25 - offset))
332347 addPoint(Point (70.0 , 20 - offset))
@@ -340,24 +355,24 @@ class MainActivity : AppCompatActivity() {
340355 val strokeForOutline =
341356 SolidStrokeSymbolLayer (1.0 , Color .black, listOf (DashGeometricEffect ()))
342357
343- // create an array to hold all necessary symbol layers - at least one for patterns and one for an outline at the end
344- val symbolLayerArray = arrayOfNulls <SymbolLayer >(angles.size + 1 )
358+ // create a list to hold all necessary symbol layers - at least one for patterns and one for an outline at the end
359+ val symbolLayerList = mutableListOf <SymbolLayer >()
345360
346361 // for each angle, create a symbol layer using the pattern stroke, with hatched lines at the given angle
347362 for (i in angles.indices) {
348363 val hatchFillSymbolLayer = HatchFillSymbolLayer (
349364 MultilayerPolylineSymbol (listOf (strokeForHatches)), angles[i]
350365 )
351- // define separation distance for lines and add them to the symbol layer array
366+ // define separation distance for lines and add them to the symbol layer list
352367 hatchFillSymbolLayer.separation = 9.0
353- symbolLayerArray[i] = hatchFillSymbolLayer
368+ symbolLayerList.add( hatchFillSymbolLayer)
354369 }
355370
356- // assign the outline layer to the last element of the symbol layer array
357- symbolLayerArray[symbolLayerArray.size - 1 ] = strokeForOutline
358- // create a multilayer polygon symbol from the symbol layer array
371+ // assign the outline layer to the last element of the symbol layer list
372+ symbolLayerList.add( strokeForOutline)
373+ // create a multilayer polygon symbol from the symbol layer list
359374 val multilayerPolygonSymbol =
360- MultilayerPolygonSymbol (symbolLayerArray .asIterable() as Iterable < SymbolLayer > )
375+ MultilayerPolygonSymbol (symbolLayerList .asIterable())
361376 // create a polygon graphic with geometry using the symbol created above, and add it to the graphics overlay
362377 val graphic = Graphic (polygonBuilder.toGeometry(), multilayerPolygonSymbol)
363378 graphicsOverlay.graphics.add(graphic)
@@ -412,11 +427,9 @@ class MainActivity : AppCompatActivity() {
412427 }
413428
414429 /* *
415- * Creates a symbol layer for use in the composition of a complex point.
416- * [fillColor] of the symbol
417- * [outlineColor] of the symbol
418- * [size] of the symbol
419- * @return the vector marker symbol layer.
430+ * Creates a symbol layer for use in the composition of a complex point
431+ * using [fillColor], [outlineColor] as colors and the [size] of the symbol
432+ * Then return a [VectorMarkerSymbolLayer] of the created symbol.
420433 */
421434 private fun getLayerForComplexPoint (
422435 fillColor : Color , outlineColor : Color , size : Double
@@ -449,7 +462,7 @@ class MainActivity : AppCompatActivity() {
449462 // create the multilayer polygon symbol
450463 val multilayerPolygonSymbol = MultilayerPolygonSymbol (getLayersForComplexPolys(true ))
451464 // create the polygon
452- val polygonBuilder = PolygonBuilder (SpatialReference .wgs84()). apply {
465+ val polygonBuilder = PolygonBuilder (SpatialReference .wgs84()) {
453466 addPoint(Point (120.0 , 0.0 ))
454467 addPoint(Point (140.0 , 0.0 ))
455468 addPoint(Point (140.0 , - 10.0 ))
@@ -470,7 +483,7 @@ class MainActivity : AppCompatActivity() {
470483 private fun addComplexPolyline () {
471484 // create the multilayer polyline symbol
472485 val multilayerPolylineSymbol = MultilayerPolylineSymbol (getLayersForComplexPolys(false ))
473- val polylineBuilder = PolylineBuilder (SpatialReference .wgs84()). apply {
486+ val polylineBuilder = PolylineBuilder (SpatialReference .wgs84()) {
474487 addPoint(Point (120.0 , - 25.0 ))
475488 addPoint(Point (140.0 , - 25.0 ))
476489 }
@@ -522,24 +535,4 @@ class MainActivity : AppCompatActivity() {
522535 Log .e(TAG , message)
523536 Snackbar .make(mapView, message, Snackbar .LENGTH_SHORT ).show()
524537 }
525-
526- private val Color .Companion .blue: Color
527- get() {
528- return fromRgba(0 , 0 , 255 , 255 )
529- }
530-
531- private val Color .Companion .yellow: Color
532- get() {
533- return fromRgba(255 , 255 , 0 , 255 )
534- }
535-
536- private val Color .Companion .magenta: Color
537- get() {
538- return fromRgba(255 , 0 , 255 , 255 )
539- }
540-
541- private val Color .Companion .cyan: Color
542- get() {
543- return fromRgba(0 , 100 , 100 , 255 )
544- }
545538}
0 commit comments