folium icon indicating copy to clipboard operation
folium copied to clipboard

Map Resizing

Open kaylynnkfc opened this issue 12 years ago • 9 comments

I'm kinda new to folium, so I may have just missed something obvious, but I haven't been able to find a folium feature to resize the map. I could change the javascript for the map, but as I've got about 10 different maps (and more to come) that are all being generated automatically using python, this doesn't seem like a good solution. I'd ideally want the map to dynamically respond based on the window size.

Is this already possible without changing the javascript? If not, it'd be a great feature.

kaylynnkfc avatar Jun 12 '14 21:06 kaylynnkfc

@silentttone looking at the source here https://github.com/wrobstory/folium/blob/master/folium/folium.py#L53 you can pass in width and height of the map.

i have tested the following and it works...

map = folium.Map(width=500,height=500,location=[40, -99], zoom_start=4)

birdage avatar Jul 09 '14 18:07 birdage

Does @birdage's reply answer your question?

I don't think we're going to have dynamically resizing maps for a while. I've got some major other structural issues to address first.

wrobstory avatar Sep 21 '14 22:09 wrobstory

@wrobstory ive had some issue with the size of the map in an ipython notebook, i.e the map will be the size you request but the cell size containing the notebook wont be the height you request, instead there will be a scroll bar.

birdage avatar Oct 13 '14 18:10 birdage

@birdage I am closing this. @silentttone issue seems to be unrelated to the notebook display like yours. We need to pass relative size (in %) for that (See #23).

(And I am working on your issue tight now :wink:, see #90)

ocefpaf avatar Apr 22 '15 23:04 ocefpaf

You should use this: f = folium.Figure(width=1000, height=500) m = folium.Map(location= initial_location, tiles="openstreetmap", zoom_start=zoom_start_defined, min_zoom = min_zoom_defined).add_to(f)

If you set it in folium.Map - it reshapes the map itself, but window map is the same (at least that is so for Jupyter Notebook)

source: https://stackoverflow.com/questions/48789751/set-map-boundary-and-stop-endless-panning-in-a-loop-of-folium-map

datamany avatar Dec 16 '19 22:12 datamany

You should use this: f = folium.Figure(width=1000, height=500) m = folium.Map(location= initial_location, tiles="openstreetmap", zoom_start=zoom_start_defined, min_zoom = min_zoom_defined).add_to(f)

If you set it in folium.Map - it reshapes the map itself, but window map is the same (at least that is so for Jupyter Notebook)

source: https://stackoverflow.com/questions/48789751/set-map-boundary-and-stop-endless-panning-in-a-loop-of-folium-map

Had the exact same issue as @silentttone , this worked perfectly. Thank you.

Singh1106 avatar Nov 11 '20 18:11 Singh1106

this worked for me @Singh1106 ! thank you :)

sahanaraguram2000 avatar Dec 03 '20 07:12 sahanaraguram2000

How do you fit the Folium map on mobile devices?

Right now it doesn't fit it, but the div does fit and the folium map is inside the div, but the folium map is not getting any effect from the css styling. If I do width less than 100% then it just moves right and leaves a white background on the left.


Folium Map example

I get this when mobile device Size: 412x914 Screenshot 2022-03-09 at 13 58 50


I want this on mobile devices Screenshot 2022-03-09 at 14 01 06

mejl avatar Mar 09 '22 03:03 mejl

I know I'm late to the party, but if you wanted to add your exact monitor size as the width as seen on this forum post: https://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python

As an example:

import folium
from screeninfo import get_monitors

m = get_monitors()
m_width = m[0].width
m_height = m[0].height

map = folium.Map(width = m_width, height = m_height, location=[LAT, LNG], 
zoom_start = ZOOMSTART, min_zoom = MINZOOM, max_bounds=True, tiles = GIVEN_TILE_SET);

Insert what you would like into the uppercase. Also, I'm not going to be using this for a frame, rather a full page, so I don't need that part, but please modify your code to make sure it is included if you need it.

KingSand08 avatar Aug 10 '24 08:08 KingSand08