Esempio n. 1
0
    def __init__(self, lat, lon, zoom):
        """ Constructer with the latitude and longitude which should lay inside of the slippy tile.

        Args:
            lat (float): latitude of a position which should lay inside of the tile
            lon (float): longitude of a position which should lay inside of the tile
            zoom (int): zoom level of the tile
        """
        self.lat = lat
        self.lon = lon
        self.zoom = zoom

        self.x, self.y = calc.deg2xy(self.lat, self.lon)

        self.xtile, self.ytile = calc.deg2num(self.lat, self.lon, self.zoom)

        self.int_xtile, self.int_ytile = int(self.xtile), int(self.ytile)

        self.bbox_deg = calc.get_bbox_deg(self.xtile, self.ytile, self.zoom)
        self.bbox_xy = calc.get_bbox_xy(self.xtile, self.ytile, self.zoom)

        self.width_x = np.abs(self.bbox_xy.left - self.bbox_xy.right)
        self.width_y = np.abs(self.bbox_xy.top - self.bbox_xy.bottom)

        self.center_x, self.center_y = calc.deg2xy(*calc.num2deg(self.int_xtile + 0.5, self.int_ytile + 0.5, self.zoom))

        self.scale_x = np.abs(self.bbox_xy.left - self.bbox_xy.right) / config.image_size
        self.scale_y = np.abs(self.bbox_xy.top - self.bbox_xy.left) / config.image_size

        self.name = f"{self.int_xtile}_{self.int_ytile}_{self.zoom}"  # internal name of this tile
Esempio n. 2
0
    def __init__(self, raw):
        """ The constructer uses the raw dictionary of the OSM server answer.

        Args:
            raw (dict): OSM server result for this object.
        """
        self.raw = raw.copy()
        self.id = self.raw["id"]

        self.data = dict(id=str(self.raw["id"]),
                         uid=str(self.raw["uid"]),
                         user=str(self.raw["user"]),
                         version=str(self.raw["version"]),
                         changeset=str(self.raw["changeset"]),
                         timestamp=str(self.raw["timestamp"]),
                         type="node",
                         lat=str(self.raw["lat"]),
                         lon=str(self.raw["lon"]))

        if "tags" in self.raw:
            self.data["tags"] = self.raw["tags"].copy()
        else:
            self.data["tags"] = dict()

        self.x, self.y = calc.deg2xy(self.raw["lat"], self.raw["lon"])
        self.trigger = False
Esempio n. 3
0
    def draw(self, viewer, qpainter, alpha):
        """ Function to draw on a View.

        Args:
            viewer (Viewer): object which must is drawn on and which must be updated
            qpainter (QPainter): object which is used to draw
            alpha (float): opacity to draw
        """
        qpainter.setOpacity(alpha)
        for elem in self.elements.values():
            qpainter.setBrush(QColor(QtCore.Qt.blue))
            qpainter.setPen(QPen(QColor(QtCore.Qt.black), 1))
            if elem.data["type"] == "node":
                x, y = calc.deg2xy(float(elem.data["lat"]),
                                   float(elem.data["lon"]))
                xscreen, yscreen = viewer.xy2screen(x, y)

                size = 6
                qpainter.drawEllipse(xscreen - size / 2, yscreen - size / 2,
                                     size, size)

                if self.selected_node and elem.id == self.selected_node:
                    qpainter.setBrush(QColor(0, 0, 0, 0))
                    qpainter.setPen(QPen(QColor(QtCore.Qt.red), 2))
                    size = 10
                    qpainter.drawRect(xscreen - size / 2, yscreen - size / 2,
                                      size, size)
Esempio n. 4
0
    def set_deg(self, lat, lon):
        """ Set center of the view.

        Args:
            lat (float): latitude of the center
            lon (float): longitude of the center
        """
        self.lat = lat
        self.lon = lon
        self.x, self.y = calc.deg2xy(self.lat, self.lon)
        self.set_zoom(self.zoom)
Esempio n. 5
0
    def __init__(self, parent=None):
        super(Viewer, self).__init__()

        self.tile_loaders = []
        for config_id in range(len(config.slippy_tiles)):
            self.tile_loaders.append(TileLoader.TileLoader(self, config_id))
        self.parent = parent
        self.element_viewer = self.parent.element_viewer

        self.lat = config.start_latitude
        self.lon = config.start_longitude
        self.zoom = config.start_zoom
        self.x, self.y = calc.deg2xy(self.lat, self.lon)

        # scale
        tile = Tile.Tile(self.lat, self.lon, self.zoom)
        self.scale_x = config.image_size / tile.width_x
        self.scale_y = config.image_size / tile.width_y

        self.click = False

        self.elements_loader = self.parent.elements_loader

        for tile_loader in self.tile_loaders:
            self.destroyed.connect(tile_loader.close)

        path_base = pathlib.Path(__file__).parent
        self.asset_error_image = str(path_base /
                                     pathlib.Path("../assets/error.png"))

        self.osm_copyright = OSMCopyright()

        self.setAcceptDrops(True)  # allow file dropping

        self.layers = self.parent.layer_manager
        for config_id, tile_loader in enumerate(self.tile_loaders):
            self.layers.add_layer(tile_loader,
                                  config.slippy_tiles[config_id].name,
                                  config.slippy_tiles[config_id].enabled)
        self.layers.add_layer(self.elements_loader, "OSM Nodes")

        self.mode = "normal"  # mode for clicking events
Esempio n. 6
0
 def __init__(self, lat, lon):
     self.lat = lat
     self.lon = lon
     self.x, self.y = calc.deg2xy(lat, lon)