无法使用小叶更改带有时间戳的geojson标记的颜色

问题描述 投票:0回答:1

我创建了一个带有时间戳的geojson文件,以在地图中绘制标记,如下所示:

def create_geojson_features(df):
    features = []
    for lat,lan,intensity,time in zip(df['latitude'],df['longitude'],df['intensity'],df['timestamp']):

        time = str(time)
        feature = {
            'type': 'Feature',
            'geometry': {
                'type':'Point', 
                'coordinates':[lan,lat]
            },
            'properties': {'time':time,'marker-color':'red','iconstyle':{'marker-color':'red'}

            }
        }
        features.append(feature)
    return features
features = create_geojson_features(df)





from folium.plugins import TimestampedGeoJson
m = folium.Map([latmean,lonmean], zoom_start=11)
TimestampedGeoJson(
        {'type': 'FeatureCollection',
        'features': features}
        , period='PT1H'
        , duration= 'PT1H'
        , add_last_point=True
        , auto_play=False
        , loop=False
        , max_speed=1
        , loop_button=True
        , date_options='YYYY/MM/DD HH:mm:ss'
        , time_slider_drag_update=True
    ).add_to(m)

我尝试了类似'style','iconColor'的其他操作,但似乎不起作用,我在每个标记中获得的唯一颜色是蓝色。您能帮忙吗?

python folium
1个回答
0
投票

一个选项将转换

  • [geometry.type toLineStringfrom Point如果仅包含LineString类型的特征,则带有时间戳,MultiPointMultiLineStringPolygonMultiPolygon)。

  • [icon键的值到circle

    import folium
    from folium import plugins
    
    m = folium.Map(
        location=[40.000000, 32.000000],
        zoom_start=12
    )
    
    points = [
        {
            'coordinates': [
                [32.000000, 40.000000],
            ],
            'times': [
                '2017-06-02T00:00:00',
                '2017-06-02T00:10:00'
            ],
            'color': 'yellowgreen'
        },
        {
            'coordinates': [
                [32.000100, 40.060600],
            ],
            'times': [
                '2020-03-30T06:10:00',
                '2020-03-31T07:20:00'
            ],
            'color': 'red'
        },
    ]
    
    features = [
        {
            'type': 'Feature',
            'geometry': {
                'type': 'LineString',
                'coordinates': point['coordinates'],
            },
            'properties': {
                'time': point['times'],
                'icon': 'circle',
                'iconstyle': {'color':point['color']}
            }
        }
        for point in points
    ]
    
    plugins.TimestampedGeoJson({
        'type': 'FeatureCollection',
        'features': features,
    }, period='PT1M', add_last_point=True).add_to(m)
    
    m.save('map.html')
    
© www.soinside.com 2019 - 2024. All rights reserved.