-
Notifications
You must be signed in to change notification settings - Fork 0
/
styles.go
101 lines (88 loc) · 2.03 KB
/
styles.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2015 Sam L'ecuyer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mapping
import (
"code.google.com/p/sadbox/color"
"encoding/xml"
"fmt"
"github.com/samlecuyer/ecumene/util"
)
type Style struct {
Name string `xml:"name,attr"`
Rules []*Rule `xml:"Rule"`
}
func (s *Style) String() string {
return fmt.Sprintf("{%s %v}", s.Name, s.Rules)
}
type Rule struct {
Filter string
Symbolizers map[util.SymbolizerType]Symbolizer
}
func (r *Rule) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
r.Symbolizers = make(map[util.SymbolizerType]Symbolizer)
for {
e, err := d.Token()
if err != nil {
break
}
switch e := e.(type) {
case xml.EndElement:
if e.Name.Local == start.Name.Local {
return nil
}
case xml.StartElement:
switch e.Name.Local {
case "Filter":
var f string
if err := d.DecodeElement(&f, &e); err != nil {
return err
}
r.Filter = f
case "Polygon":
s := new(PolygonSymbolizer)
if err := d.DecodeElement(s, &e); err != nil {
return err
}
r.Symbolizers[util.PolygonType] = s
case "Path":
s := new(PathSymbolizer)
if err := d.DecodeElement(s, &e); err != nil {
return err
}
r.Symbolizers[util.PathType] = s
case "Text":
s := new(TextSymbolizer)
if err := d.DecodeElement(s, &e); err != nil {
return err
}
r.Symbolizers[util.TextType] = s
}
}
}
return d.Skip()
}
type Symbolizer interface {
Name() string
}
type PolygonSymbolizer struct {
Fill color.Hex `xml:"fill,attr"`
}
func (s *PolygonSymbolizer) Name() string {
return "Polygon"
}
type PathSymbolizer struct {
Weight float64 `xml:"width,attr" default:"0.5"`
Stroke color.Hex `xml:"stroke,attr"`
}
func (s *PathSymbolizer) Name() string {
return "Path"
}
type TextSymbolizer struct {
Size float64 `xml:"size,attr"`
Fill color.Hex `xml:"fill,attr"`
Attr string `xml:"name,attr"`
}
func (s *TextSymbolizer) Name() string {
return "Text"
}