Removed KML Support

This commit is contained in:
tidwall 2018-10-11 09:01:42 -07:00
parent 0ac1eea9be
commit 5ad27e7b5e
2 changed files with 2 additions and 81 deletions

View File

@ -1,43 +0,0 @@
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(`<?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()
}

View File

@ -45,7 +45,6 @@ var (
output = "json"
port = 9851
oneCommand string
tokml bool
raw bool
noprompt bool
tty bool
@ -106,8 +105,6 @@ func parseArgs() bool {
switch arg {
default:
return badArg(arg)
case "-kml":
tokml = true
case "--raw":
raw = true
case "--tty":
@ -293,9 +290,8 @@ func main() {
if err != io.EOF {
fmt.Fprintln(os.Stderr, err.Error())
return
} else {
fmt.Fprintln(os.Stderr, refusedErrorString(addr))
}
fmt.Fprintln(os.Stderr, refusedErrorString(addr))
}
}
} else {
@ -359,10 +355,7 @@ func main() {
break // break out of prompt and just feed data to screen
}
if mustOutput {
if tokml {
msg = convert2kml(msg)
fmt.Fprintln(os.Stdout, string(msg))
} else if output == "resp" {
if output == "resp" {
if !raw {
msg = convert2termresp(msg)
}
@ -449,35 +442,6 @@ func numlen(n int) int {
return l
}
func convert2kml(msg []byte) []byte {
k := NewKML()
var m map[string]interface{}
if err := json.Unmarshal(msg, &m); err == nil {
if v, ok := m["points"].([]interface{}); ok {
for _, v := range v {
if v, ok := v.(map[string]interface{}); ok {
if v, ok := v["point"].(map[string]interface{}); ok {
var name string
var lat, lon float64
if v, ok := v["id"].(string); ok {
name = v
}
if v, ok := v["lat"].(float64); ok {
lat = v
}
if v, ok := v["lon"].(float64); ok {
lon = v
}
k.AddPoint(name, lat, lon)
}
}
}
}
return k.Bytes()
}
return []byte(`{"ok":false,"err":"results must contain points"}`)
}
func help(arg string) error {
var groupsA []string
for group := range groupsM {