diff --git a/README.md b/README.md index 17e73aa..5b03f4a 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ polygon = shape(json) fill_layer = mapsy.FillLayer( [ mapsy.FillItem( - polygon, + geometry=polygon, fill_color=mapsy.Color(0.5, 0.5, 0.5, 0.3), line_color=mapsy.Color(0, 0, 0), line_width=2, @@ -120,7 +120,7 @@ line = shape(json) fill_layer = mapsy.LineLayer( [ mapsy.LineItem( - line, + geometry=line, join=mapsy.LineJoin.round, cap=mapsy.LineCap.round width=12, @@ -147,7 +147,7 @@ point = shape(json) circle_layer = mapsy.CircleLayer( [ mapsy.CircleItem( - point, + geometry=point, fill_color=mapsy.Color(0.5, 0.5, 0.5, 0.3), line_color=mapsy.Color(0, 0, 0), line_width=2, @@ -175,7 +175,7 @@ point = shape(json) symbol_layer = mapsy.SymbolLayer( [ mapsy.SymbolItem( - point, + geometry=point, icon=mapsy.Icons.PIN_24, text="Hello World", text_offset=(0, 16) diff --git a/example/simple_map.py b/example/simple_map.py index 9c2d402..232bad5 100644 --- a/example/simple_map.py +++ b/example/simple_map.py @@ -60,8 +60,8 @@ def main(): fill = mapsy.FillLayer( [ mapsy.FillItem( - polygon, - fill_color=mapsy.Color(0.5, 0.5, 0.5, 0.3), + geometry=polygon, + color=mapsy.Color(0.5, 0.5, 0.5, 0.3), line_color=mapsy.Color(0, 0, 0), line_width=2, ) diff --git a/mapsy/layer/fill_layer.py b/mapsy/layer/fill_layer.py index ab81e93..ed4c645 100644 --- a/mapsy/layer/fill_layer.py +++ b/mapsy/layer/fill_layer.py @@ -8,8 +8,8 @@ @dataclass class FillItem: - polygon: Polygon | MultiPolygon - fill_color: Color + geometry: Polygon | MultiPolygon + color: Color line_color: Color line_width: int = 0 @@ -21,20 +21,20 @@ def __init__(self, items: list[FillItem]) -> None: def render(self, context: RenderContext) -> None: for item in self.items: polygon_in_img_crs = context.transformer.transform_to_image_crs( - item.polygon + item.geometry ) if isinstance(polygon_in_img_crs, MultiPolygon): for poly in polygon_in_img_crs.geoms: context.render_backend.draw_polygon( polygon=poly, line_color=item.line_color, - fill_color=item.fill_color, + fill_color=item.color, line_width=item.line_width, ) else: context.render_backend.draw_polygon( polygon=polygon_in_img_crs, line_color=item.line_color, - fill_color=item.fill_color, + fill_color=item.color, line_width=item.line_width, ) diff --git a/mapsy/layer/line_layer.py b/mapsy/layer/line_layer.py index a33cf17..9db490b 100644 --- a/mapsy/layer/line_layer.py +++ b/mapsy/layer/line_layer.py @@ -19,14 +19,14 @@ class LineItem: color: str | None = None width: float | None = 1 cap: LineCap | None = LineCap.BUTT - join: LineJoin | None = LineJoin.MITER + join: LineJoin | None = LineJoin.ROUND outline_color: str | None = None outline_width: float | None = None class LineLayer(Layer): - def __init__(self, lines: list[LineItem]) -> None: - self.items = lines + def __init__(self, items: list[LineItem]) -> None: + self.items = items def render(self, context: RenderContext) -> None: def render_line(geom: LineString, item: LineItem) -> None: diff --git a/mapsy/layer/symbol_layer.py b/mapsy/layer/symbol_layer.py index 2945276..81a0c51 100644 --- a/mapsy/layer/symbol_layer.py +++ b/mapsy/layer/symbol_layer.py @@ -33,8 +33,8 @@ class SymbolItem: class SymbolLayer(Layer): items: list[SymbolItem] - def __init__(self, symbols: list[SymbolItem]) -> None: - self.items = symbols + def __init__(self, items: list[SymbolItem]) -> None: + self.items = items super().__init__() @staticmethod diff --git a/mapsy/render/cairo_backend.py b/mapsy/render/cairo_backend.py index 34e0a92..99c9faf 100644 --- a/mapsy/render/cairo_backend.py +++ b/mapsy/render/cairo_backend.py @@ -139,6 +139,8 @@ def draw_paths(color: Color): if line_width > 0: context.set_line_width(line_width) + context.set_line_join(cairo.LINE_JOIN_ROUND) + draw_paths(line_color) context.stroke() @@ -148,7 +150,7 @@ def draw_line( color: Color, width: float, cap: LineCap = LineCap.BUTT, - join: LineJoin = LineJoin.MITER, + join: LineJoin = LineJoin.ROUND, outline_color: Color = None, outline_width: float = 0, ) -> None: diff --git a/pyproject.toml b/pyproject.toml index 06f8ef3..283a4a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mapsy" -version = "0.1.0" +version = "0.2.0" description = "Mapsy is a Python library designed easily render static maps in python." authors = ["Felix Horvat "] readme = "README.md" diff --git a/test/data/test_fill_layer.png b/test/data/test_fill_layer.png index 2b58173..4cceb13 100644 Binary files a/test/data/test_fill_layer.png and b/test/data/test_fill_layer.png differ diff --git a/test/data/test_line_layer.png b/test/data/test_line_layer.png index da0ecfc..c42c775 100644 Binary files a/test/data/test_line_layer.png and b/test/data/test_line_layer.png differ diff --git a/test/test_fill_layer.py b/test/test_fill_layer.py index e3e3d97..9a93a9b 100644 --- a/test/test_fill_layer.py +++ b/test/test_fill_layer.py @@ -7,14 +7,14 @@ def test_fill_layer(tmp_path): items = [ mapsy.FillItem( - polygon=Polygon([(0, 0), (0.5, 0), (0.5, 0.5), (0, 0.5)]), - fill_color=mapsy.Color(1, 0, 0), + geometry=Polygon([(0, 0), (0.5, 0), (0.5, 0.5), (0, 0.5)]), + color=mapsy.Color(1, 0, 0), line_color=mapsy.Color(0, 0, 0), line_width=1, ), mapsy.FillItem( - polygon=Polygon([(0.5, 0.5), (1, 0.5), (1, 1), (0.5, 1)]), - fill_color=mapsy.Color(0, 1, 0), + geometry=Polygon([(0.5, 0.5), (1, 0.5), (1, 1), (0.5, 1)]), + color=mapsy.Color(0, 1, 0), line_color=mapsy.Color(1, 1, 1), line_width=10, ),