Beispiel #1
0
def main():
    toponym_to_find = " ".join(sys.argv[1:])

    if toponym_to_find:
        # Показываем карту с фиксированным масштабом.
        lat, lon = get_coordinates(toponym_to_find)
        ll_spn = f"ll={lat},{lon}&spn=0.005,0.005"
        show_map(ll_spn, "map")

        # Показываем карту с масштабом, подобранным по заданному объекту.
        ll, spn = get_ll_span(toponym_to_find)
        ll_spn = f"ll={ll}&spn={spn}"
        show_map(ll_spn, "map")

        # Добавляем исходную точку на карту.
        point_param = f"pt={ll}"
        show_map(ll_spn, "map", add_params=point_param)
    else:
        print('No data')
def main():
    towns = [
        "Ярославль",
        "Нижний Новгород",
        "Казань",
        "Великий Новгород",
        "Архангельск",
        "Саратов",
        "Петрозаводск",
        "Астрахань"
    ]
    random.shuffle(towns)

    for town in towns:
        # Показываем карту с масштабом, подобранным по заданному объекту.
        ll, spn = get_ll_span(town)
        map_type = "sat"
        if random.random() > 0.5:
            spn = "0.001,0.001"
            map_type = "map"
        ll_spn = "ll={ll}&spn={spn}".format(**locals())
        show_map(ll_spn, map_type)
Beispiel #3
0
def main():
    global flag
    pygame.font.init()
    font = pygame.font.Font(None, 32)
    fond_for_err = pygame.font.Font(None, 16)
    input_box = pygame.Rect(5, 5, 140, 32)
    clear_buton = pygame.Rect(5, 43, 110, 24)
    color_inactive = pygame.Color('lightskyblue3')
    color_active = pygame.Color('black')
    color = color_inactive
    active = False
    text = ''
    end_text = font.render('', True, color)
    step = 0.006
    # Показываем карту с фиксированным масштабом.
    ll_spn = f"ll={res.coord_x},{res.coord_y}&z={res.zoom}&l={res.type_map}"
    x, y, zoom, type_map = res.coord_x, res.coord_y, res.zoom, res.type_map
    show_map_yandex(ll_spn, "map")
    map_file = "map.png"
    types = ['map', 'sat', 'sat,skl']
    info = ''
    point_param = ''
    # Инициализируем pygame
    looping = True
    count = types.index(type_map)
    while looping:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                looping = False
            if event.type == pygame.MOUSEBUTTONDOWN:
                if input_box.collidepoint(event.pos):
                    # Toggle the active variable.
                    active = not active
                else:
                    active = False
                if clear_buton.collidepoint(event.pos):
                    point_param = ''
                    flag = False
                    show_map_yandex(ll_spn, "map")
                # Change the current color of the input box.
                color = color_active if active else color_inactive
            if event.type == pygame.KEYDOWN:
                if active:
                    if event.key == pygame.K_RETURN:
                        toponym_to_find = text
                        ll = get_ll_span(toponym_to_find)
                        ll_spn = f"ll={ll}&z={zoom}&l={type_map}"
                        if try_to(ll_spn, "map"):
                            # Показываем карту с масштабом, подобранным по заданному объекту.
                            show_map_yandex(ll_spn, "map")
                            x, y = get_coordinates(text)
                            # Добавляем исходную точку на карту.
                            point_param = f"pt={ll}"
                            print(point_param)
                            show_map_yandex(ll_spn,
                                            "map",
                                            add_params=point_param)
                            end_text = fond_for_err.render(
                                '', True, (255, 0, 0))
                            info = get_address(text)
                            flag = True
                        else:
                            end_text = fond_for_err.render(
                                'Введите корректное имя поиска', True,
                                (255, 0, 0))
                        text = ''
                    elif event.key == pygame.K_BACKSPACE:
                        text = text[:-1]
                    else:
                        text += event.unicode
            key = pygame.key.get_pressed()
            if key[pygame.K_PAGEUP]:
                zoom = zoom + 1 if zoom + 1 < 20 else zoom
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)
            if key[pygame.K_PAGEDOWN]:
                zoom = zoom - 1 if zoom - 1 > 0 else zoom
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)
            if key[pygame.K_UP]:
                y += step * math.pow(2, 15 - zoom)
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)
            if key[pygame.K_DOWN]:
                y -= step * math.pow(2, 15 - zoom)
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)
            if key[pygame.K_RIGHT]:
                x += step * math.pow(2, 15 - zoom)
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)
            if key[pygame.K_LEFT]:
                x -= step * math.pow(2, 15 - zoom)
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)
            if key[pygame.K_HOME]:
                count = (count + 1) % 3
                type_map = types[count]
                ll_spn = f"ll={x},{y}&z={zoom}&l={type_map}"
                show_map_yandex(ll_spn, "map", add_params=point_param)

        # Инициализируем pygame
        # Рисуем картинку, загружаемую из только что созданного файла.
        screen.blit(pygame.image.load(map_file), (0, 0))
        txt_surface = font.render(text, True, color)
        # Resize the box if the text is too long.
        width = max(200, txt_surface.get_width() + 10)
        input_box.w = width
        # Blit the text.
        screen.blit(txt_surface, (input_box.x + 5, input_box.y + 5))
        # Blit the input_box rect
        pygame.draw.rect(screen, color, input_box, 1)
        pygame.draw.rect(screen, (200, 200, 200), clear_buton)
        screen.blit(
            pygame.font.Font(None, 16).render('Сбросить метку', True,
                                              (0, 0, 0)),
            (clear_buton.x + 5, clear_buton.y + 5))
        screen.blit(end_text, [350, 430])
        if flag:
            write_info(info)
        # Переключаем экран и ждем закрытия окна.
        pygame.display.flip()
        pygame.display.update()
    pygame.quit()
    # Удаляем за собой файл с изображением.
    os.remove(map_file)
Beispiel #4
0
from Samples.geocoder import get_ll_span
from Samples.mapapi_PG import show_map
coords = input('Введите координаты через запятую без пробела: ')
ll, spn = get_ll_span(coords)
show_map(f'll={ll}&spn={spn}')