tile38/kml/kml.go

40 lines
1.2 KiB
Go
Raw Normal View History

2016-03-05 02:08:16 +03:00
package kml
import (
"bytes"
"fmt"
"github.com/tidwall/tile38/geojson"
)
type pointT struct {
name string
point geojson.SimplePoint
}
type KML struct {
points []pointT
}
func New() *KML {
return &KML{}
}
func (kml *KML) AddPoint(name string, lat, lon float64) {
kml.points = append(kml.points, pointT{name: name, point: geojson.SimplePoint{X: lon, Y: lat}})
}
func (kml *KML) Bytes() []byte {
var buf bytes.Buffer
buf.WriteString(`<?xml version="1.0" encoding="UTF-8"?>` + "\n")
buf.WriteString(`<kml xmlns="http://www.opengis.net/kml/2.2">` + "\n")
buf.WriteString(`<Document>` + "\n")
buf.WriteString(`<Style id="yellow"><IconStyle><Icon><href>http://www.google.com/intl/en_us/mapfiles/ms/icons/yellow-dot.png</href></Icon></IconStyle></Style> ` + "\n")
buf.WriteString(`<Style id="blue"><IconStyle><Icon><href>http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png</href></Icon></IconStyle></Style> ` + "\n")
for _, point := range kml.points {
buf.WriteString(fmt.Sprintf(`<Placemark><styleUrl>#yellow</styleUrl><name>%s</name><Point><coordinates>%f,%f,0</coordinates></Point></Placemark>`+"\n", point.name, point.point.X, point.point.Y))
}
buf.WriteString(`</Document></kml>` + "\n")
return buf.Bytes()
}