diff --git a/map_machine/boundary_box.py b/map_machine/boundary_box.py index ca490a7..a73ac70 100644 --- a/map_machine/boundary_box.py +++ b/map_machine/boundary_box.py @@ -159,9 +159,16 @@ class BoundaryBox: return f"{left:.3f},{bottom:.3f},{right:.3f},{top:.3f}" + def update(self, coordinates: np.ndarray) -> None: + """Make the boundary box cover coordinates.""" + self.left = min(self.left, coordinates[1]) + self.bottom = min(self.bottom, coordinates[0]) + self.right = max(self.right, coordinates[1]) + self.top = max(self.top, coordinates[0]) + def combine(self, other: "BoundaryBox") -> None: """Combine with another boundary box.""" self.left = min(self.left, other.left) - self.right = min(self.right, other.right) self.bottom = min(self.bottom, other.bottom) - self.top = min(self.top, other.top) + self.right = max(self.right, other.right) + self.top = max(self.top, other.top) diff --git a/map_machine/osm_reader.py b/map_machine/osm_reader.py index d2f9eb4..dd8990c 100644 --- a/map_machine/osm_reader.py +++ b/map_machine/osm_reader.py @@ -372,6 +372,14 @@ class OSMData: node = OSMNode.parse_from_structure(element) node_map[node.id_] = node self.add_node(node) + if not self.view_box: + self.view_box = BoundaryBox( + node.coordinates[1], + node.coordinates[0], + node.coordinates[1], + node.coordinates[0], + ) + self.view_box.update(node.coordinates) for element in structure["elements"]: if element["type"] == "way":