Skip to content

Kml Style width for LineString is not rendered in pixels #1401

Open

Description

@AiswaryaS

Summary

Kml Style width for LineString is not rendered in pixels

Expected behavior

The KML style width in float needs to be converted to pixels while rendering map.

Observed behavior

The KML style width is very thin on the map and there is a difference between 10dp width line and 10.0 as strokline width. The rendering of the same KML file line strings on google maps on Android is different from the thickness of the line strings on iOS.We also observed that the kml file without width element appears too thick on Android and very thin on iOS.

Environment details

  1. All android versions and all device model
  2. Google maps utility version "com.google.maps.android:android-maps-utils:3.8.2")

Steps to reproduce

Render any kml that has this style element and apply to line strings:

<Style> 9aB10FDA 10.0 </Style>

Code example

val kmlLayer = KmlLayer(
googleMap,
replaceWidthValue(ByteArrayInputStream(kmlByteArray)),
this
)
kmlLayer?.addLayerToMap()

I am unable to override the style using this kmlLayer object as the KmlStyle is not exposed. Please help to fix this as the rendering is not uniform on iOS and Android. Kindly provide us with as solution or workaround quickly if possible.

Thanks,
Aiswarya

Activity

  1. added
    triage me
    type: bug
    on Oct 9, 2024
  2. kikoso commented on May 6, 2025

    @kikoso
    Collaborator

    Hi @AiswaryaS . I am not sure if I am following everything but the current KmlParser is indeed parsing the KmlStyle object, isn't it?

  3. added
    priority: p1
    and removed
    triage me
    on Feb 24, 2026
  4. dkhawk commented on Sep 23, 2026

    @dkhawk
    Contributor

    Hi @AiswaryaS, thank you for the report and patience! Here is an update on the status of this issue and how it is handled in the library:

    1. Legacy KmlLayer Deprecation

    In android-maps-utils v5.0+ (the modular Kotlin rewrite), KmlLayer and the legacy com.google.maps.android.data.kml.* package have been formally deprecated (@Deprecated("Use the new platform-agnostic data layer and renderer instead.")). Future development is centered on the new modular data rendering pipeline under com.google.maps.android.data.renderer.* (MapViewRenderer).

    2. Technical Context: Android vs iOS Stroke Width

    • OGC KML 2.2 Specification (§12.8 <LineStyle>): Defines <width> strictly as "Width of the line, in pixels."
    • Google Maps Android SDK: PolylineOptions.width(float) accepts values in physical screen pixels, not density-independent pixels (dp).
    • Google Maps iOS SDK: GMSPolyline.strokeWidth is measured in screen points (which automatically scale by 2x or 3x on Retina displays).

    Because the Android Maps SDK applies width directly in physical screen pixels, a KML <width>2</width> renders as a literal 2-pixel stroke. On modern high-density Android displays (xxhdpi / xxxhdpi), 2 physical device pixels is less than 0.7 dp, making it appear hairline-thin compared to iOS.

    3. Programmatic Style Customization in the New Architecture

    In the legacy KmlLayer, placemark styles were encapsulated internally and difficult to alter dynamically. In the new architecture:

    • KmlParser and KmlMapper parse KML into an open, platform-agnostic DataScene / DataLayer model with accessible Feature and LineStyle objects.
    • Callers can now inspect and adjust styles programmatically (such as scaling width by context.resources.displayMetrics.density) prior to rendering:
      val kml = KmlParser.parse(inputStream)
      val scene = KmlMapper.toScene(kml)
      val density = context.resources.displayMetrics.density
      
      // Programmatically adjust or scale line widths as needed
      scene.layers.forEach { layer ->
          layer.features.forEach { feature ->
              (feature.style as? LineStyle)?.let { lineStyle ->
                  // Adjust or scale width
              }
          }
      }
      
      val renderer = MapViewRenderer(googleMap, DefaultIconProvider(context))
      renderer.render(scene)

    4. Feature Request for Built-In Density Scaling

    To track adding built-in, opt-in density awareness to MapViewRenderer (and reviewing fallback defaults when <width> is omitted in KML), we have opened a dedicated feature request: #1793.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p1type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions