def show_map(ll, z, _map_type='map', add_params=None): global map_type, flag_update_map global _lon, _lat flag_update_map = False map_type = _map_type pygame.init() screen = pygame.display.set_mode((600, 540)) _z = z _lon, _lat = map(float, ll.split(',')) buttons_viev = DivButtons( ButtonFlag((545, 465), buts, func=lambda: chance_viev('map'), text='Схема', text_size=23, name='but_satellite', shift_text=(-4, 0)), ButtonFlag((545, 495), buts, func=lambda: chance_viev('sat'), text='Спутник', text_size=23, name='but_scheme', shift_text=(4, 0)), ButtonFlag((545, 525), buts, func=lambda: chance_viev('sat,skl'), text='Гибрид', text_size=23, name='but_gibrid', shift_text=(3, 0))) buttons_viev.elements[0].states['clicked'] = True GUI.add_element(buttons_viev) search_div = Div( TextBox((40, 5, 400, 30), '', default_text='Введите адрес...', name='tb_address'), Button('Поиск', (495, 21), (100, 30), lambda: get_coord('_lon', '_lat', 'tb_address'), 'but_search', but_color=(255, 255, 255), hovered=(190, 190, 190), size_font=24, shift_text=(21, 7))) GUI.add_element(search_div) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) clock = pygame.time.Clock() while True: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: os.remove(map_file) pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_PAGEUP: if _z - 1 >= 2: _z -= 1 map_file = update_static( ','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_PAGEDOWN: if _z + 1 <= 17: _z += 1 map_file = update_static( ','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_RIGHT: _lon += 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_LEFT: _lon -= 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_UP: _lat += 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_DOWN: _lat -= 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) GUI.apply_event(event) clock.tick(60) if flag_update_map: map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) flag_update_map = False screen.blit(pygame.image.load(map_file), (0, 0)) GUI.update() GUI.render(screen) pygame.display.flip()
def show_map(ll="37.620070,55.756640", z=16, _map_type='map', add_params=None): global map_type, flag_update_map, address, postcode global _lat, _lon, _pt flag_update_map = False postcode = '' address = None map_type = _map_type last_type = _map_type pygame.init() screen = pygame.display.set_mode((600, 540)) _z = z _lat, _lon = map(float, ll.split(',')) _pt = add_params _tb_info = TextBlock((2, 452, 490, 86), [], 24, text_color=(77, 81, 83), bg_color=(255, 255, 255), name='tb_info') GUI.add_element(_tb_info) buttons_view = DivButtons( ButtonFlag((545, 465), buts, func=lambda: change_view('map'), text='Схема', text_size=23, name='but_satellite', shift_text=(-4, 0)), ButtonFlag((545, 495), buts, func=lambda: change_view('sat'), text='Спутник', text_size=23, name='but_scheme', shift_text=(4, 0)), ButtonFlag((545, 525), buts, func=lambda: change_view('sat,skl'), text='Гибрид', text_size=23, name='but_gibrid', shift_text=(3, 0))) buttons_view.elements[0].states['clicked'] = True GUI.add_element(buttons_view) search = TextBox((40, 5, 400, 30), '', default_text='Введите адрес...', name='tb_address') search_div = Div( search, Button('X', (425, 21), (29, 28), lambda: clear_search(search, _tb_info), 'delete', but_color=(255, 255, 255), hovered=(190, 190, 190), size_font=24, shift_text=(10, 7)), Button('Поиск', (500, 21), (100, 30), lambda: get_coord('_lat', '_lon', 'tb_address', text_block=_tb_info, switch=switch.on), 'but_search', but_color=(255, 255, 255), hovered=(190, 190, 190), size_font=24, shift_text=(21, 7))) GUI.add_element(search_div) switch = Switch( (411, 512, 40, 25), 'Индекс', color_switch=(62, 151, 209), color_background=(240, 248, 255), color_background_on=(240, 248, 255), func=lambda: post_code(switch.on, globals()['address'], _tb_info.text)) GUI.add_element(switch) map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) clock = pygame.time.Clock() while True: screen.fill((254, 202, 131)) for event in pygame.event.get(): if event.type == pygame.QUIT: os.remove(map_file) pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_PAGEUP or event.key == pygame.K_w: if _z - 1 >= 2: _z -= 1 map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: _z += 1 map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) elif event.key == pygame.K_PAGEDOWN or event.key == pygame.K_s: if _z + 1 <= 17: _z += 1 map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: _z -= 1 map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) elif event.key == pygame.K_RIGHT: _lat += 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: _lat -= 422.4 / (2**(_z - 1)) map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) elif event.key == pygame.K_LEFT: _lat -= 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: _lat += 422.4 / (2**(_z - 1)) map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) elif event.key == pygame.K_UP: _lon += 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: _lon -= 178.25792 / (2**(_z - 1)) map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) elif event.key == pygame.K_DOWN: _lon -= 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: _lon += 178.25792 / (2**(_z - 1)) map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) elif event.type == pygame.MOUSEBUTTONDOWN: pos = event.pos if 40 < pos[1] < 450: try: x_k = (422.4 / (2**(_z - 1))) / 600 y_k = (178.25792 / (2**(_z - 1))) / 450 x, y = pos[0] - 300, 225 - pos[1] lat, lon = _lat + x * x_k, _lon + y * y_k clear_search(search, _tb_info) address = get_address(','.join([str(lat), str(lon)])).split(', ') _tb_info.text = [address[0], ', '.join(address[1:])] post_code(switch.on, ','.join([str(lat), str(lon)]), _tb_info.text) _pt = 'pt={},{},pm2rdm'.format(lat, lon) map_file = update_static( ','.join([str(_lat), str(_lon)]), _z, map_type, _pt) except Exception as e: print('Невозможно поставить метку') GUI.apply_event(event) if flag_update_map: map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) if not map_file: map_type = last_type map_file = update_static(','.join([str(_lat), str(_lon)]), _z, map_type, _pt) buttons_view.elements[0].states['clicked'] = True buttons_view.elements[1].states['clicked'] = False else: last_type = map_type flag_update_map = False screen.blit(pygame.image.load(map_file), (0, 0)) GUI.update() GUI.render(screen) pygame.display.flip()
def show_map(ll, z, _map_type='map', add_params=None): global map_type, flag_update_map, address, postcode global _lon, _lat, _pt flag_update_map = False postcode = None address = None map_type = _map_type pygame.init() screen = pygame.display.set_mode((600, 540)) _z = z _lon, _lat = map(float, ll.split(',')) _pt = add_params _tb_info = TextBlock((2, 452, 490, 86), [], 24, text_color=(77, 81, 83), bg_color=(255, 255, 255), name='tb_info') GUI.add_element(_tb_info) buttons_view = DivButtons( ButtonFlag((545, 465), buts, func=lambda: change_view('map'), text='Схема', text_size=23, name='but_satellite', shift_text=(-4, 0)), ButtonFlag((545, 495), buts, func=lambda: change_view('sat'), text='Спутник', text_size=23, name='but_scheme', shift_text=(4, 0)), ButtonFlag((545, 525), buts, func=lambda: change_view('sat,skl'), text='Гибрид', text_size=23, name='but_gibrid', shift_text=(3, 0))) buttons_view.elements[0].states['clicked'] = True GUI.add_element(buttons_view) search = TextBox((40, 5, 400, 30), '', default_text='Введите адрес...', name='tb_address') search_div = Div( search, Button('X', (425, 21), (29, 28), lambda: clear_search(search, _tb_info), 'delete', but_color=(255, 255, 255), hovered=(190, 190, 190), size_font=24, shift_text=(10, 7)), Button('Поиск', (500, 21), (100, 30), lambda: get_coord('_lon', '_lat', 'tb_address', text_block=_tb_info, switch=switch.on), 'but_search', but_color=(255, 255, 255), hovered=(190, 190, 190), size_font=24, shift_text=(21, 7))) GUI.add_element(search_div) switch = Switch((411, 512, 40, 25), 'Индекс', color_switch=(62, 151, 209), color_background=(240, 248, 255), color_background_on=(240, 248, 255), func=lambda: post_code(switch.on, globals()['address']) ) # func = lambda: get_post_code() globals()['address'] GUI.add_element(switch) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type, _pt) clock = pygame.time.Clock() while True: screen.fill((254, 202, 131)) for event in pygame.event.get(): if event.type == pygame.QUIT: os.remove(map_file) pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_PAGEUP or event.key == pygame.K_w: if _z - 1 >= 2: _z -= 1 map_file = update_static( ','.join([str(_lon), str(_lat)]), _z, map_type, _pt) elif event.key == pygame.K_PAGEDOWN or event.key == pygame.K_s: if _z + 1 <= 17: _z += 1 map_file = update_static( ','.join([str(_lon), str(_lat)]), _z, map_type, _pt) elif event.key == pygame.K_RIGHT: _lon += 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type, _pt) elif event.key == pygame.K_LEFT: _lon -= 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type, _pt) elif event.key == pygame.K_UP: _lat += 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type, _pt) elif event.key == pygame.K_DOWN: _lat -= 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type, _pt) GUI.apply_event(event) clock.tick(60) if flag_update_map: map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type, _pt) flag_update_map = False screen.blit(pygame.image.load(map_file), (0, 0)) GUI.update() GUI.render(screen) pygame.display.flip()
def show_map(ll, z, _map_type='map', add_params=None): global map_type, flag_update_map global _lon, _lat flag_update_map = False map_type = _map_type pygame.init() screen = pygame.display.set_mode((600, 540)) _z = z _lon, _lat = map(float, ll.split(',')) #GUI.add_element(Button('Карта', (50, 465), (100, 26), lambda: chance_viev('map'), 'test_but', hovered=(180, 180, 180), # size_font=30)) #GUI.add_element(Button('Спутник', (50, 495), (100, 26), lambda: chance_viev('sat'), 'test_but', hovered=(180, 180, 180), # size_font=30)) #GUI.add_element(Button('Гидрид', (50, 525), (100, 26), lambda: chance_viev('sat,skl'), 'test_but', hovered=(180, 180, 180), # size_font=30)) buttons_viev = DivButtons( ButtonFlag((545, 465), buts, func=lambda: chance_viev('map'), text='Схема', text_size=23, name='but_satellite', shift_text=(-4, 0)), ButtonFlag((545, 495), buts, func=lambda: chance_viev('sat'), text='Спутник', text_size=23, name='but_scheme', shift_text=(4, 0)), ButtonFlag((545, 525), buts, func=lambda: chance_viev('sat,skl'), text='Гибрид', text_size=23, name='but_gibrid', shift_text=(3, 0))) buttons_viev.elements[0].states['clicked'] = True GUI.add_element(buttons_viev) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) timer = 10 clock = pygame.time.Clock() while True: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: os.remove(map_file) pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_PAGEUP: if _z - 1 >= 2: _z -= 1 map_file = update_static(ll, _z, map_type) elif event.key == pygame.K_PAGEDOWN: if _z + 1 <= 17: _z += 1 map_file = update_static(ll, _z, map_type) elif event.key == pygame.K_RIGHT: _lon += 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_LEFT: _lon -= 422.4 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_UP: _lat += 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) elif event.key == pygame.K_DOWN: _lat -= 178.25792 / (2**(_z - 1)) map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) GUI.apply_event(event) if flag_update_map: map_file = update_static(','.join([str(_lon), str(_lat)]), _z, map_type) flag_update_map = False clock.tick(60) timer -= 1 if timer == 0: timer = 30 screen.blit(pygame.image.load(map_file), (0, 0)) GUI.update() GUI.render(screen) pygame.display.flip()