Repository navigation
Description
Is your feature request related to a problem? Please describe.
In KML (and GeoJSON) files, line stroke width is specified as a numerical value (<LineStyle><width> is defined as "width in pixels" per OGC KML 2.2 §12.8). When rendered via MapViewRenderer onto a GoogleMap, this value is passed directly to PolylineOptions.width(it.width) and PolygonOptions.strokeWidth(it.strokeWidth).
Because the Google Maps Android SDK interprets PolylineOptions.width in raw physical screen pixels:
- On modern high-density Android devices (e.g.,
xxhdpi3x,xxxhdpi3.5x/4x), lines with width values such as1.0or2.0render as hairline strokes (< 0.7 dp) that are difficult to see. - Cross-platform rendering diverges significantly from iOS, where the Google Maps iOS SDK defines
GMSPolyline.strokeWidthin density-independent screen points (which automatically scale on Retina displays). - When
<width>is omitted in KML,KmlMapperdefaults to1.0f, resulting in a single physical pixel line on high-DPI screens.
This was previously reported in #1401 against the legacy KmlLayer.
Describe the solution you'd like
Provide an opt-in density-scaling mechanism or transform hook in MapViewRenderer (and/or KmlMapper):
- For example, an opt-in property on
MapViewRenderer(such asdensityAware: Boolean = false, taking a display density multiplier orDisplayMetrics) to scale stroke widths from dp/points to device screen pixels:val effectiveWidth = if (densityAware) style.width * displayDensity else style.width
- Or a customizable
strokeWidthTransformer: ((Float) -> Float)?allowing callers to customize width resolution. - Additionally, consider revising the default fallback width in
KmlMapperwhen<width>is null/omitted so it doesn't default to a 1px hairline.
Describe alternatives you've considered
With the new com.google.maps.android.data.renderer.* architecture, developers can iterate over the parsed DataScene / DataLayer features prior to calling renderer.render(scene) and adjust each LineStyle.width or PolygonStyle.strokeWidth by multiplying by context.resources.displayMetrics.density. However, built-in support or an opt-in property in the renderer would streamline cross-platform parity and developer ergonomics.
Additional context
Spun off from discussion in #1401.
Activity