Hey guys,
I wonder whether it's possible for DivIcon
to have an automatic size.
The context:
On my map, hovering over a country will trigger a tooltip with the country's name.
I also have several DivIcon
s, with the following code:
folium.Marker(
location=[lat, lon],
icon=folium.DivIcon(
html='''
<div style="background-color: red; display: inline-block;">
<span>
{region_name}:
<br />{region_info}
</span>
</div>
''',
icon_size=(100, 100),
icon_anchor=(0, 0),
)
).add_to(map)
Because of the variation in region_name
s and region_info
s, the width of the content varies between 50 and 90 pixels. I want my text to be displayed on two lines and the div
to fit its content: the display: inline-block
in the html allows me to do this, even if my icon_size
is constant.
But the problem is that the size of the DivIcon
affects the tooltips: I can have a 70px-wide block with content, but an area of 30px next to it which doesn't display as a block but still counts as that block. So if I hover out of the visible block, instead of the tooltip appearing with some country's name, nothing happens. This is especially problematic when this area covers a bunch of small countries.
What I'd like to happen is for the DivIcon to fit to the html within, or to have some kind of dynamic behaviour. I have tried doing icon_size=(10, 10)
or removing icon_size
, but the block just shrinks to fit to the longest word in the content. I have tried to go through the code for folium.DivIcon
, branca.MacroElement
, branca.Figure
, etc., but wasn't able to get control of this behaviour.
Any suggestions welcome.
gpd.__version__
'0.6.1'
folium.__version__
'0.11.0'
gdf.crs # gdf created via gpd.read_file()
{'init': 'epsg:4326'}
folium.GeoJson(gdf, name='gdf test').add_to(test_map)
RuntimeError Traceback (most recent call last)
<ipython-input-24-268ce60b1d50> in <module>
35
---> 36 folium.GeoJson(gdf, name='gdf test').add_to(test_map)
37
. . .
S:\MDP\Programs\Anaconda3\lib\site-packages\pyproj\__init__.py in __new__(self, projparams, preserve_units, **kwargs)
360 # on case-insensitive filesystems).
361 projstring = projstring.replace('EPSG','epsg')
--> 362 return _proj.Proj.__new__(self, projstring)
363
364 def __call__(self, *args, **kw):
_proj.pyx in _proj.Proj.__cinit__()
RuntimeError: b'no arguments in initialization list'
fg = folium.FeatureGroup(name="tiles")
with open(geojson_file) as geojson:
tileDic = json.load(geojson)
for feature in tileDic['features']:
coords = [[y,x] for i in feature['geometry']['coordinates'] for x,y in i ]
tileId = feature['properties']['tile_id']
print(coords)
print(tileId)
fg.add_child(folium.Polygon(locations=coords,fill=True,popup=(folium.Popup(tileId))))
I would like to publish information from an ArcGIS MapServer to Folium. I had some It looks like that can be done if a given api is configured to create tiles, but many are not. My first question is, does anyone know if this is possible?
Some ArcGIS MapServer services are published in the WMS format but these are relative few. I tried to configure the api listed below as a Folium “wms_layer” but I am getting a driver error (also listed below). Anyone know if this is even possible?
m.add_wms_layer(wms_name="Census Current (2020) WMS",wms_url="https://tigerweb.geo.census.gov/arcgis/services/TIGERweb/tigerWMS_Current/MapServer/WMSServer",
wms_format="image/png",
wms_layers='2010 Census Public Use Microdata Areas Labels')
DriverError: D:\Dev\APS\aps\data\satskred\AvalDet_20190101_051134_ref_20181226_trno_095_VV\AvalDet_20190101_051134_ref_20181226_trno_095_VV.shp\AvalDet_20190101_051134_ref_20181226_trno_095_VV.shp: No such file or directory
import folium
from folium import features
m = folium.Map([ 45.75345246,12.34117475], zoom_start=7)
points_ = {'type': 'FeatureCollection',
'features': [{'type': 'Feature',
'properties': {'Codice': 500732, 'Categoria': 'D1', 'Cluster': 3},
'geometry': {'type': 'Point', 'coordinates': [12.34117475, 45.75345246]},
'id': '0'},
{'type': 'Feature',
'properties': {'Codice': 500732, 'Categoria': 'A2', 'Cluster': 3,'iconColor':'red'},
'geometry': {'type': 'Point', 'coordinates': [14.34117475, 46.75345246]},
'id': '1'}]}
pp = folium.Popup("hello",fields=['Codice'])
ic = features.Icon(iconColor="red")
gj = folium.GeoJson(points_)#, tooltip=tooltip)
gj.add_child(ic)
gj.add_child(pp)
m.add_child(gj).add_child(pp).add_child(ic)
m