Skip to content

Commit 5d474f1

Browse files
committed
Define the extra tags separately, to save repetition. Refs #1
1 parent b2a6d32 commit 5d474f1

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

examples/openstreetmap-carto-legend.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,52 @@
66
{
77
"name": "motorway",
88
"type": "linestring",
9-
"tags": { "feature": "highway_motorway", "cycleway": null, "service": null, "tunnel": null, "bicycle": null, "bridge": null, "construction": null, "highway": "motorway", "foot": null, "horse": null, "tracktype": null },
9+
"tags": { "feature": "highway_motorway", "highway": "motorway" },
1010
"layers": ["roads-casing", "roads-fill"],
1111
"zoom": 18
1212
},
1313
{
1414
"name": "motorway",
1515
"type": "linestring",
16-
"tags": { "feature": "highway_motorway", "cycleway": null, "service": null, "tunnel": null, "bicycle": null, "bridge": null, "construction": null, "highway": "motorway", "foot": null, "horse": null, "tracktype": null },
16+
"tags": { "feature": "highway_motorway", "highway": "motorway" },
1717
"layers": ["roads-casing", "roads-fill"],
1818
"zoom": 15
1919
},
2020
{
2121
"name": "motorway",
2222
"type": "linestring",
23-
"tags": { "feature": "highway_motorway", "cycleway": null, "service": null, "tunnel": null, "bicycle": null, "bridge": null, "construction": null, "highway": "motorway", "foot": null, "horse": null, "tracktype": null },
23+
"tags": { "feature": "highway_motorway", "highway": "motorway" },
2424
"layers": ["roads-low-zoom"],
2525
"zoom": 6
2626
},
2727
{
2828
"name": "residential",
2929
"type": "linestring",
30-
"tags": { "feature": "highway_residential", "cycleway": null, "service": null, "tunnel": "", "bicycle": null, "bridge": null, "construction": null, "highway": "residential", "foot": null, "horse": null, "tracktype": null },
30+
"tags": { "feature": "highway_residential", "highway": "residential" },
3131
"layers": ["roads-casing", "roads-fill"],
3232
"zoom": 15
3333
},
3434
{
3535
"name": "residential",
3636
"type": "linestring",
37-
"tags": { "feature": "highway_footway", "cycleway": null, "service": null, "tunnel": null, "bicycle": null, "bridge": null, "construction": null, "highway": "footway", "foot": null, "horse": null, "tracktype": null },
37+
"tags": { "feature": "highway_footway", "highway": "footway" },
3838
"layers": ["roads-casing", "roads-fill"],
3939
"zoom": 15
4040
},
4141
{
4242
"name": "pub",
4343
"type": "point",
44-
"tags": { "amenity": "pub", "access": null, "highway": null, "historic": null, "leisure": null, "lock": null, "man_made": null, "religion": null, "shop": null, "tourism": null, "waterway": null },
44+
"tags": { "amenity": "pub" },
4545
"layers": ["amenity-points"],
4646
"zoom": 16
4747
},
4848
{
4949
"name": "park",
5050
"type": "polygon",
51-
"tags": { "feature": "leisure_park", "religion": null },
51+
"tags": { "feature": "leisure_park" },
5252
"layers": ["landcover"],
5353
"zoom": 15
5454
}
55-
]
55+
],
56+
"extra_tags": ["feature", "cycleway", "service", "tunnel", "bicycle", "bridge", "construction", "highway", "foot", "horse", "tracktype", "access", "historic", "leisure", "lock", "man_made", "religion", "shop", "tourism", "waterway"]
5657
}

lib/mapnik_legendary.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'json'
33

44
require 'mapnik_legendary/geometry'
5+
require 'mapnik_legendary/tags'
56

67
module MapnikLegendary
78
DEFAULT_ZOOM = 17
@@ -29,8 +30,9 @@ def self.generate_legend(legend_file, map_file, options)
2930
# TODO - use a proper csv library rather than .join(",") !
3031
zoom = feature["zoom"] || DEFAULT_ZOOM
3132
geom = Geometry.new(feature["type"], zoom, map).to_csv
32-
header = feature["tags"].keys.push("wkt").join(",")
33-
row = feature["tags"].values.push(geom).join(",")
33+
tags = Tags.merge_nulls(feature["tags"], legend["extra_tags"])
34+
header = tags.keys.push("wkt").join(",")
35+
row = tags.values.push(geom).join(",")
3436
datasource = Mapnik::Datasource.create(:type => 'csv', :inline => header + "\n" + row )
3537

3638
map.layers.clear

lib/mapnik_legendary/tags.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module MapnikLegendary
2+
class Tags
3+
def self.merge_nulls(tags, extras)
4+
Hash[extras.map{|t| [t,"null"]}].merge(tags)
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)