KmlToGeoJson

Converts KML into the GeoJSON MapLibre can read.

MapLibre has no KML source, and the F-Droid map used to drop LayerType.KML imports on the floor: the file appeared in the layers sheet, could be toggled, and drew nothing.

Hand-written rather than a new dependency. The KML that reaches this app is what other mapping tools export — Placemarks with a Point, LineString or Polygon and a colour — and the subset the renderers draw is no wider than what this reads. It parses through xmlutil, which the app already resolves for CoT XML, so this is common code and runs wherever the app does rather than only on Android.

Styles come out as simplestyle-spec properties, which is what both flavors' renderers already read, so a converted KML is styled by the same code path as an imported GeoJSON.

Unsupported by design, because the renderers on both sides ignore them anyway: NetworkLink, ScreenOverlay, Model, and time spans. GroundOverlays are parsed — they come back from convertDocument beside the GeoJSON, because an image draped over a box has no GeoJSON representation at all.

Functions

Link copied to clipboard
fun convert(kml: String): String?

Reads kml and returns a GeoJSON FeatureCollection document, or null if nothing mappable was found.

Link copied to clipboard

Everything drawable in kml: the vector features as a GeoJSON FeatureCollection (null if there are none), plus any <GroundOverlay> images. A document can hold either without the other — a pure overlay export has no placemarks at all, and it must not read as "nothing mappable".