Beispiel #1
0
    def __init__(self, use_case: GetMapUseCase,
                 get_coords: GetCoords, get_address: GetAddress, get_postal_code: GetPostalCode,
                 get_address_organization: GetAddressOrganization, parent=None):
        self.use_case = use_case
        self.get_coords = get_coords
        self.get_address = get_address
        self.get_postal_code = get_postal_code
        self.map_params = MapParams()
        self.geocoder_adapter = GeocoderAdapter()
        self.middle_coords_x = 300
        self.middle_coords_y = 245
        self.get_address_organization = get_address_organization
        self.object_service_adapter = ObjectServiceAdapter()

        self.search_obj = ""
        self.postal_code = ""

        super(QMainWindow, self).__init__(parent)

        uic.loadUi(r"ui\main_window.ui", self)

        self.button_search.clicked.connect(self.search)
        self.button_clear.clicked.connect(self.clear)
        self.check_postal_code.clicked.connect(self.add_postal_code)
        self.choise_type.activated[str].connect(self.changed_type)

        self.show_map()
Beispiel #2
0
    def __init__(self, uc: GetMapUseCase, parent=None):
        super().__init__(parent)

        self.map_label = QLabel()

        layout = QVBoxLayout()
        layout.addWidget(self.map_label)

        self.setLayout(layout)
        self.uc = uc
        self.map_params = MapParams()
        self.show_map()
Beispiel #3
0
 def execute(self, param: MapParams):
     return self.map_service.get_map(param.get_start_longitude(),
                                     param.get_start_latitude(),
                                     param.get_longitude(),
                                     param.get_latitude(),
                                     param.get_zoom(),
                                     param.get_type_map())
    def __init__(self, uc: GetMapUseCase, parent=None):
        super().__init__(parent)

        self.map_label = QLabel(self)
        self.search_line = QLineEdit(self)
        self.search_line.setFocusPolicy(Qt.ClickFocus)
        self.search_button = QPushButton(self, text='Искать')
        self.search_button.setFocusPolicy(Qt.NoFocus)
        self.reset_search_button = QPushButton(
            self, text='Сброс поискового результата')
        self.reset_search_button.setFocusPolicy(Qt.NoFocus)
        self.address_text_string = QTextEdit(self)
        self.address_text_string.setFocusPolicy(Qt.NoFocus)
        self.post_index_button = QRadioButton(
            self, text='Отображение почтовго индекса')

        self.reset_search_button.clicked.connect(self.reset_search)
        self.search_button.clicked.connect(self.send_search_line)
        self.post_index_button.clicked.connect(self.update_assress)

        main_layout = QHBoxLayout()
        map_layout = QVBoxLayout()
        settings_layout = QVBoxLayout()
        map_layout.addWidget(self.map_label)
        settings_layout.addWidget(self.search_line)
        settings_layout.addWidget(self.search_button)
        settings_layout.addWidget(self.reset_search_button)
        settings_layout.addWidget(self.address_text_string)
        settings_layout.addWidget(self.post_index_button)
        main_layout.addLayout(settings_layout)
        main_layout.addLayout(map_layout)

        self.setLayout(main_layout)

        self.uc = uc

        self.map_params = MapParams()

        self.show_map()
Beispiel #5
0
class Window(QMainWindow):
    def __init__(self, use_case: GetMapUseCase,
                 get_coords: GetCoords, get_address: GetAddress, get_postal_code: GetPostalCode,
                 get_address_organization: GetAddressOrganization, parent=None):
        self.use_case = use_case
        self.get_coords = get_coords
        self.get_address = get_address
        self.get_postal_code = get_postal_code
        self.map_params = MapParams()
        self.geocoder_adapter = GeocoderAdapter()
        self.middle_coords_x = 300
        self.middle_coords_y = 245
        self.get_address_organization = get_address_organization
        self.object_service_adapter = ObjectServiceAdapter()

        self.search_obj = ""
        self.postal_code = ""

        super(QMainWindow, self).__init__(parent)

        uic.loadUi(r"ui\main_window.ui", self)

        self.button_search.clicked.connect(self.search)
        self.button_clear.clicked.connect(self.clear)
        self.check_postal_code.clicked.connect(self.add_postal_code)
        self.choise_type.activated[str].connect(self.changed_type)

        self.show_map()

    def keyPressEvent(self, key_event: QtGui.QKeyEvent) -> None:
        key = key_event.key()
        if key == Qt.Key_PageUp:
            self.map_params.zoom_up()
        elif key == Qt.Key_PageDown:
            self.map_params.zoom_down()
        if key == Qt.Key_Left:
            self.map_params.left()
        elif key == Qt.Key_Right:
            self.map_params.right()
        if key == Qt.Key_Up:
            self.map_params.up()
        elif key == Qt.Key_Down:
            self.map_params.down()

        if key == Qt.LeftButton:
            print(1)

        self.show_map()

    def find_coords_where_click(self, event: QMouseEvent):
        self.map_params.find_scale(self.map_params.latitude)
        x, y = event.x() - self.middle_coords_x, event.y() - self.middle_coords_y
        self.map_params.start_longitude = self.map_params.longitude + \
                                          x * self.map_params.scale_x
        self.map_params.start_latitude = self.map_params.latitude - \
                                         y * self.map_params.scale_y

    def mousePressEvent(self, event: QMouseEvent):
        key = event.button()
        if key == 1:
            if (event.x() <= 600 and event.y() <= 470) and event.y() >= 20:
                self.output_address.setText('')
                self.find_coords_where_click(event)

                name_object = self.get_coords.execute_object(
                    (self.geocoder_adapter.get_object
                     (self.map_params.start_longitude,
                      self.map_params.start_latitude)))

                self.output_address.setText(name_object)
                self.add_postal_code(flag_find_by_coords=True)

                self.show_map()
        elif key == 2:
            if (event.x() <= 600 and event.y() <= 470) and event.y() >= 20:
                self.output_address.setText('')
                self.find_coords_where_click(event)
                name_place = self.get_address.execute(self.geocoder_adapter.get_object(
                    self.map_params.get_start_longitude(), self.map_params.get_start_latitude()
                ))
                name_object = self.get_address_organization.execute_organization(
                    self.object_service_adapter.get_organization(
                        self.map_params.get_start_longitude(),
                        self.map_params.get_start_latitude(), name_place),
                    self.map_params.get_start_longitude(),
                    self.map_params.get_start_latitude())
                if name_object:
                    self.output_address.setText(str(name_object))
                self.add_postal_code(flag_find_by_coords=True)
                self.show_map()

    def search(self):
        self.search_obj = self.input_object.text()
        if self.search_obj:
            coords = self.get_coords.execute(self.geocoder_adapter.get_coords(self.search_obj))
            self.map_params.set_latitude(coords[1])
            self.map_params.set_start_latitude(coords[1])
            self.map_params.set_start_longitude(coords[0])
            self.map_params.set_longitude(coords[0])

            address = self.get_address.execute(self.geocoder_adapter.get_coords(self.search_obj))
            self.output_address.setText(address)

        self.show_map()

    def clear(self):
        self.map_params.into_source_coords()
        self.input_object.clear()
        self.output_address.clear()
        self.search()
        self.show_map()

    def changed_type(self, text):
        if text == 'Схема':
            self.map_params.change_type_map()
        elif text == 'Спутник':
            self.map_params.change_type_sat()
        elif text == 'Гибрид':
            self.map_params.change_type_sat_skl()

    def add_postal_code(self, flag_find_by_coords=False):
        if not self.check_postal_code.isChecked():
            if self.postal_code:
                self.output_address.setText(self.output_address.text()[:-len(self.postal_code) - 2])
                self.postal_code = ""
        else:
            try:
                if not flag_find_by_coords:
                    self.postal_code = self.get_postal_code.execute(
                        self.geocoder_adapter.get_coords(self.search_obj))
                else:
                    self.postal_code = self.get_postal_code.execute_by_coords(
                        self.geocoder_adapter.get_object(self.map_params.get_start_longitude(),
                                                         self.map_params.get_start_latitude()))

                if self.check_postal_code.isChecked():
                    self.output_address.setText(self.output_address.text() + ", " + self.postal_code)
            except KeyError:
                return

    def show_map(self):
        map_picture = self.use_case.execute(self.map_params)

        pixmap = QPixmap()
        type_map = str()

        if self.map_params.get_type_map() == 'sat' or self.map_params.get_type_map() == 'sat,skl':
            type_map = 'JPG'
        elif self.map_params.get_type_map() == 'map':
            type_map = 'PNG'

        pixmap.loadFromData(map_picture, type_map)
        self.map_label.setPixmap(pixmap)
Beispiel #6
0
class MainWindow(QWidget):
    def __init__(self, uc: GetMapUseCase, parent=None):
        super().__init__(parent)

        self.map_label = QLabel()

        layout = QVBoxLayout()
        layout.addWidget(self.map_label)

        self.setLayout(layout)
        self.uc = uc
        self.map_params = MapParams()
        self.show_map()

    def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        key = event.key()
        if key == Qt.Key_PageUp:
            self.map_params.up_zoom()
        elif key == Qt.Key_PageDown:
            self.map_params.down_zoom()
        elif key == Qt.Key_Up:
            self.map_params.up()
        elif key == Qt.Key_Down:
            self.map_params.down()
        elif key == Qt.Key_Left:
            self.map_params.left()
        elif key == Qt.Key_Right:
            self.map_params.right()
        self.show_map()

    def show_map(self):
        map = self.uc.execute(self.map_params)
        pixmap = QPixmap()
        pixmap.loadFromData(map, "PNG")
        self.map_label.setPixmap(pixmap)
Beispiel #7
0
 def __init__(self, uc: GetMapUseCase, parent=None):
     super().__init__(parent)
     self.initUI()
     self.uc = uc
     self.map_params = MapParams()
     self.show_map()
Beispiel #8
0
class MainWindow(QWidget):
    def __init__(self, uc: GetMapUseCase, parent=None):
        super().__init__(parent)
        self.initUI()
        self.uc = uc
        self.map_params = MapParams()
        self.show_map()

    def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        key = event.key()
        if key == Qt.Key_PageUp:
            self.map_params.up_zoom()
        elif key == Qt.Key_PageDown:
            self.map_params.down_zoom()
        elif key == Qt.Key_Up:
            self.map_params.up()
        elif key == Qt.Key_Down:
            self.map_params.down()
        elif key == Qt.Key_Left:
            self.map_params.left()
        elif key == Qt.Key_Right:
            self.map_params.right()

        self.show_map()

    def initUI(self):
        self.setGeometry(100, 100, 1000, 800)
        self.setWindowTitle('Maps API')

        self.map_label = QLabel(self)
        self.map_label.setGeometry(20, -20, 530, 530)

        layout = QVBoxLayout()
        layout.addWidget(self.map_label)
        self.setLayout(layout)

        self.type_box = QComboBox(self)
        self.type_box.addItems(['Схема', "Спутник", "Гибрид"])
        self.type_box.setGeometry(85, 10, 150, 30)

        self.type_label = QLabel(self)
        self.type_label.setText('Тип карты:')
        self.type_label.setGeometry(10, 10, 150, 30)

        self.res_button = QPushButton("Показать", self)
        self.res_button.setGeometry(10, 50, 150, 30)
        self.res_button.clicked.connect(self.click)

        self.btn1 = QPushButton("Искать", self)
        self.btn1.move(520, 640)
        self.btn1.resize(100, 30)
        self.btn1.clicked.connect(self.click)

        self.btn2 = QPushButton("Сброс поискового результата", self)
        self.btn2.move(10, 720)
        self.btn2.resize(200, 30)
        self.btn2.clicked.connect(self.click)

        self.line1 = QLineEdit('', self)
        self.line1.move(10, 640)
        self.line1.resize(500, 30)

        self.label_fullname = QLabel(self)
        self.label_fullname.setText('Полный адрес: ')
        self.label_fullname.setGeometry(10, 680, 1000, 30)

    def click(self):
        source = self.sender()

        if source.text() == 'Искать':
            address = self.line1.text()
            pos = list(search_for_coordinates(address))
            name = search_full_name(address)
            self.map_params.new_search(pos[0], pos[1])
            self.label_fullname.setText('Полный адрес: ' + name)

        elif source.text() == 'Сброс поискового результата':
            self.line1.setText('')
            name = search_full_name("Москва, МГУ")
            self.label_fullname.setText('Полный адрес: ' + name)

            self.map_params.new_search('37.530887', '55.703118')

        else:
            if self.type_box.currentIndex() == 0:
                self.map_params.new_l('map')
            if self.type_box.currentIndex() == 1:
                self.map_params.new_l('sat')
            if self.type_box.currentIndex() == 2:
                self.map_params.new_l('skl')

        self.show_map()
        self.map_label.setFocus()

    def show_map(self):
        map = self.uc.execute(self.map_params)

        pixmap = QPixmap()
        pixmap.loadFromData(map, "PNG")
        self.map_label.setPixmap(pixmap)
class MainWindow(QWidget):
    def __init__(self, uc: GetMapUseCase, parent=None):
        super().__init__(parent)

        self.map_label = QLabel(self)
        self.search_line = QLineEdit(self)
        self.search_line.setFocusPolicy(Qt.ClickFocus)
        self.search_button = QPushButton(self, text='Искать')
        self.search_button.setFocusPolicy(Qt.NoFocus)
        self.reset_search_button = QPushButton(
            self, text='Сброс поискового результата')
        self.reset_search_button.setFocusPolicy(Qt.NoFocus)
        self.address_text_string = QTextEdit(self)
        self.address_text_string.setFocusPolicy(Qt.NoFocus)
        self.post_index_button = QRadioButton(
            self, text='Отображение почтовго индекса')

        self.reset_search_button.clicked.connect(self.reset_search)
        self.search_button.clicked.connect(self.send_search_line)
        self.post_index_button.clicked.connect(self.update_assress)

        main_layout = QHBoxLayout()
        map_layout = QVBoxLayout()
        settings_layout = QVBoxLayout()
        map_layout.addWidget(self.map_label)
        settings_layout.addWidget(self.search_line)
        settings_layout.addWidget(self.search_button)
        settings_layout.addWidget(self.reset_search_button)
        settings_layout.addWidget(self.address_text_string)
        settings_layout.addWidget(self.post_index_button)
        main_layout.addLayout(settings_layout)
        main_layout.addLayout(map_layout)

        self.setLayout(main_layout)

        self.uc = uc

        self.map_params = MapParams()

        self.show_map()

    def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        key = event.key()
        if key == Qt.Key_PageUp:
            self.map_params.up_zoom()
        elif key == Qt.Key_PageDown:
            self.map_params.down_zoom()
        elif key == Qt.Key_Up:
            self.map_params.up()
        elif key == Qt.Key_Down:
            self.map_params.down()
        elif key == Qt.Key_Left:
            self.map_params.left()
        elif key == Qt.Key_Right:
            self.map_params.right()
        elif key == Qt.Key_M:
            self.map_params.change_l()

        self.show_map()

    def show_map(self):
        map = self.uc.execute(self.map_params)

        pixmap = QPixmap()
        pixmap.loadFromData(map, self.map_params.get_format())
        self.map_label.setPixmap(pixmap)

    def send_search_line(self):
        # чтобы сбросить выделение с ввода текста надо нажать поиск
        if self.search_line.text() == '':
            return None
        self.map_params.clear_points()
        response = self.uc.search_pos(self.search_line.text())
        self.map_params.set_pos(response)
        self.map_params.add_point(response)
        self.search_line.clearFocus()
        self.show_map()
        response_address = self.uc.get_address(
            self.search_line.text(), self.post_index_button.isChecked())
        self.map_params.set_address(self.address_text_string, response_address)

    def reset_search(self):
        self.map_params.clear_points()
        self.show_map()
        self.map_params.clear_address(self.address_text_string)

    def update_assress(self):
        if self.post_index_button.isChecked():
            self.send_search_line()
        else:
            self.map_params.reset_index(self.address_text_string)
Beispiel #10
0
 def __init__(self):
     self.map_params = MapParams()
Beispiel #11
0
 def execute(self, param: MapParams):
     return self.map_service.get_map(param.get_longitude(),
                                     param.get_latitude(), param.get_zoom(),
                                     param.get_l(), param.get_points())