Select to view content in your preferred language

How do I display map server symbols in legend in Kotlin 200.2

701
2
Jump to solution
09-15-2023 01:42 PM
klebercj
Occasional Contributor

Below is the function I'm using to create my legend data.  Debugging of the data shows the symbology from the map server is being pulled, but not displayed.  What would I need to do in order to make the symbols display in the legend? 

fun showLegendDialog(view: View) {
val dialogView = LayoutInflater.from(this).inflate(R.layout.legend_dialog, null)
val builder = AlertDialog.Builder(this)
.setTitle("Legend")
.setView(dialogView)
.setPositiveButton("Close") { dialog, _ -> dialog.dismiss() }

val dialog = builder.create()
dialog.show()

val legendLayout: LinearLayout = dialogView.findViewById(R.id.legendLayout)
val mapImageLayer = mapView.map?.operationalLayers?.get(0) as? ArcGISMapImageLayer

mapImageLayer?.let {
CoroutineScope(Dispatchers.Main).launch {
val mapServerNameTextView = TextView(this@MainActivity)
mapServerNameTextView.text = it.name
mapServerNameTextView.setTypeface(null, Typeface.BOLD)
mapServerNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f)
legendLayout.addView(mapServerNameTextView)

for (sublayer in it.mapImageSublayers) {
if (sublayer.isVisible) {
val sublayerNameTextView = TextView(this@MainActivity)
sublayerNameTextView.text = " " + sublayer.name
sublayerNameTextView.setTypeface(null, Typeface.BOLD)
sublayerNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
legendLayout.addView(sublayerNameTextView)

val legenddata = sublayer.fetchLegendInfos()
for (legendInfo in legenddata.getOrThrow()) {
val legendImageView = ImageView(this@MainActivity)
val symbol = legendInfo.symbol
if (symbol != null) {
legendLayout.addView(legendImageView)
}
val legendName = legendInfo.name
if (legendName.isNotEmpty()) {
val legendNameTextView = TextView(this@MainActivity)
legendNameTextView.text = " " + legendName
legendLayout.addView(legendNameTextView)
}
}
}
}
}
}
}
0 Kudos
1 Solution

Accepted Solutions
GuntherHeppner
Esri Contributor

You will need to create a bitmap from your symbol and then pass that to your ImageView. In oder to create a bitmap from your symbol, use one of the Symbol.createSwatch functions. 

View solution in original post

0 Kudos
2 Replies
GuntherHeppner
Esri Contributor

You will need to create a bitmap from your symbol and then pass that to your ImageView. In oder to create a bitmap from your symbol, use one of the Symbol.createSwatch functions. 

0 Kudos
klebercj
Occasional Contributor

Thank you I was able to use the Symbol.createSwatch functions to display the symbology of the map server I was using.