MKergall / osmbonuspack

A third-party library of (very) useful additional objects for osmdroid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

polyline.setWidth and color are deprecated?

antonpitts opened this issue · comments

Trying to follow Tutorial 4 to apply different styling to lines and polygons in a KML, and the IDE (and docs, as far as I can tell) say setWidth, color, and paint are deprecated and to use getOutlinePaint instead, but that returns a val which can't be assigned to. So how would one set the with and colour of a line without using the deprecated methods?

OK, occurred to me somewhat late that I could still set the properties on the outlinePaint (and fillPaint), even if those can't be assigned to. So for anyone finding this with the same question, this seems to work (if you've defined the colours and width you want as constants):

 override fun onPolygon(polygon: Polygon?, kmlPlacemark: KmlPlacemark?, kmlPolygon: KmlPolygon?) {
        polygon?.fillPaint?.color = AREA_FILL_COLOUR
        polygon?.outlinePaint?.let{
            it.color= AREA_LINE_COLOUR
            it.strokeWidth = AREA_LINE_WIDTH
        }
    }
commented
  1. It's deprecated, but it still works.
  2. getOutlinePaint gives you a Paint, then use : paint.setStrokeWidth, etc...