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" output = "json"
port = 9851 port = 9851
oneCommand string oneCommand string
tokml bool
raw bool raw bool
noprompt bool noprompt bool
tty bool tty bool
@ -106,8 +105,6 @@ func parseArgs() bool {
switch arg { switch arg {
default: default:
return badArg(arg) return badArg(arg)
case "-kml":
tokml = true
case "--raw": case "--raw":
raw = true raw = true
case "--tty": case "--tty":
@ -293,9 +290,8 @@ func main() {
if err != io.EOF { if err != io.EOF {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())
return return
} else {
fmt.Fprintln(os.Stderr, refusedErrorString(addr))
} }
fmt.Fprintln(os.Stderr, refusedErrorString(addr))
} }
} }
} else { } else {
@ -359,10 +355,7 @@ func main() {
break // break out of prompt and just feed data to screen break // break out of prompt and just feed data to screen
} }
if mustOutput { if mustOutput {
if tokml { if output == "resp" {
msg = convert2kml(msg)
fmt.Fprintln(os.Stdout, string(msg))
} else if output == "resp" {
if !raw { if !raw {
msg = convert2termresp(msg) msg = convert2termresp(msg)
} }
@ -449,35 +442,6 @@ func numlen(n int) int {
return l 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 { func help(arg string) error {
var groupsA []string var groupsA []string
for group := range groupsM { for group := range groupsM {