-
Notifications
You must be signed in to change notification settings - Fork 8
/
label.go
68 lines (58 loc) · 2.35 KB
/
label.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
package map180
import (
"bytes"
"fmt"
"strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
type label struct {
x, y, featureType int
label string
}
func (m *map3857) labels() (l []label, err error) {
rows, err := db.Query(`with l as (
select st_transScale(geom, $5, $6, $7, $8) as pt, type, name from public.map180_labels
where
ST_Within(geom, ST_MakeEnvelope($1,$2,$3,$4, 3857))
AND zoom = $9
)
select round(ST_X(pt)), round(ST_Y(pt)*-1), type,name from l`, m.llx, m.lly, m.urx, m.ury, m.xshift, m.yshift, m.dx, m.dx, m.zoom)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
lb := label{}
err = rows.Scan(&lb.x, &lb.y, &lb.featureType, &lb.label)
if err != nil {
return
}
l = append(l, lb)
}
rows.Close()
return
}
func labelsToSVG(labels []label) string {
var b bytes.Buffer
for _, l := range labels {
l.label = strings.Replace(l.label, `Mount`, `Mt`, -1)
caser := cases.Title(language.BritishEnglish)
l.label = caser.String(strings.ToLower(l.label))
switch l.featureType {
case 0:
b.WriteString(fmt.Sprintf("<circle cx=\"%d\" cy=\"%d\" r=\"1\" stroke=\"grey\" stroke-width=\"1\" fill=\"lightgrey\" />", l.x, l.y))
b.WriteString(fmt.Sprintf("<text fill=\"grey\" font-style=\"italic\" x=\"%d\" y=\"%d\" font-size=\"%d\" text-anchor=\"start\">%s</text>", l.x+3, l.y+5, 11, l.label))
case 1:
b.WriteString(fmt.Sprintf(" <circle cx=\"%d\" cy=\"%d\" r=\"1\" stroke=\"deepskyblue\" stroke-width=\"1\" fill=\"deepskyblue\" />", l.x, l.y))
b.WriteString(fmt.Sprintf("<text fill=\"deepskyblue\" font-style=\"italic\" x=\"%d\" y=\"%d\" font-size=\"%d\" text-anchor=\"start\">%s</text>", l.x+3, l.y+5, 11, l.label))
case 3:
b.WriteString(fmt.Sprintf("<circle cx=\"%d\" cy=\"%d\" r=\"1\" stroke=\"grey\" stroke-width=\"1\" fill=\"lightgrey\" />", l.x, l.y))
b.WriteString(fmt.Sprintf("<text fill=\"grey\" font-style=\"italic\" x=\"%d\" y=\"%d\" font-size=\"%d\" text-anchor=\"start\">%s</text>", l.x+3, l.y+5, 11, l.label))
case 4:
b.WriteString(fmt.Sprintf("<circle cx=\"%d\" cy=\"%d\" r=\"1\" stroke=\"darkslategrey\" stroke-width=\"1\" fill=\"darkslategrey\" />", l.x, l.y))
b.WriteString(fmt.Sprintf("<text fill=\"darkslategrey\" font-style=\"italic\" x=\"%d\" y=\"%d\" font-size=\"%d\" text-anchor=\"start\">%s</text>", l.x+3, l.y+5, 11, l.label))
}
}
return b.String()
}