Skip to content
Permalink
Browse files

add AnyInteresting function to Tags object

  • Loading branch information...
paulmach committed Oct 6, 2018
1 parent 2bdd701 commit 7a428b332f5f6a5ab5b361caa0d09a196088c9fc
Showing with 66 additions and 13 deletions.
  1. +1 −13 osmgeojson/convert.go
  2. +27 −0 tag.go
  3. +38 −0 tag_test.go
@@ -9,18 +9,6 @@ import (
"github.com/paulmach/osm/internal/mputil"
)

var uninterestingTags = map[string]bool{
"source": true,
"source_ref": true,
"source:ref": true,
"history": true,
"attribution": true,
"created_by": true,
"tiger:county": true,
"tiger:tlid": true,
"tiger:upload_uuid": true,
}

type context struct {
noID bool
noMeta bool
@@ -405,7 +393,7 @@ func hasInterestingTags(tags osm.Tags, ignore map[string]string) bool {

for _, tag := range tags {
k, v := tag.Key, tag.Value
if !uninterestingTags[k] &&
if !osm.UninterestingTags[k] &&
(ignore == nil || !(ignore[k] == "true" || ignore[k] == v)) {
return true
}
27 tag.go
@@ -7,6 +7,22 @@ import (
"sync"
)

// UninterestingTags are boring tags. If an element only has
// these tags it does not usually need to be displayed.
// For example, if a node with just these tags is part of a way, it
// probably does not need its own icon along the way.
var UninterestingTags = map[string]bool{
"source": true,
"source_ref": true,
"source:ref": true,
"history": true,
"attribution": true,
"created_by": true,
"tiger:county": true,
"tiger:tlid": true,
"tiger:upload_uuid": true,
}

// Tag is a key+value item attached to osm nodes, ways and relations.
type Tag struct {
Key string `xml:"k,attr"`
@@ -38,6 +54,17 @@ func (ts Tags) Map() map[string]string {
return result
}

// AnyInteresting will return true if there is at last one interesting tag.
func (ts Tags) AnyInteresting() bool {
for _, t := range ts {
if !UninterestingTags[t.Key] {
return true
}
}

return false
}

// MarshalJSON allows the tags to be marshalled as a key/value object,
// as defined by the overpass osmjson.
func (ts Tags) MarshalJSON() ([]byte, error) {
@@ -6,6 +6,44 @@ import (
"testing"
)

func TestTags_AnyInteresting(t *testing.T) {
cases := []struct {
name string
tags Tags
interesting bool
}{
{
name: "has interesting",
tags: Tags{
{Key: "building", Value: "yes"},
},
interesting: true,
},
{
name: "no tags",
tags: Tags{},
interesting: false,
},
{
name: "no interesting tags",
tags: Tags{
{Key: "source", Value: "whatever"},
{Key: "history", Value: "lots"},
},
interesting: false,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
v := tc.tags.AnyInteresting()
if v != tc.interesting {
t.Errorf("incorrect interesting: %v != %v", v, tc.interesting)
}
})
}
}

func TestTags_MarshalJSON(t *testing.T) {
data, err := Tags{}.MarshalJSON()
if err != nil {

0 comments on commit 7a428b3

Please sign in to comment.
You can’t perform that action at this time.