support zorder fields
parent
1f34a2311e
commit
0041b01856
|
@ -48,6 +48,7 @@ func init() {
|
||||||
"direction": &simpleColumnType{"SMALLINT"},
|
"direction": &simpleColumnType{"SMALLINT"},
|
||||||
"integer": &simpleColumnType{"INTEGER"},
|
"integer": &simpleColumnType{"INTEGER"},
|
||||||
"wayzorder": &simpleColumnType{"INTEGER"},
|
"wayzorder": &simpleColumnType{"INTEGER"},
|
||||||
|
"zorder": &simpleColumnType{"INTEGER"},
|
||||||
"pseudoarea": &simpleColumnType{"REAL"},
|
"pseudoarea": &simpleColumnType{"REAL"},
|
||||||
"mapping_key": &simpleColumnType{"VARCHAR"},
|
"mapping_key": &simpleColumnType{"VARCHAR"},
|
||||||
"mapping_value": &simpleColumnType{"VARCHAR"},
|
"mapping_value": &simpleColumnType{"VARCHAR"},
|
||||||
|
|
|
@ -10,6 +10,7 @@ type Field struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
Args map[string]interface{} `json:"args"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Table struct {
|
type Table struct {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package mapping
|
package mapping
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"goposm/element"
|
"goposm/element"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -10,21 +11,24 @@ var AvailableFieldTypes map[string]FieldType
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
AvailableFieldTypes = map[string]FieldType{
|
AvailableFieldTypes = map[string]FieldType{
|
||||||
"bool": {"bool", "bool", Bool},
|
"bool": {"bool", "bool", Bool, nil},
|
||||||
"id": {"id", "int64", Id},
|
"id": {"id", "int64", Id, nil},
|
||||||
"string": {"string", "string", String},
|
"string": {"string", "string", String, nil},
|
||||||
"direction": {"direction", "int8", Direction},
|
"direction": {"direction", "int8", Direction, nil},
|
||||||
"integer": {"integer", "int32", Integer},
|
"integer": {"integer", "int32", Integer, nil},
|
||||||
"mapping_key": {"mapping_key", "string", Key},
|
"mapping_key": {"mapping_key", "string", Key, nil},
|
||||||
"mapping_value": {"mapping_value", "string", Value},
|
"mapping_value": {"mapping_value", "string", Value, nil},
|
||||||
"geometry": {"geometry", "geometry", Geometry},
|
"geometry": {"geometry", "geometry", Geometry, nil},
|
||||||
"wayzorder": {"wayzorder", "int32", WayZOrder},
|
"wayzorder": {"wayzorder", "int32", WayZOrder, nil},
|
||||||
"pseudoarea": {"pseudoarea", "float32", PseudoArea},
|
"pseudoarea": {"pseudoarea", "float32", PseudoArea, nil},
|
||||||
|
"zorder": {"zorder", "int32", nil, MakeZOrder},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MakeValue func(string, *element.OSMElem, Match) interface{}
|
type MakeValue func(string, *element.OSMElem, Match) interface{}
|
||||||
|
|
||||||
|
type MakeMakeValue func(string, FieldType, Field) (MakeValue, error)
|
||||||
|
|
||||||
type FieldSpec struct {
|
type FieldSpec struct {
|
||||||
Name string
|
Name string
|
||||||
Type FieldType
|
Type FieldType
|
||||||
|
@ -60,6 +64,13 @@ func (t *Table) TableFields() *TableFields {
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("unhandled type:", mappingField.Type)
|
log.Println("unhandled type:", mappingField.Type)
|
||||||
} else {
|
} else {
|
||||||
|
if fieldType.MakeFunc != nil {
|
||||||
|
makeValue, err := fieldType.MakeFunc(mappingField.Name, fieldType, *mappingField)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
fieldType = FieldType{fieldType.Name, fieldType.GoType, makeValue, nil}
|
||||||
|
}
|
||||||
field.Type = fieldType
|
field.Type = fieldType
|
||||||
}
|
}
|
||||||
result.fields = append(result.fields, field)
|
result.fields = append(result.fields, field)
|
||||||
|
@ -71,6 +82,7 @@ type FieldType struct {
|
||||||
Name string
|
Name string
|
||||||
GoType string
|
GoType string
|
||||||
Func MakeValue
|
Func MakeValue
|
||||||
|
MakeFunc MakeMakeValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func Bool(val string, elem *element.OSMElem, match Match) interface{} {
|
func Bool(val string, elem *element.OSMElem, match Match) interface{} {
|
||||||
|
@ -172,3 +184,33 @@ func WayZOrder(val string, elem *element.OSMElem, match Match) interface{} {
|
||||||
|
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakeZOrder(fieldName string, fieldType FieldType, field Field) (MakeValue, error) {
|
||||||
|
ranks := make(map[string]int)
|
||||||
|
_rankList, ok := field.Args["ranks"]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("missing ranks in args for zorder")
|
||||||
|
}
|
||||||
|
|
||||||
|
rankList, ok := _rankList.([]interface{})
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("ranks in args for zorder not a list")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, rank := range rankList {
|
||||||
|
rankName, ok := rank.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("rank in ranks not a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
ranks[rankName] = len(rankList) - i
|
||||||
|
}
|
||||||
|
zOrder := func(val string, elem *element.OSMElem, match Match) interface{} {
|
||||||
|
if r, ok := ranks[match.Value]; ok {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return zOrder, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue