I'm trying to create a custom infoWindow for a polyline that contains just text and that has to be shown at the center of the polyline "segment". I have created a simple InfoWindow class (MyInfoWindow):
class MyInfoWindow(layoutResId : Int, map : MapView): InfoWindow(layoutResId, map) {
init{
if(titleId == RES_ID){
setResId(map.context)
}
mView.setOnTouchListener(object : OnTouchListener{
override fun onTouch(p0: View?, p1: MotionEvent?): Boolean {
if(p1!!.action == MotionEvent.ACTION_UP){
close()
}
return true
}
})
}
override fun onOpen(item: Any?) {
val overlay : OverlayWithIW = item as OverlayWithIW
val title : String = overlay.getTitle()
if(mView == null){
return
}
val temp : TextView = mView.findViewById(titleId)
temp.text = title
}
override fun onClose() {
}
companion object{
private const val RES_ID : Int = 0
var titleId : Int = RES_ID
fun setResId(context : Context){
titleId = context.resources.getIdentifier("id/poly_title", null, context.packageName)
Log.i("title", "$titleId")
}
}
}
and an xml file that contains only the textView to show(polyline_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="65dp"
android:layout_height="65dp"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="@+id/poly_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:maxEms="17"
android:layout_gravity="left"
android:text="text"/>
</LinearLayout>
From the designed class that handles the Polyline I've done this
_polyline = Polyline(_map)
_polyline!!.setTitle("distance test")
_infoWindow = MyInfoWindow(R.layout.polyline_layout, _map)
_polyline!!.setInfoWindow(_infoWindow)
What can I do to show the text in the middle of the polyline's segments.
Unforunately with this code I can only see the segmente without the text even when I've clicked.
When creating your own bubble, you MUST use specific ids. (and doing that, also remove your code related to retrieval of your own id)
See: https://github.com/MKergall/osmbonuspack/wiki/Tutorial_2#9-creating-your-own-bubble-layout