Skip to content
Advertisement

How to show Company CI icon useing MarkerCluster in Folium

from folium.plugins import MarkerCluster
import folium
from folium.features import CustomIcon
import pandas as pd
import folium.plugins as plug

df = pd.read_excel('store.xlsx')
df1 = df[['대리점명','Latitude','Longitude']]
df1.rename(columns= {'대리점명':'Store'}, inplace=True)
df1.head()
x = []
y = []
name = []
for i in range(len(df1['Latitude'])):
    if df['Latitude'][i] == 0.0 or df['Longitude'][i] == 0.0:
        pass
    else:
        name.append(df1['Store'][i])
        x.append(df1['Latitude'][i])
        y.append(df1['Longitude'][i])
print('store_sum: ',len(name))
print('x_sum: ',len(x))
print('y_sum: ',len(y))
import folium
import folium.plugins as plug
import json

map_store = folium.Map(location=[37.58, 127.0],zoom_start=11.5)

marker_cluster = plug.MarkerCluster().add_to(map_store)

file_name= r'seoul_municipalities_geo.json'
file_name = file_name.replace('\','/')
with open(file_name, 'rt') as f:
    geo = json.load(f)
    f.close()
folium.GeoJson(geo, name='Store').add_to(map_store)

for i in range(len(x)):

    folium.Marker([x[i],y[i]], popup= name[i], icon=folium.Icon(color='purple', icon='ok-circle')).add_to(marker_cluster)


map_store

I want to change purple cheak icon to company ci

sub_df = df

latitude = 37.58
longitude = 127.0

mm = folium.Map(
    location=[latitude, longitude],
    zoom_start=11.5
)

coords = sub_df[['Latitude', 'Longitude']]

marker_cluster = MarkerCluster().add_to(mm)

for lat, long in zip(coords['Latitude'], coords['Longitude']):
    icon_path = r"hci.png"
    icon = CustomIcon(
        icon_image=icon_path,
        icon_size=(180, 80),
        icon_anchor=(50, 50),
    )
    marker = folium.Marker(location=[lat, long], icon=icon, popup="대리점명")
    mm.add_child(marker)

mm

Also this image is directly above code print result? OUt?

I tried many time But really I cant

And you can’t understand my mean about bad English or can’t understand my question

please look under url

https://towardsdatascience.com/visualizing-tesla-superchargers-in-france-8c10894ab3c

This is perfect example I want to mimic like this

Anyway in first image, change purple checkbox Marker to company CI(CI image is in second picuture)

Advertisement

Answer

The point is that each marker must be set to belong to a marker cluster. Latitude and longitude and store name are created randomly. Also, the logo is a stack overflow logo.

import numpy as np
import pandas as pd
import folium
from folium.plugins import MarkerCluster
from folium.features import CustomIcon

df = pd.DataFrame({'Store':name_list,
                   'Latitude': [random.uniform(36.0, 38.0) for _ in range(100)],
                   'Longitude': [random.uniform(126.0, 128.0) for _ in range(100)]})

df.head()
    Store   Latitude    Longitude
0   ocUReOT56a  36.164013   127.045411
1   KbAQtbB5eG  36.534577   127.515191
2   PdiCOLvjC4  36.715178   126.333321
3   eM33oRtVii  37.889212   126.589194
4   nporJ7t4mY  36.604549   127.563762

latitude = 37.58
longitude = 127.0

mm = folium.Map(location=[latitude, longitude], zoom_start=10)

marker_cluster = MarkerCluster().add_to(mm)

for row in df.itertuples():
    icon_path = r"./data/240px-Stack_Overflow_icon.svg.png"
    icon = CustomIcon(icon_image=icon_path, icon_size=(50, 50))
    folium.Marker(location=[row.Latitude, row.Longitude], icon=icon, popup=row.Store).add_to(marker_cluster)

mm

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement