/
placemark.go
46 lines (40 loc) · 1.22 KB
/
placemark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gokml_gx
import (
"encoding/xml"
"strings"
)
/*
* Placemark
*/
type Placemark struct {
XMLName xml.Name `xml:"Placemark"`
Id string `xml:"id,attr,omitempty"`
Name string `xml:"name,omitempty"`
Description string `xml:"description,omitempty"`
StyleUrl string `xml:"styleUrl,omitempty"`
Coordinates string `xml:"Point>coordinates"`
Extended ExtendedData `xml:"ExtendedData"`
}
// NewPlacemark() creates a new placemark. All parameters are strings.
func NewPlacemark(id, name, desc, lat, lon, alt, styleurl string) Placemark {
p := Placemark{Id: id, Name: name, Description: desc}
if styleurl != "" {
p.StyleUrl = styleurl
}
p.SetCoordinates(lat, lon, alt)
return p
}
// SetCoordinates takes latitude, longitude, and altitude
// and sets the Coordinates value of the Placemark.
func (p *Placemark) SetCoordinates(lat, lon, alt string) {
s := []string{lon, lat, alt}
p.Coordinates = strings.Join(s, ",")
}
// AddExtendedData() adds an ExtendedData structure to the Placemark
func (p *Placemark) AddExtendedData(e ExtendedData) {
p.Extended = e
}
// Placemark.Marshal()
func (p *Placemark) Marshal() ([]byte, error) {
return xml.MarshalIndent(p, "", " ")
}