コード例 #1
0
ファイル: Viewer.py プロジェクト: thefeiter/osmapy
    def load_elements(self):
        """ Start loading OSM elements from the api which belong in the current map view.
        """
        left, top = self.screen2xy(0, 0)
        right, bottom = self.screen2xy(self.frameGeometry().width(), self.frameGeometry().height())
        north, west = calc.xy2deg(left, bottom)
        south, east = calc.xy2deg(right, top)
        self.elements_loader.load(west, north, east, south)

        self.update()
コード例 #2
0
ファイル: Viewer.py プロジェクト: thefeiter/osmapy
    def set_xy(self, x, y):
        """ Set center of the view.

        Args:
            x (float): mercator x of the center
            y (float): mercator y of the center
        """
        self.x = x
        self.y = y
        self.lat, self.lon = calc.xy2deg(self.x, self.y)
        self.set_zoom(self.zoom)
コード例 #3
0
ファイル: Node.py プロジェクト: thefeiter/osmapy
    def set_position(self, x, y):
        """ Set new position of node

        Args:
            x (float): mercator x
            y (float): mercator y
        """
        self.x = x
        self.y = y
        lat, lon = calc.xy2deg(x, y)
        self.data["lat"], self.data["lon"] = str(lat), str(lon)
コード例 #4
0
ファイル: Viewer.py プロジェクト: carmeliale/osmapy
    def mousePressEvent(self, event):
        """ Callback when the mouse is clicked. This is use to react on a click on the OSM copyright, select a node
        or create a new node.

        Args:
            event (Event): contains the click information
        """
        if event.buttons() == QtCore.Qt.LeftButton:
            # click on copyright
            if event.x() > self.frameGeometry().width() - self.osm_copyright.width - self.osm_copyright.margin and \
                    event.y() > self.frameGeometry().height() - self.osm_copyright.height - self.osm_copyright.margin:
                webbrowser.open(self.osm_copyright.url)
                return

        if self.mode == "normal":
            if event.buttons() == QtCore.Qt.RightButton:
                posx = event.x()
                posy = event.y()
                smallest = 9999999
                elem_id = None
                for key, elem in self.elements_loader.elements.items():
                    xscreen, yscreen = self.xy2screen(elem.x, elem.y)
                    dist = np.sqrt((xscreen - posx)**2 + (yscreen - posy)**2)
                    if dist < smallest:
                        elem_id = key
                        smallest = dist
                if elem_id:
                    self.elements_loader.selected_node = elem_id
                    self.update()
                    self.element_viewer.set_node(
                        self.elements_loader.elements[elem_id])
        elif self.mode == "new_node":
            if event.buttons() == QtCore.Qt.RightButton:
                x, y = self.screen2xy(event.x(), event.y())
                lat, lon = calc.xy2deg(x, y)
                self.elements_loader.new_node(lat, lon)
                self.update()
                self.change_mode("normal")
コード例 #5
0
 def from_xy(cls, x, y):
     lat, lon = calc.xy2deg(x, y)
     return cls(lat, lon)