software.purpledragon.poi4s.kml.KmlWriter.scala Maven / Gradle / Ivy
package software.purpledragon.poi4s.kml
import java.io.OutputStream
import software.purpledragon.poi4s.model.PoiFile
import scala.xml.{Elem, PrettyPrinter}
object KmlWriter {
private val prettyPrinter = new PrettyPrinter(80, 4)
def write(poiFile: PoiFile, os: OutputStream): Unit = {
val xml = generateKml(poiFile)
os.write(prettyPrinter.format(xml).getBytes("UTF-8"))
}
private def generateKml(kmlFile: PoiFile): Elem = {
{kmlFile.name.map(n => {n} ).orNull}
{kmlFile.description.map(d => {d} ).orNull}
{
kmlFile.waypoints map { waypoint =>
{waypoint.name.map(n => {n} ).orNull}
{waypoint.description.map(p => {p} ).orNull}
{
waypoint.elevation match {
case Some(e) =>
s"${waypoint.lon},${waypoint.lat},$e"
case None =>
s"${waypoint.lon},${waypoint.lat}"
}
}
}
}
}
}