From b768f45bcb5dc4d98d5d2b5825db7a17e1b71064 Mon Sep 17 00:00:00 2001 From: Constantin Shalnev Date: Fri, 25 Sep 2015 11:03:48 +0300 Subject: [PATCH] Use original MAPCSS/2.0 format for mapcss files --- data/mapcss-dynamic.txt | 1 + tools/kothic/libkomwm.py | 11 +++++++---- tools/kothic/mapcss/__init__.py | 25 +++++++------------------ 3 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 data/mapcss-dynamic.txt diff --git a/data/mapcss-dynamic.txt b/data/mapcss-dynamic.txt new file mode 100644 index 0000000000..727e829eb0 --- /dev/null +++ b/data/mapcss-dynamic.txt @@ -0,0 +1 @@ +population diff --git a/tools/kothic/libkomwm.py b/tools/kothic/libkomwm.py index ebab913e57..3f085b2dc1 100644 --- a/tools/kothic/libkomwm.py +++ b/tools/kothic/libkomwm.py @@ -68,15 +68,18 @@ def komap_mapswithme(options): class_order.sort() types_file.close() - # Get all mapcss tags which are used in mapcss-mapping.csv - mapcss_mapping_tags = set() + # Get all mapcss static tags which are used in mapcss-mapping.csv + mapcss_static_tags = set() for v in classificator.values(): for t in v.keys(): - mapcss_mapping_tags.add(t) + mapcss_static_tags.add(t) + + # 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'))]) # Parse style mapcss style = MapCSS(options.minzoom, options.maxzoom + 1) - style.parse(filename = options.filename, mapcss_tags = mapcss_mapping_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: diff --git a/tools/kothic/mapcss/__init__.py b/tools/kothic/mapcss/__init__.py index f2ff6f9c51..0d3650ee31 100644 --- a/tools/kothic/mapcss/__init__.py +++ b/tools/kothic/mapcss/__init__.py @@ -33,7 +33,6 @@ CLASS = re.compile(r'^ ([\.:]:?[*\w]+) \s* ', re.S | re.X) ZOOM = re.compile(r'^ \| \s* z([\d\-]+) \s* ', re.I | re.S | re.X) GROUP = re.compile(r'^ , \s* ', re.I | re.S | re.X) CONDITION = re.compile(r'^ \[(.+?)\] \s* ', re.S | re.X) -RUNTIME_CONDITION = re.compile(r'^ \((.+?)\) \s* ', re.S | re.X) OBJECT = re.compile(r'^ (\*|[\w]+) \s* ', re.S | re.X) DECLARATION = re.compile(r'^ \{(.+?)\} \s* ', re.S | re.X) IMPORT = re.compile(r'^@import\("(.+?)"\); \s* ', re.S | re.X) @@ -188,7 +187,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, mapcss_tags=None): + def parse(self, css=None, clamp=True, stretch=1000, filename=None, static_tags=set(), dynamic_tags=set()): """ Parses MapCSS given as string """ @@ -250,20 +249,7 @@ class MapCSS(): sc.newGroup() previous = oGROUP - # RuntimeCondition - (population>=10000) - elif RUNTIME_CONDITION.match(css): - if (previous == oDECLARATION): - self.choosers.append(sc) - sc = StyleChooser(self.scalepair) - if (previous != oOBJECT) and (previous != oZOOM) and (previous != oCONDITION): - sc.newObject() - cond = RUNTIME_CONDITION.match(css).groups()[0] - log.debug("runtime condition found: %s" % (cond)) - css = RUNTIME_CONDITION.sub("", css) - sc.addRuntimeCondition(parseCondition(cond)) - previous = oCONDITION - - # Condition - [highway=primary] + # Condition - [highway=primary] or [population>1000] elif CONDITION.match(css): if (previous == oDECLARATION): self.choosers.append(sc) @@ -274,10 +260,13 @@ class MapCSS(): log.debug("condition found: %s" % (cond)) c = parseCondition(cond) tag = c.extract_tag() - if (tag != "*") and (mapcss_tags != None) and (tag not in mapcss_tags): + if tag == "*" or tag in static_tags: + sc.addCondition(c) + elif tag in dynamic_tags: + sc.addRuntimeCondition(c) + else: raise Exception("Unknown tag '" + tag + "' in condition " + cond) css = CONDITION.sub("", css) - sc.addCondition(c) previous = oCONDITION # Object - way, node, relation