package main import ( "bytes" "fmt" "github.com/tidwall/tile38/pkg/geojson" ) type pointT struct { name string point geojson.SimplePoint } // KML represents a KML object. type KML struct { points []pointT } // NewKML returns a new KML object. func NewKML() *KML { return &KML{} } // AddPoint adds a point to a KML object. func (kml *KML) AddPoint(name string, lat, lon float64) { kml.points = append(kml.points, pointT{name: name, point: geojson.SimplePoint{X: lon, Y: lat}}) } // Bytes returns the xml of the KML. func (kml *KML) Bytes() []byte { var buf bytes.Buffer buf.WriteString(`` + "\n") buf.WriteString(`` + "\n") buf.WriteString(`` + "\n") buf.WriteString(` ` + "\n") buf.WriteString(` ` + "\n") for _, point := range kml.points { buf.WriteString(fmt.Sprintf(`#yellow%s%f,%f,0`+"\n", point.name, point.point.X, point.point.Y)) } buf.WriteString(`` + "\n") return buf.Bytes() }