File size: 2,137 Bytes
01142fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890c31a
01142fd
 
 
 
 
890c31a
 
01142fd
 
 
 
890c31a
01142fd
 
 
 
 
890c31a
01142fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890c31a
01142fd
 
 
 
 
 
 
890c31a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
import pandas as pd
import plotly.graph_objects as go

def preprocess_df(df):
    """
    Убрать строки без координат, преобразовать координаты в float.
    """
    no_coords = df['latitude'] == ''
    df = df.drop(df[no_coords].index)
    df['latitude'] = df['latitude'].astype('float')
    df['longitude'] = df['longitude'].astype('float')
    return df

def plot_map(landmarks):
    # Загрузка данных
    data = pd.DataFrame(landmarks)
    data = preprocess_df(data)

    # Создание маркеров
    marker_size = 12  # Размер маркера

    fig = go.Figure()

    marker_colors = ['orange', 'purple', 'red', 'green']

    for i, row in data.iterrows():
        if type(row['latitude']) is not float:
            continue
        fig.add_trace(go.Scattermapbox(
            name=row['find'],
            lat=[row['latitude']],
            lon=[row['longitude']],
            mode='markers',
            marker=dict(
                size=marker_size,
                color=marker_colors[i % len(marker_colors)],
                sizemode='diameter',  # Размер маркера в диаметрах
            ),
            text=row['find']
        ))

    # Вычисление границы области, содержащей все маркеры
    min_lat, max_lat = data['latitude'].min(), data['latitude'].max()
    min_lon, max_lon = data['longitude'].min(), data['longitude'].max()

    # Рассчитываем центр и масштаб для отображения всех маркеров
    center_lat = (min_lat + max_lat) / 2
    center_lon = (min_lon + max_lon) / 2
    zoom_level = 12  # Масштаб (может потребоваться настройка)

    # Настройка карты
    fig.update_layout(
        mapbox_style="carto-darkmatter",
        mapbox=dict(
            center=dict(lat=center_lat, lon=center_lon),
            zoom=zoom_level,
        ),
    )

    # Отображение карты в Streamlit
    st.plotly_chart(fig, use_container_width=True)