From b777d7bb4f1b4bc838c3b6470ec5a9d3e7d7c24d Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Fri, 12 Nov 2021 03:32:17 +0300 Subject: [PATCH] Add white and black modes. --- map_machine/constructor.py | 36 +++++++++++++++++++++++++++++--- map_machine/map_configuration.py | 10 +++++++++ map_machine/mapper.py | 4 ++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/map_machine/constructor.py b/map_machine/constructor.py index 59d394b..cecb045 100644 --- a/map_machine/constructor.py +++ b/map_machine/constructor.py @@ -238,6 +238,10 @@ class Constructor: color = get_user_color(line.user, self.configuration.seed) elif self.configuration.drawing_mode == DrawingMode.TIME: color = get_time_color(line.timestamp, self.osm_data.time) + elif self.configuration.drawing_mode == DrawingMode.WHITE: + color = Color("#666666") + elif self.configuration.drawing_mode == DrawingMode.BLACK: + color = Color("#BBBBBB") elif self.configuration.drawing_mode != DrawingMode.NORMAL: logging.fatal( f"Drawing mode {self.configuration.drawing_mode} is not " @@ -416,6 +420,8 @@ class Constructor: def construct_node(self, node: OSMNode) -> None: """Draw one node.""" tags: dict[str, str] = node.tags + if not tags: + return if not self.check_level(tags): return @@ -427,9 +433,10 @@ class Constructor: icon_set: IconSet draw_outline: bool = True - if self.configuration.is_wireframe(): - if not tags: - return + if self.configuration.drawing_mode in ( + DrawingMode.AUTHOR, + DrawingMode.TIME, + ): color: Color = DEFAULT_COLOR if self.configuration.drawing_mode == DrawingMode.AUTHOR: color = get_user_color(node.user, self.configuration.seed) @@ -451,6 +458,29 @@ class Constructor: self.points.append(point) return + if self.configuration.drawing_mode in ( + DrawingMode.WHITE, + DrawingMode.BLACK, + ): + if self.configuration.drawing_mode == DrawingMode.WHITE: + color = Color("#CCCCCC") + if self.configuration.drawing_mode == DrawingMode.BLACK: + color = Color("#444444") + icon_set, priority = self.scheme.get_icon( + self.extractor, tags, processed, self.configuration + ) + icon_set.main_icon.recolor(color) + point: Point = Point( + icon_set, + [], + tags, + processed, + flung, + add_tooltips=self.configuration.show_tooltips, + ) + self.points.append(point) + return + icon_set, priority = self.scheme.get_icon( self.extractor, tags, processed, self.configuration ) diff --git a/map_machine/map_configuration.py b/map_machine/map_configuration.py index 741ff5b..3d8f5e1 100644 --- a/map_machine/map_configuration.py +++ b/map_machine/map_configuration.py @@ -2,9 +2,12 @@ Map drawing configuration. """ import argparse +from colour import Color from dataclasses import dataclass from enum import Enum +from typing import Optional + __author__ = "Sergey Vartanov" __email__ = "me@enzet.ru" @@ -15,6 +18,8 @@ class DrawingMode(Enum): NORMAL = "normal" AUTHOR = "author" TIME = "time" + WHITE = "white" + BLACK = "black" class LabelMode(Enum): @@ -73,3 +78,8 @@ class MapConfiguration: def is_wireframe(self) -> bool: """Whether drawing mode is special.""" return self.drawing_mode != DrawingMode.NORMAL + + def backghround_color(self) -> Optional[Color]: + if self.drawing_mode not in (DrawingMode.NORMAL, DrawingMode.BLACK): + return Color("#111111") + return None diff --git a/map_machine/mapper.py b/map_machine/mapper.py index 384ff19..a8c47f1 100644 --- a/map_machine/mapper.py +++ b/map_machine/mapper.py @@ -48,8 +48,8 @@ class Map: self.configuration = configuration self.background_color: Color = self.scheme.get_color("background_color") - if self.configuration.is_wireframe(): - self.background_color: Color = Color("#111111") + if self.configuration.backghround_color(): + self.background_color = self.configuration.backghround_color() def draw(self, constructor: Constructor) -> None: """Draw map."""