Support extra tags for libkomwm
This commit is contained in:
parent
01addafa2e
commit
071089b704
3 changed files with 29 additions and 11 deletions
|
@ -5,6 +5,7 @@ import csv
|
|||
import sys
|
||||
import itertools
|
||||
from multiprocessing import Pool
|
||||
from collections import OrderedDict
|
||||
import mapcss.webcolors
|
||||
whatever_to_hex = mapcss.webcolors.webcolors.whatever_to_hex
|
||||
whatever_to_cairo = mapcss.webcolors.webcolors.whatever_to_cairo
|
||||
|
@ -183,7 +184,7 @@ def komap_mapswithme(options):
|
|||
if cl in unique_types_check and row[2] != 'x':
|
||||
raise Exception('Duplicate type: {0}'.format(row[0]))
|
||||
pairs = [i.strip(']').split("=") for i in row[1].split(',')[0].split('[')]
|
||||
kv = {}
|
||||
kv = OrderedDict()
|
||||
for i in pairs:
|
||||
if len(i) == 1:
|
||||
if i[0]:
|
||||
|
@ -209,10 +210,12 @@ def komap_mapswithme(options):
|
|||
types_file.close()
|
||||
|
||||
# Get all mapcss static tags which are used in mapcss-mapping.csv
|
||||
mapcss_static_tags = set()
|
||||
# This is a dict with main_tag flags (True = appears first in types)
|
||||
mapcss_static_tags = {}
|
||||
for v in classificator.values():
|
||||
for t in v.keys():
|
||||
mapcss_static_tags.add(t)
|
||||
for i, t in enumerate(v.keys()):
|
||||
# Exception for "sport=*" since these are both main and secondary keys.
|
||||
mapcss_static_tags[t] = i == 0 and t != 'sport'
|
||||
|
||||
# Get all mapcss dynamic tags from mapcss-dynamic.txt
|
||||
mapcss_dynamic_tags = set([line.rstrip() for line in open(os.path.join(ddir, 'mapcss-dynamic.txt'))])
|
||||
|
@ -220,7 +223,8 @@ def komap_mapswithme(options):
|
|||
# Parse style mapcss
|
||||
global style
|
||||
style = MapCSS(options.minzoom, options.maxzoom + 1)
|
||||
style.parse(filename = options.filename, static_tags = mapcss_static_tags, dynamic_tags = mapcss_dynamic_tags)
|
||||
style.parse(filename=options.filename, static_tags=mapcss_static_tags,
|
||||
dynamic_tags=mapcss_dynamic_tags)
|
||||
|
||||
# Build optimization tree - class/type -> StyleChoosers
|
||||
for cl in class_order:
|
||||
|
|
|
@ -79,9 +79,9 @@ class Condition:
|
|||
if t == 'eq':
|
||||
return "%s=%s" % (params[0], params[1])
|
||||
if t == 'ne':
|
||||
return "%s=%s" % (params[0], params[1])
|
||||
return "%s!=%s" % (params[0], params[1])
|
||||
if t == 'regex':
|
||||
return "%s=~/%s/" % (params[0], params[1]);
|
||||
return "%s=~/%s/" % (params[0], params[1])
|
||||
if t == 'true':
|
||||
return "%s?" % (params[0])
|
||||
if t == 'untrue':
|
||||
|
|
|
@ -194,7 +194,7 @@ class MapCSS():
|
|||
raise Exception("Variable not found: " + str(format(name)))
|
||||
return self.variables[name] if name in self.variables else m.group()
|
||||
|
||||
def parse(self, css=None, clamp=True, stretch=1000, filename=None, static_tags=set(), dynamic_tags=set()):
|
||||
def parse(self, css=None, clamp=True, stretch=1000, filename=None, static_tags={}, dynamic_tags=set()):
|
||||
"""
|
||||
Parses MapCSS given as string
|
||||
"""
|
||||
|
@ -254,6 +254,7 @@ class MapCSS():
|
|||
elif GROUP.match(css):
|
||||
css = GROUP.sub("", css, 1)
|
||||
sc.newGroup()
|
||||
had_main_tag = False
|
||||
previous = oGROUP
|
||||
|
||||
# Condition - [highway=primary] or [population>1000]
|
||||
|
@ -261,14 +262,26 @@ class MapCSS():
|
|||
if (previous == oDECLARATION):
|
||||
self.choosers.append(sc)
|
||||
sc = StyleChooser(self.scalepair)
|
||||
had_main_tag = False
|
||||
if (previous != oOBJECT) and (previous != oZOOM) and (previous != oCONDITION):
|
||||
sc.newObject()
|
||||
had_main_tag = False
|
||||
cond = CONDITION.match(css).groups()[0]
|
||||
log.debug("condition found: %s" % (cond))
|
||||
c = parseCondition(cond)
|
||||
tag = c.extract_tag()
|
||||
if tag == "*" or tag in static_tags:
|
||||
sc.addCondition(c)
|
||||
tag_type = static_tags.get(tag, None)
|
||||
if tag == "*" or tag_type is not None:
|
||||
if tag_type and had_main_tag:
|
||||
if '!' in cond:
|
||||
condType = 'ne'
|
||||
cond = cond.replace('!', '')
|
||||
else:
|
||||
condType = 'eq'
|
||||
sc.addRuntimeCondition(Condition(condType, ('extra_tag', cond)))
|
||||
else:
|
||||
sc.addCondition(c)
|
||||
if tag_type:
|
||||
had_main_tag = True
|
||||
elif tag in dynamic_tags:
|
||||
sc.addRuntimeCondition(c)
|
||||
else:
|
||||
|
@ -285,6 +298,7 @@ class MapCSS():
|
|||
log.debug("object found: %s" % (obj))
|
||||
css = OBJECT.sub("", css, 1)
|
||||
sc.newObject(obj)
|
||||
had_main_tag = False
|
||||
previous = oOBJECT
|
||||
|
||||
# Declaration - {...}
|
||||
|
|
Loading…
Add table
Reference in a new issue