【问题标题】:Change marker in folium map叶子地图中的更改标记
【发布时间】:2015-11-06 20:17:48
【问题描述】:

我有一个脚本可以通过 folium 在地图上绘制多个点。有没有办法改变标记的形状和颜色?

不管是通过python代码还是html file都可以。

import folium
import json


map_osm = folium.Map(location=[37.7622, -122.4356], zoom_start=13)

geojson = {
    "type": "Feature",
    "geometry": {
        "type": "MultiPoint",
        "coordinates": [[-122.42436302145, 37.8004143219856], [-122.42699532676599, 37.80087263276921]],
    },
    "properties": {"prop0": "value0"}
}

map_osm.geo_json(geo_str=json.dumps(geojson))
map_osm.create_map(path='osm.html')

【问题讨论】:

    标签: javascript python leaflet folium


    【解决方案1】:

    以下是我用点绘制的方法。我实际上是在尝试整理一个notebook of examples (adding color, popup, etc),尽管我仍在解决问题。

    import folium
    import pandas as pd
    
    #create a map
    this_map = folium.Map(prefer_canvas=True)
    
    def plotDot(point):
        '''input: series that contains a numeric named latitude and a numeric named longitude
        this function creates a CircleMarker and adds it to your this_map'''
        folium.CircleMarker(location=[point.latitude, point.longitude],
                            radius=2,
                            weight=0).add_to(this_map)
    
    #use df.apply(,axis=1) to "iterate" through every row in your dataframe
    data.apply(plotDot, axis = 1)
    
    
    #Set the zoom to the maximum possible
    this_map.fit_bounds(this_map.get_bounds())
    
    #Save the map to an HTML file
    this_map.save('html_map_output/simple_dot_plot.html')
    
    this_map
    

    您也可以使用polygon markers that this guy shows off

    【讨论】:

      【解决方案2】:

      你可以试试这样的:

      for i in range(0,len(data)):
      folium.Marker([data['lat'][i], data['long'][i]],
                #Make color/style changes here
                icon = folium.Icon(color='green'),
                ).add_to(map_1)
      

      【讨论】:

        【解决方案3】:

        您可能会发现单独创建标记比先构建 GeoJSON 对象更容易。根据示例,这很容易让您能够设置它们的样式:

        map_1 = folium.Map(location=[45.372, -121.6972], zoom_start=12,tiles='Stamen Terrain')
        map_1.simple_marker([45.3288, -121.6625], popup='Mt. Hood Meadows',marker_icon='cloud')
        

        【讨论】:

        • 我刚刚为这个问题创建了一个示例,我的实际数据包含两千多个点。
        猜你喜欢
        • 1970-01-01
        • 2018-11-12
        • 2013-02-25
        • 2019-09-18
        • 2019-09-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-20
        相关资源
        最近更新 更多