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)
}
}
}
}
}
}
}
Solved! Go to Solution.
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.
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.
Thank you I was able to use the Symbol.createSwatch functions to display the symbology of the map server I was using.