Folium: Add Search Box on Folium map

Created on 15 Jul 2016  Â·  60Comments  Â·  Source: python-visualization/folium

Can anybody point me towards how to add a Search box on Folium?
I know Leaflet has this functionality but couldn't find any documentation on Folium.
Thanks in advance.

feature request plugin

All 60 comments

There is no search box on folium. One could add a plugin for the https://github.com/stefanocudini/leaflet-search and implement it.

PRs welcome :smile:

@sangyh

I have started to work on the leaflet-search plugin, it is awaiting a Pull Request, if you're still interested in this plugin a peer review would be great.

@ocefpaf
can you please help more about mentioned plugin, how to install or add to a folium project?

I have made an example notebook, did you look at that?

Sent from my iPhone

On 17 Oct 2017, at 06:00, morteza3000 <[email protected]notifications@github.com> wrote:

@ocefpafhttps://github.com/ocefpaf
can you please help more about mentioned plugin, how to install or add to a folium project?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-337118188, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQfyAZKB4K9WBUT_EoqJH5Sdwpwcfks5stDR3gaJpZM4JNCFm.

No I didn't, can you please give me the name of that example notebook?

Plugins-search.ipynb

I think it should be there, I’ll check on my laptop when I get a chance if not.

Sent from my iPhone

On 17 Oct 2017, at 14:35, morteza3000 <[email protected]notifications@github.com> wrote:

No I didn't, can you please give me the name of that example notebook?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-337233170, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQWK59yLpUrMDEsiuBqxKRufajPIPks5stK07gaJpZM4JNCFm.

I'll really appreciate if you can share it.

PR: https://github.com/python-visualization/folium/pull/747

https://github.com/ghandic/folium/blob/search-features/examples/Plugins-Search.ipynb

(all of the data is self contained in the notebook - this will be changed shortly. This search feature is on my feature-seach branch

I'm away from office with limited connection. I'll check it as soon as I
get back.

On Oct 17, 2017 4:05 AM, "Andy Challis" notifications@github.com wrote:

I have made an example notebook, did you look at that?

Sent from my iPhone

On 17 Oct 2017, at 06:00, morteza3000 <[email protected] [email protected]>> wrote:

@ocefpafhttps://github.com/ocefpaf
can you please help more about mentioned plugin, how to install or add to
a folium project?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub python-visualization/folium/issues/464#issuecomment-337118188>, or mute
the thread auth/AWaWQfyAZKB4K9WBUT_EoqJH5Sdwpwcfks5stDR3gaJpZM4JNCFm>.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/python-visualization/folium/issues/464#issuecomment-337137889,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA6BLy5N7qjJXD8NroHTO055n0ERNirMks5stFGxgaJpZM4JNCFm
.

@ghandic
Thanks a lot but I faced with below error when I wanted to run notebook.


AttributeError Traceback (most recent call last)
in ()
9 )
10
---> 11 plugins.Search(states, search_zoom=6, geom_type="Polygon").add_to(m)
12
13 m.save(os.path.join('results', 'Plugins_search_polygon.html'))

AttributeError: 'module' object has no attribute 'Search'

Did you pip install from my search-feature branch? It’s not been accepted into the master branch of Folium yet.

Sent from my iPhone

On 18 Oct 2017, at 05:54, morteza3000 <[email protected]notifications@github.com> wrote:

@ghandichttps://github.com/ghandic
Thanks a lot but I faced with below error when I wanted to run notebook.


AttributeError Traceback (most recent call last)
in ()
9 )
10
---> 11 plugins.Search(states, search_zoom=6, geom_type="Polygon").add_to(m)
12
13 m.save(os.path.join('results', 'Plugins_search_polygon.html'))

AttributeError: 'module' object has no attribute 'Search'

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-337460144, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQfVU5m1VVUKMtElcRinPjvmydO2Oks5stYRpgaJpZM4JNCFm.

sorry I'm totally new to folium, I've just install folium by pip and add your search.py file to "C:ProgramDataAnaconda2Libsite-packagesfoliumplugins". is it write?
can you help what to do step by step?

run this:

pip uninstall -y folium
pip install git+https://github.com/ghandic/folium.git@search-features

You will then have the latest development that has not been merged into master.

for second command I got below error:

C:Windowssystem32>pip install git+https://github.com/ghandic/folium.git@search
-features
Collecting git+https://github.com/ghandic/folium.git@search-features
Cloning https://github.com/ghandic/folium.git (to search-features) to c:users
morteza.hasappdatalocaltemppip-ktrr6c-build
Error [Error 2] The system cannot find the file specified while executing comm
and git clone -q https://github.com/ghandic/folium.git c:usersmorteza.hasappd
atalocaltemppip-ktrr6c-build
Cannot find command 'git'

Install git...

Thanks a lot, it works now. :)

image

I want to search based on popup labels, is it possible?

here is my code:

import folium
from folium import plugins

coordinates = [
[42.3581, -71.0636],
[42.82995815, -74.78991444],
[39.17929819, -78.56603306]]

m = folium.Map(location=[41.9, -97.3], zoom_start=4, tiles="cartodbpositron")
my_Circle1 = folium.CircleMarker(location=[42.3581, -71.0636], radius= 6, popup=str("one"), color='red', fill_opacity=0.7)
my_Circle2 = folium.CircleMarker(location=[42.82995815, -74.78991444], radius= 6, popup=str("two"), color='red', fill_opacity=0.7)
my_Circle3 = folium.CircleMarker(location=[39.17929819, -78.56603306], radius= 6, popup=str("three"), color='red', fill_opacity=0.7)
plugins.Search(coordinates, search_zoom=6, geom_type="Polygon").add_to(m)

m.add_child(my_Circle1)
m.add_child(my_Circle2)
m.add_child(my_Circle3)

m.save('example.html')

This is how it was meant to be done:

points = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "one"
},
"geometry": {
"type": "Point",
"coordinates": [-71.0636, 42.3581]
}
},
{
"type": "Feature",
"properties": {
"name": "two"
},
"geometry": {
"type": "Point",
"coordinates": [-74.78991444, 42.82995815]
}
},
{
"type": "Feature",
"properties": {
"name": "three"
},
"geometry": {
"type": "Point",
"coordinates": [-78.56603306, 39.17929819]
}
}
]
}

m = folium.Map(
location=[42.82995815, -74.78991444],
tiles = 'cartodbpositron',
zoom_start=4
)

plugins.Search(points, search_zoom=20, ).add_to(m)

m.save('example.html')

It needs a layer to search through and you haven't supplied it by just passing coordinates. This will be added in with assertations into the next commit - as well as being able to use GeoJsonCss to add popups and styling rather than the default marker - this would allow you to use a circle marker then

@morteza3000 I have implemented GeoJsonCss now, so re install folium as you did before if you want to use it

Here is your example with popups and a custom Icon:

points = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "One"
},
"geometry": {
"type": "Point",
"coordinates": [-71.0636, 42.3581]
},
"style": {
"icon": {
"iconUrl": "http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png",
"iconSize": [32, 32],
"iconAnchor": [16, 16]
}
},
"popupTemplate": "{name}"
},
{
"type": "Feature",
"properties": {
"name": "Two"
},
"geometry": {
"type": "Point",
"coordinates": [-74.78991444, 42.82995815]
},
"style": {
"icon": {
"iconUrl": "http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png",
"iconSize": [32, 32],
"iconAnchor": [16, 16]
}
},
"popupTemplate": "{name}"
},
{
"type": "Feature",
"properties": {
"name": "Three"
},
"geometry": {
"type": "Point",
"coordinates": [-78.56603306, 39.17929819]
},
"style": {
"icon": {
"iconUrl": "http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png",
"iconSize": [32, 32],
"iconAnchor": [16, 16]
}
},
"popupTemplate": "{name}"
}
]
}

m = folium.Map(
location=[42.82995815, -74.78991444],
tiles = 'cartodbpositron',
zoom_start=4
)

plugins.Search(points, search_zoom=20).add_to(m)

m.save('example.html')

I installed new one and it is working perfectly, Thanks.

@ghandic can you please help me with another issue? I want to have name as plain text instead of icon, is it possible?

It is, I don’t think it’s integrated within folium yet but you can hack around it by using an image with the text in it, might be better with a png since you can have a transparent background.

Sent from my iPhone

On 12 Nov 2017, at 06:24, Morteza Hasan Abadi <[email protected]notifications@github.com> wrote:

@ghandichttps://github.com/ghandic can you please help me with another issue? I want to have name as plain text instead of icon, is it possible?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-343716417, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQYexUXm3YhFLhVjBCunZoLYiWCZCks5s1o8pgaJpZM4JNCFm.

Hi @ghandic, How can I install git? Can you help me?

Hi i could not run this

pip install git+https://github.com/ghandic/folium.git@search-features

can you send an updated link please

thxs

@HSAG-2018
pip install folium
as it is now in the master branch :)

ok i see
however i got this error: AttributeError: module 'folium.plugins' has no attribute 'Search'
when using this command
plugins.Search(en_sid, search_zoom=6, geom_type='Polygon').add_to(map)
any idea what i have missed? thx

What version of folium are you using?

0.5.0

Ok that was last updated 4 months ago you can install from this git repo’s master branch, I’m on my phone atm so can’t check the pip install command

@ocefpaf how are we managing the Pypi repo?

pip install git+https://github.com/python-visualization/folium.git

still not working not sure if from server side or my laptop...
C:UseCase3>pip install git+https://github.com/python-visualization/folium.git
Collecting git+https://github.com/python-visualization/folium.git
Cloning https://github.com/python-visualization/folium.git to c:usershappdatalocaltemppip-iqccyg6z-build
fatal: unable to access 'https://github.com/python-visualization/folium.git/': SSL certificate problem: unable to get local issuer certificate Command "git clone -q https://github.com/python-visualization/folium.git C:UsershAppDataLocalTemppip-iqccyg6z-build" failed with error code 128 in None

Ok try cloning the repo first then run the setup.py

Sent from my iPhone

On 17 Jan 2018, at 20:19, HSAG-2018 <[email protected]notifications@github.com> wrote:

still not working not sure if from server side or my laptop...
C:UseCase3>pip install git+https://github.com/python-visualization/folium.git
Collecting git+https://github.com/python-visualization/folium.git
Cloning https://github.com/python-visualization/folium.git to c:usershappdatalocaltemppip-iqccyg6z-build
fatal: unable to access 'https://github.com/python-visualization/folium.git/': SSL certificate problem: unable to get local issuer certificate Command "git clone -q https://github.com/python-visualization/folium.git C:UsershAppDataLocalTemppip-iqccyg6z-build" failed with error code 128 in None

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-358431749, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQQEvVWnYuptJ3nOiliaOHqOd9Opwks5tLlXggaJpZM4JNCFm.

the cloning does not work so i tried to download the zip save it locally then run setup.py but this has no effect...shld replacing the whole existing folium directory with the new dowloaded one work? thxs

@ocefpaf how are we managing the Pypi repo?

There will be a new release once I can allocate some time to review and merge the open PRs.

@ghandic Hello sorry to bother. I also want to add search functionality on a group of markers and display a pop up so I tried running the sample code with GeoJsonCss implemented which you provided above but it doesn't seem to be working. To be more specific, I can't get the pop ups to appear.

I've pip installed from the git (pip install git+https://github.com/python-visualization/folium.git) and am running on python 3.6.3.

Hope I can get it to work soon :) Thanks!

image

Hi @javaUtilScammer can you add your source code? I’ll take a look at this this morning if you can

Hi @ghandic , didn't expect you to reply so fast but big thank you :) I wanted to implement the search functionality on another map I made using Folium a while back but I can't get the popups to appear on a sample.

It's pretty much the code you commented a while back plus imports. Thanks!

import folium
from folium import plugins
from folium import GeoJson

points = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "One"
},
"geometry": {
"type": "Point",
"coordinates": [-71.0636, 42.3581]
},
"style": {
"icon": {
"iconUrl": "http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png",
"iconSize": [32, 32],
"iconAnchor": [16, 16]
}
},
"popupTemplate": "{name}"
},
{
"type": "Feature",
"properties": {
"name": "Two"
},
"geometry": {
"type": "Point",
"coordinates": [-74.78991444, 42.82995815]
},
"style": {
"icon": {
"iconUrl": "http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png",
"iconSize": [32, 32],
"iconAnchor": [16, 16]
}
},
"popupTemplate": "{name}"
},
{
"type": "Feature",
"properties": {
"name": "Three"
},
"geometry": {
"type": "Point",
"coordinates": [-78.56603306, 39.17929819]
},
"style": {
"icon": {
"iconUrl": "http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png",
"iconSize": [32, 32],
"iconAnchor": [16, 16]
}
},
"popupTemplate": "{name}"
}
]
}

m = folium.Map(
location=[42.82995815, -74.78991444],
tiles = 'cartodbpositron',
zoom_start=4
)

plugins.Search(data=points, search_zoom=20,position="topright").add_to(m)
m.save('example.html')

@javaUtilScammer the GeoJsonCss part has not been merged into master on this repo, I just had a look at my fork vs this repo. @ocefpaf was there some problems with the GeoJsonCSS?

@ocefpaf was there some problems with the GeoJsonCSS?

My time to finish reviewing it. I do recall some issues when testing against the notebook gallery, but I cannot get back to that this month :unamused:

No problem @ocefpaf I saw some of the modifications you did and it simplifies it a lot, I'm happy to test some of those notebooks out.

Meanwhile @javaUtilScammer if you really need this purely as an output and not for long term you could use my forked repo https://github.com/ghandic/folium.git

Check back soon and I'm sure we'll be a few steps closer to having this up and running!

No problem @ocefpaf I saw some of the modifications you did and it simplifies it a lot, I'm happy to test some of those notebooks out.

Our testing is a little time consuming, we need to run all the notebooks from example folder and inspect them visually. If you could do that and fix the remaining issues that would be awesome!

@ocefpaf Just found a great little package which speeds that up, called nbmerge

# cd into the project folder
pip install nbmerge
# Merges all of the notebooks into one inside examples/_merged.ipynb
nbmerge --recursive -i -p ".*" -o examples/_merged.ipynb

Meanwhile @javaUtilScammer if you really need this purely as an output and not for long term you could use my forked repo https://github.com/ghandic/folium.git

@ghandic will do that for now but will definitely come back when the merge is complete! Big thanks goes to you and @ocefpaf for the quick action :)

@ocefpaf

I spun up a docker container running jupyter notebook, cloned the repo and installed folium from your last commit hash on the pull request for #762

Then I merged all the notebooks and ran all cells, all of which seems to work perfectly. I haven't done any other testing than that, just checked the outputs and nothing errored

Docker-compose.yml

version: "2"
services:
  jupyter-notebook:
    build: .
    image: challisa/folium-notebook
    container_name: folium-notebook
    ports:
      - "8888:8888"
    volumes:
      - ~:/home/jovyan/work
    entrypoint: start-notebook.sh --NotebookApp.token='' --NotebookApp.iopub_data_rate_limit=1000000000000000 

Dockerfile

FROM jupyter/minimal-notebook

USER root

# libav-tools for matplotlib anim
RUN apt-get update && \
    apt-get install -y --no-install-recommends libav-tools && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Cartopy
RUN conda install --yes -c conda-forge cartopy

USER $NB_USER

RUN pip install  \
    'matplotlib' \
    'mplleaflet' \
    'geographiclib' \
    'gpxpy' \
    'altair' \
    'vincent' \
    'geopandas' \
    'pandas' \
    'widgetsnbextension' && \
    # Activate ipywidgets extension in the environment that runs the notebook server
    jupyter nbextension enable --py widgetsnbextension --sys-prefix 

USER $NB_USER

@ghandic Hi Andy, am I right that the popup functionality has not yet been merged with master?

Hi guys! Can anyone help me with search function? How can I find a marker by typing "one" in searchbar?

from folium import plugins, Map, Marker, FeatureGroup, Popup, LayerControl
import webbrowser

m = Map(location=[43.25, 45.83333 ], zoom_start=10, zoom_control=False)

fg = FeatureGroup(name='VTK')

g1 = plugins.FeatureGroupSubGroup(fg, 'FTTB')
g2 = plugins.FeatureGroupSubGroup(fg, 'FTTH')
g3 = plugins.FeatureGroupSubGroup(fg, 'GPON')
Marker([43.119749, 45.562305], popup=Popup('one')).add_to(g1)
Marker([43.143048, 45.534987], popup=Popup('two')).add_to(g2)
Marker([43.131022, 45.546844], popup=Popup('three')).add_to(g3)
m.add_child(fg)
m.add_child(g1)
m.add_child(g2)
m.add_child(g3)

m.add_child(plugins.Search(fg))
m.add_child(LayerControl(collapsed=False))
m.save('test_map2.html')
webbrowser.open('test_map2.html')

@HSAG-2018
pip install folium
as it is now in the master branch :)

@ghandic , when I install it with (> pip install folium) below error appears for same examples.
can you please help?

AssertionError: Search can only index FeatureGroup, MarkerCluster, GeoJson, and TopoJson layers at this time.

I believe they have refactored the code since I made my pull request. Maybe check in the example notebooks?

Sent from my iPhone

On 6 Apr 2019, at 21:46, Morteza Hasan Abadi <[email protected]notifications@github.com> wrote:

@HSAG-2018https://github.com/HSAG-2018
pip install folium
as it is now in the master branch :)

@ghandichttps://github.com/ghandic , when I install it with (> pip install folium) below error appears for same examples.
can you please help?

AssertionError: Search can only index FeatureGroup, MarkerCluster, GeoJson, and TopoJson layers at this time.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-480494235, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQcqnduWjpewznBwxl6Hcc5Z96r69ks5veHsVgaJpZM4JNCFm.

Yes, your example notebooks also don't work with provided data.

I haven’t updated the pull request. Someone else made changes, I will have a look if I get chance. Maybe check who made the updates.

Sent from my iPhone

On 7 Apr 2019, at 16:07, Morteza Hasan Abadi <[email protected]notifications@github.com> wrote:

Yes, your example notebooks also don't work with provided data.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/python-visualization/folium/issues/464#issuecomment-480562278, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWaWQaz2neyK2xg7LmMrjp3KFKYMVGilks5veYs9gaJpZM4JNCFm.

@morteza3000 please open a new issue for your problem and include:

  • a stand-alone code snippet that results in the error message
  • the full error message
  • your folium version: print(folium.__version__)

@Conengmo , please be informed that below issue has been raised.
Problem with Folium search plugin (loading Geojosn Data) #1125

Thanks a lot, it works now. :)

image

hey, can you share the code

is there a search plugin that works for FastMarkerCluster? I can't use MarkerCluster because it hinders the load performance because I'm using over 11,000 markers.

Check out the example notebooks https://github.com/python-visualization/folium/blob/master/examples/plugin-Search.ipynb

@ghandic , How we can style points in your example?

citygeo = folium.GeoJson(
pop_ranked_cities,
name='US Cities',
tooltip=folium.GeoJsonTooltip(
fields=['nameascii','pop_max'],
aliases=['','Population Max'],
localize=True)
).add_to(m)

how to add style_function to this in order to change points color or use custom icon?

Hey everyone,

as the docs say, the search plugin can index FeatureGroup, MarkerCluster, GeoJson and TopoJson layers.
It only worked for me on GeoJson layers so far.

Could you please provide an example for FeatureGroup or MarkerCluster without GeoJson?

Thanks in advance ;)

Looking at the Search plugins python file, search is currently only implemented for GeoJson and TopoJson. I'm not entirely sure as to why the documentation states that it also implements the search for FeatureGroup and MarkerClusters. Maybe there were/are plans down the line for it (?)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AntonioLopardo picture AntonioLopardo  Â·  15Comments

Alcampopiano picture Alcampopiano  Â·  14Comments

achourasia picture achourasia  Â·  15Comments

Demetrio92 picture Demetrio92  Â·  18Comments

nathan3leaf picture nathan3leaf  Â·  32Comments