如何在Python中循环遍历GeoJSON属性以生成HTML弹出格式(使用folium/geopandas)

huangapple go评论71阅读模式
英文:

How to loop geojson properties for HTML pop up format in Python (folium/geopandas)

问题

我想使用HTML在Folium中创建一个表格弹出窗口。一切都很好,直到我意识到我的块名称错误,似乎我的循环也是错误的。这是我得到的内容:

# 在表格弹出窗口上设置样式
def popup_html_block(row):
    i = row
    block_name = All_Blocks['Block_Name'].iloc[i]
    status = All_Blocks['Status'].iloc[i]
    operator = All_Blocks['Operator'].iloc[i]
    kilo = All_Blocks['Sq. Kilometers'].iloc[i]
    miles = All_Blocks['Sq. Miles'].iloc[i]
    left_col_color = "#65b3d0"
    right_col_color = "#ebf2f7"

    html = """<!DOCTYPE html>
    <html>

    <head>
    <h4 style="margin-bottom:10"; width="200px">{}</h4>""".format(block_name) + """
    
    </head>
    <table style="height: 126px; width: 350px;">
    <tbody>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Status</span></td>
    <td style="width: 150px;background-color: """ + right_col_color + """;">{}""".format(status) + """
    </tr>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Operator</span></td>
    <td style="width: 150px;background-color: """ + right_col_color + """;">{}""".format(operator) + """
    </tr>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Sq. Kilometers</span></td>
    <td style="width: 150px;background-color: """ + right_col_color + """;">{}""".format(kilo) + """
    </tr>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Sq. Miles</span></td>
    <td style="width: 150px;background-color: """ + right_col_color + """;">{}""".format(miles) + """
    </tr>
    </tbody>
    </table>
    </html>
    """

    return html

# 将ESRI卫星图层添加到地图
tile = folium.TileLayer(
    tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
    attr='Esri',
    name='Esri Satellite',
    overlay=False,
    control=False
).add_to(map1)

# 在主地图的右下角放置一个迷你地图(可选,可以关闭),以及其他插件,如滚动缩放切换器、全屏等
minimap = plugins.MiniMap(toggle_display=True)
map1.add_child(minimap)
plugins.ScrollZoomToggler().add_to(map1)
plugins.Fullscreen(position="topright").add_to(map1)
plugins.Draw(position='topright').add_to(map1)

# 将块添加到主地图
for i in range(0, len(All_Blocks)):
    html = popup_html_block(i)
    iframe = branca.element.IFrame(html=html, width=500, height=200)
    popup = folium.Popup(folium.Html(html, script=True), max_width=500)

    folium.GeoJson(data=All_Blocks,
                    style_function=lambda feature: {
                        'fillColor':  '#65b3d0',
                        'color': 'black',
                        'weight': 3,
                        'fillOpacity': 0.2,
                        'dashArray': '5,5'
                    },

                    highlight_function=lambda x: {
                        'fillOpacity': 1},

                    tooltip=folium.features.GeoJsonTooltip(
                        fields=['Block_Name'], aliases=['Name']),

                    popup=popup).add_to(map1)

我的地理JSON虚拟数据:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Block_Name":"East-Block","Status":"Production","Operator":"A","Sq. Kilometers":145.97,"Sq. Miles":56.36},"geometry":{"coordinates":[[[96.4001057373053,5.208656351062942],[96.43375136718726,5.221648609300516],[96.46259047851515,5.23737571951817],[96.46121718750072,5.279084831409563],[96.35684707031174,5.279768564031215],[96.35753371582075,5.340617736210092],[96.26140334472717,5.341985064196123],[96.26140334472717,5.261307518914151],[96.32663466796942,5.23053789406255],[96.4001057373053,5.208656351062942]]],"type":"Polygon"}},{"type":"Feature","properties":{"Block_Name":"West-Block","Status":"Production","Operator":"B","Sq. Kilometers":171.38,"Sq. Miles":66.17},"geometry":{"coordinates":[[[96.1500638674625,5.274467547614364],[96.14897384519247,5.419171436272961],[96.01490110586337,5.42134172287426],[96.01526444661994,5.383360416138984],[96.07521567152321,5.3826369393847955],[96.07557901227983,5.355867695999478],[96.03488484749829,5.355867696870973],[96.03452150673985,5.334162042989206],[96.0501451592911,5.327288425995064],[96.06431544881394,5.305219978512483],[96.07812239757834,5.292557397961701],[96.10500961359554,5.285683317057433],[96.13117014809939,5.279894558164472],[96.14025366702509,5.278809159853225],[96.1500638674625,5.274467547614364]]],"type":"Polygon"}},{"type":"Feature","properties":{"Block_Name":"South-Block","Status":"Exploration","Operator":"A","Sq. Kilometers":48.74,"Sq. Miles":18.82},"geometry":{"coordinates":[[[96.15020619743746,5.321413143458614],[96.15075239154925,5.274369183512903],[96.15921840028875,5.

<details>
<summary>英文:</summary>

So I want to build a table pop up using HTML in Folium. Everything is fine until I realize my block name is wrong, and it seems like my looping is false. Here&#39;s what I got

       # styling on tables pop up
        def popup_html_block(row):
            i = row
            block_name = All_Blocks[&#39;Block_Name&#39;].iloc[i]
            status = All_Blocks[&#39;Status&#39;].iloc[i]
            operator = All_Blocks[&#39;Operator&#39;].iloc[i]
            kilo = All_Blocks[&#39;Sq. Kilometers&#39;].iloc[i]
            miles = All_Blocks[&#39;Sq. Miles&#39;].iloc[i]
            left_col_color = &quot;#65b3d0&quot;
            right_col_color = &quot;#ebf2f7&quot;
    
            html = &quot;&quot;&quot;&lt;!DOCTYPE html&gt;
            &lt;html&gt;
            
            &lt;head&gt;
            &lt;h4 style=&quot;margin-bottom:10&quot;; width=&quot;200px&quot;&gt;{}&lt;/h4&gt;&quot;&quot;&quot;.format(block_name) + &quot;&quot;&quot;
            
            &lt;/head&gt;
                &lt;table style=&quot;height: 126px; width: 350px;&quot;&gt;
            &lt;tbody&gt;
            &lt;tr&gt;
            &lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Status&lt;/span&gt;&lt;/td&gt;
            &lt;td style=&quot;width: 150px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(status) + &quot;&quot;&quot;
            &lt;/tr&gt;
            &lt;tr&gt;
            &lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Operator&lt;/span&gt;&lt;/td&gt;
            &lt;td style=&quot;width: 150px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(operator) + &quot;&quot;&quot;
            &lt;/tr&gt;
            &lt;tr&gt;
            &lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Sq. Kilometers&lt;/span&gt;&lt;/td&gt;
            &lt;td style=&quot;width: 150px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(kilo) + &quot;&quot;&quot;
            &lt;/tr&gt;
            &lt;tr&gt;
            &lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Sq. Miles&lt;/span&gt;&lt;/td&gt;
            &lt;td style=&quot;width: 150px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(miles) + &quot;&quot;&quot;
            &lt;/tr&gt;
            &lt;/tbody&gt;
            &lt;/table&gt;
            &lt;/html&gt;
            &quot;&quot;&quot;
    
            return html
    
    # Put ESRI Satellite for the layer map
            tile = folium.TileLayer(
                tiles=&#39;https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}&#39;,
                attr=&#39;Esri&#39;,
                name=&#39;Esri Satellite&#39;,
                overlay=False,
                control=False
            ).add_to(map1)
    
            # put a minimap on bottom corner of the main map (optional, can be turned off) and other plugins such as szroll zoom toggler, fullscreen, etc
            minimap = plugins.MiniMap(toggle_display=True)
            map1.add_child(minimap)
            plugins.ScrollZoomToggler().add_to(map1)
            plugins.Fullscreen(position=&quot;topright&quot;).add_to(map1)
            plugins.Draw(position=&#39;topright&#39;).add_to(map1)
    
            # Adding blocks to the main map
            for i in range(0, len(All_Blocks)):
                html = popup_html_block(i)
                iframe = branca.element.IFrame(html=html, width=500, height=200)
                popup = folium.Popup(folium.Html(html, script=True), max_width=500)
    
            folium.GeoJson(data=All_Blocks,
                            style_function=lambda feature: {
                                &#39;fillColor&#39;:  &#39;#65b3d0&#39;,
                                #    &#39;fillColor&#39;: &#39;#F1D581&#39; if &#39;x&#39; in feature[&#39;properties&#39;][&#39;Status&#39;] == &#39;Exploration&#39; else &#39;#65b3d0&#39;,
                                &#39;color&#39;: &#39;black&#39;,
                                &#39;weight&#39;: 3,
                                &#39;fillOpacity&#39;: 0.2,
                                &#39;dashArray&#39;: &#39;5,5&#39;
                            },
    
                            highlight_function=lambda x: {
                                &#39;fillOpacity&#39;: 1},
    
                            tooltip=folium.features.GeoJsonTooltip(
                                fields=[&#39;Block_Name&#39;], aliases=[&#39;Name&#39;]),
    
                            popup=popup).add_to(map1)
my geo json dummy data :

    {&quot;type&quot;:&quot;FeatureCollection&quot;,&quot;features&quot;:[{&quot;type&quot;:&quot;Feature&quot;,&quot;properties&quot;:{&quot;Block_Name&quot;:&quot;East-Block&quot;,&quot;Status&quot;:&quot;Production&quot;,&quot;Operator&quot;:&quot;A&quot;,&quot;Sq. Kilometers&quot;:145.97,&quot;Sq. Miles&quot;:56.36},&quot;geometry&quot;:{&quot;coordinates&quot;:[[[96.4001057373053,5.208656351062942],[96.43375136718726,5.221648609300516],[96.46259047851515,5.23737571951817],[96.46121718750072,5.279084831409563],[96.35684707031174,5.279768564031215],[96.35753371582075,5.340617736210092],[96.26140334472717,5.341985064196123],[96.26140334472717,5.261307518914151],[96.32663466796942,5.23053789406255],[96.4001057373053,5.208656351062942]]],&quot;type&quot;:&quot;Polygon&quot;}},{&quot;type&quot;:&quot;Feature&quot;,&quot;properties&quot;:{&quot;Block_Name&quot;:&quot;West-Block&quot;,&quot;Status&quot;:&quot;Production&quot;,&quot;Operator&quot;:&quot;B&quot;,&quot;Sq. Kilometers&quot;:171.38,&quot;Sq. Miles&quot;:66.17},&quot;geometry&quot;:{&quot;coordinates&quot;:[[[96.1500638674625,5.274467547614364],[96.14897384519247,5.419171436272961],[96.01490110586337,5.42134172287426],[96.01526444661994,5.383360416138984],[96.07521567152321,5.3826369393847955],[96.07557901227983,5.355867695999478],[96.03488484749829,5.355867696870973],[96.03452150673985,5.334162042989206],[96.0501451592911,5.327288425995064],[96.06431544881394,5.305219978512483],[96.07812239757834,5.292557397961701],[96.10500961359554,5.285683317057433],[96.13117014809939,5.279894558164472],[96.14025366702509,5.278809159853225],[96.1500638674625,5.274467547614364]]],&quot;type&quot;:&quot;Polygon&quot;}},{&quot;type&quot;:&quot;Feature&quot;,&quot;properties&quot;:{&quot;Block_Name&quot;:&quot;South-Block&quot;,&quot;Status&quot;:&quot;Exploration&quot;,&quot;Operator&quot;:&quot;A&quot;,&quot;Sq. Kilometers&quot;:48.74,&quot;Sq. Miles&quot;:18.82},&quot;geometry&quot;:{&quot;coordinates&quot;:[[[96.15020619743746,5.321413143458614],[96.15075239154925,5.274369183512903],[96.15921840028875,5.269746173698309],[96.19062456174476,5.259684209917438],[96.21137993801023,5.259140315346897],[96.23814344951205,5.262403675642247],[96.26108360222605,5.263763404046799],[96.26108360222605,5.320325462349771],[96.15020619743746,5.321413143458614]]],&quot;type&quot;:&quot;Polygon&quot;}},{&quot;type&quot;:&quot;Feature&quot;,&quot;properties&quot;:{&quot;Block_Name&quot;:&quot;Center-Block&quot;,&quot;Status&quot;:&quot;Exploration&quot;,&quot;Operator&quot;:&quot;C&quot;,&quot;Sq. Kilometers&quot;:48.74,&quot;Sq. Miles&quot;:18.82},&quot;geometry&quot;:{&quot;coordinates&quot;:[[[96.14996393515247,5.321933704052],[96.26084133994107,5.320846023863609],[96.26138753405411,5.3417835292513445],[96.35451363019473,5.340967795663914],[96.35451363019473,5.36924592531598],[96.29224750139701,5.369789722668301],[96.29197440434115,5.401329137491388],[96.33922019505121,5.401057252985197],[96.33922019505121,5.419001368471612],[96.14887154692752,5.419545121233369],[96.14996393515247,5.321933704052]]],&quot;type&quot;:&quot;Polygon&quot;}},{&quot;type&quot;:&quot;Feature&quot;,&quot;properties&quot;:{&quot;Block_Name&quot;:&quot;North-Block&quot;,&quot;Status&quot;:&quot;Production&quot;,&quot;Operator&quot;:&quot;A&quot;,&quot;Sq. Kilometers&quot;:64.55,&quot;Sq. Miles&quot;:24.92},&quot;geometry&quot;:{&quot;coordinates&quot;:[[[96.08469351270912,5.419774728990944],[96.21141054675434,5.419774728990944],[96.33102705734086,5.41868722339008],[96.33048086322776,5.43826202425123],[96.24745935816333,5.438805759641596],[96.24745935816333,5.451311537935112],[96.30644832228882,5.451855261522326],[96.30590212817572,5.467079321826603],[96.15952210608873,5.466535612046528],[96.16006830020183,5.439893228949643],[96.08523970682091,5.440980696292215],[96.08469351270912,5.419774728990944]]],&quot;type&quot;:&quot;Polygon&quot;}}]}


and here&#39;s the picture

[![enter image description here][1]][1]

[![enter image description here][2]][2]

it seems like it won&#39;t loop row by row, all the pop up are same, any help I would appreciate it. Thanks!


  [1]: https://i.stack.imgur.com/PTVg9.png
  [2]: https://i.stack.imgur.com/rl9Wp.png

</details>


# 答案1
**得分**: 1

我找到了解决方案以下是完整的代码

```python
# styling on tables pop up
def make_popup(df):
    blockname = df["Block_Name"]
    status = df["Status"]
    operator = df["Operator"]
    kilos = df["Sq. Kilometers"]
    miles = df["Sq. Miles"]

    left_col_color = "#65b3d0"
    right_col_color = "#ebf2f7"

    html = """
    <!DOCTYPE html>
    <html>

    <head>
    <strong><h4 style="margin-bottom:30px; width:200px; font-size: 25px;">{}</strong></h4>""".format(blockname) + """
    
    </head>
    <table style="height: 126px; width: 300px;">
    <tbody>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Status</span></td>
    <td style="width: 200px;background-color: """ + right_col_color + """;">{}</td>""".format(status) + """
    </tr>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Operator</span></td>
    <td style="width: 200px;background-color: """ + right_col_color + """;">{}</td>""".format(operator) + """
    </tr>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Sq. Kilometers</span></td>
    <td style="width: 200px;background-color: """ + right_col_color + """;">{}</td>""".format(kilos) + """
    </tr>
    <tr>
    <td style="background-color: """ + left_col_color + """;"><span style="color: #151515;">Sq. Miles</span></td>
    <td style="width: 200px;background-color: """ + right_col_color + """;">{}</td>""".format(miles) + """
    </tr>
    </tbody>
    </table>
    </html>
    """
    return html

map1 = folium.Map(location=location,
                zoom_start=11, control_scale=300, tiles=None)

# Put ESRI Satellite for the layer map
tile = folium.TileLayer(
    tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
    attr='Esri',
    name='Esri Satellite',
    overlay=False,
    control=False
).add_to(map1)

# put a minimap on bottom corner of the main map (optional, can be turned off) and other plugins such as szroll zoom toggler, fullscreen, etc
minimap = plugins.MiniMap(toggle_display=True)
map1.add_child(minimap)
plugins.ScrollZoomToggler().add_to(map1)
plugins.Fullscreen(position="topright").add_to(map1)
plugins.Draw(position='topright').add_to(map1)

def filter_by_name(df, name):
    return df[df['Block_Name'].isin(name)]

# option_block = st.multiselect('Select the block name', (All_Blocks['Block_Name']), default=All_Blocks['Block_Name'])
df_filter = filter_by_name(All_Blocks,All_Blocks['Block_Name'])

# Adding blocks to the main map (UPDATE)
for i, row in df_filter.iterrows():
    geo_json = folium.features.GeoJson(row.geometry.__geo_interface__, name=str(i), 
                                        style_function=
                                        lambda feature: {
                                        'fillColor':  '#65b3d0',
                                        # 'fillColor': '#F1D581' if 'x' in feature['properties']['Status'] == 'Exploration' else '#65b3d0',
                                        'color': 'black',
                                        'weight': 3,
                                        'fillOpacity': 0.2,
                                        'dashArray': '5,5'
                                    },

                                    highlight_function=lambda x: {
                                        'fillOpacity': 1},

                                    tooltip=folium.features.Tooltip(All_Blocks.iloc[i]['Block_Name'], sticky=False))
                                        # fields=All_Blocks.iloc[i]['Block_Name'], aliases=['Name']))

    geo_json.add_child(folium.Popup(make_popup(All_Blocks.iloc[i])))
    geo_json.add_to(map1)

这是完整的代码,不包括翻译。

英文:

I found the solution, here's is the full code

    # styling on tables pop up
def make_popup(df):
blockname = df[&quot;Block_Name&quot;]
status = df[&quot;Status&quot;]
operator = df[&quot;Operator&quot;]
kilos = df[&quot;Sq. Kilometers&quot;]
miles = df[&quot;Sq. Miles&quot;]
left_col_color = &quot;#65b3d0&quot;
right_col_color = &quot;#ebf2f7&quot;
html = &quot;&quot;&quot;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;strong&gt;&lt;h4 style=&quot;margin-bottom:30px; width:200px; font-size: 25px;&quot;&gt;{}&lt;/strong&gt;&lt;/h4&gt;&quot;&quot;&quot;.format(blockname) + &quot;&quot;&quot;
&lt;/head&gt;
&lt;table style=&quot;height: 126px; width: 300px;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Status&lt;/span&gt;&lt;/td&gt;
&lt;td style=&quot;width: 200px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(status) + &quot;&quot;&quot;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Operator&lt;/span&gt;&lt;/td&gt;
&lt;td style=&quot;width: 200px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(operator) + &quot;&quot;&quot;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Sq. Kilometers&lt;/span&gt;&lt;/td&gt;
&lt;td style=&quot;width: 200px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(kilos) + &quot;&quot;&quot;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;background-color: &quot;&quot;&quot; + left_col_color + &quot;&quot;&quot;;&quot;&gt;&lt;span style=&quot;color: #151515;&quot;&gt;Sq. Miles&lt;/span&gt;&lt;/td&gt;
&lt;td style=&quot;width: 200px;background-color: &quot;&quot;&quot; + right_col_color + &quot;&quot;&quot;;&quot;&gt;{}&lt;/td&gt;&quot;&quot;&quot;.format(miles) + &quot;&quot;&quot;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/html&gt;
&quot;&quot;&quot;
return html
map1 = folium.Map(location=location,
zoom_start=11, control_scale=300, tiles=None)
# Put ESRI Satellite for the layer map
tile = folium.TileLayer(
tiles=&#39;https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}&#39;,
attr=&#39;Esri&#39;,
name=&#39;Esri Satellite&#39;,
overlay=False,
control=False
).add_to(map1)
# put a minimap on bottom corner of the main map (optional, can be turned off) and other plugins such as szroll zoom toggler, fullscreen, etc
minimap = plugins.MiniMap(toggle_display=True)
map1.add_child(minimap)
plugins.ScrollZoomToggler().add_to(map1)
plugins.Fullscreen(position=&quot;topright&quot;).add_to(map1)
plugins.Draw(position=&#39;topright&#39;).add_to(map1)
def filter_by_name(df, name):
return df[df[&#39;Block_Name&#39;].isin(name)]
# option_block = st.multiselect(&#39;Select the block name&#39;, (All_Blocks[&#39;Block_Name&#39;]), default=All_Blocks[&#39;Block_Name&#39;])
df_filter = filter_by_name(All_Blocks,All_Blocks[&#39;Block_Name&#39;])
# Adding blocks to the main map (UPDATE)
for i, row in df_filter.iterrows():
geo_json = folium.features.GeoJson(row.geometry.__geo_interface__, name=str(i), 
style_function=
lambda feature: {
&#39;fillColor&#39;:  &#39;#65b3d0&#39;,
#    &#39;fillColor&#39;: &#39;#F1D581&#39; if &#39;x&#39; in feature[&#39;properties&#39;][&#39;Status&#39;] == &#39;Exploration&#39; else &#39;#65b3d0&#39;,
&#39;color&#39;: &#39;black&#39;,
&#39;weight&#39;: 3,
&#39;fillOpacity&#39;: 0.2,
&#39;dashArray&#39;: &#39;5,5&#39;
},
highlight_function=lambda x: {
&#39;fillOpacity&#39;: 1},
tooltip=folium.features.Tooltip(All_Blocks.iloc[i][&#39;Block_Name&#39;], sticky=False))
# fields=All_Blocks.iloc[i][&#39;Block_Name&#39;], aliases=[&#39;Name&#39;]))
geo_json.add_child(folium.Popup(make_popup(All_Blocks.iloc[i])))
geo_json.add_to(map1)

答案2

得分: 0

Maybe use the GeoJsonPopup (https://python-visualization.github.io/folium/modules.html#folium.features.GeoJsonPopup). This allows you to bind different popups to different GeoJson elements. Lookup the parameters on the website for the binding attributes.

英文:

Maybe use the GeoJsonPopup (https://python-visualization.github.io/folium/modules.html#folium.features.GeoJsonPopup). This allows you to bind different popups to different GeoJson elements. Lookup the parameters on the website for the binding attributes.

huangapple
  • 本文由 发表于 2023年2月6日 16:35:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75358982.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定