Closed oztalha closed 8 years ago
Hi @oztalha,
We are focused on getting folium 0.2.0
ready. So we don't have the manpower to investigate this.
Can you:
Thanks!
I'm also having issues with the data_out path. The problem with the current implementation is that I need to run the webserver and the python script from the same directory so that they both use the same relative path. This is not how I have my project set up, so it's restrictive.
I recommend solving this problem by eliminating the json data file and embedding the data in the html file. In conjunction with geo_str, this embeds all the necessary data in the html file and eliminates the need to run a webserver.
@jthornbrue Thank you for you comment.
I recommend solving this problem by eliminating the json data file and embedding the data in the html file.
This is what we've been doing in the coming v0.2
, while keeping the possibility not to embed the data. Here's a copy of GeoJson
dcostring:
Creates a GeoJson plugin to append into a map with
Map.add_plugin.
Parameters
----------
data: file, dict or str.
The GeoJSON data you want to plot.
* If file, then data will be read in the file and fully
embedded in Leaflet's JavaScript.
* If dict, then data will be converted to JSON and embedded
in the JavaScript.
* If str, then data will be passed to the JavaScript as-is.
style_function: function, default None
A function mapping a GeoJson Feature to a style dict.
Examples
--------
>>> # Providing file that shall be embeded.
>>> GeoJson(open('foo.json'))
>>> # Providing filename that shall not be embeded.
>>> GeoJson('foo.json')
>>> # Providing dict.
>>> GeoJson(json.load(open('foo.json')))
>>> # Providing string.
>>> GeoJson(open('foo.json').read())
>>> # Providing a style_function that put all states in green, but Alabama in blue.
>>> style_function=lambda x: {'fillColor': '#0000ff' if x['properties']['name']=='Alabama' else '#00ff00'}
>>> GeoJson(geojson, style_function=style_function)
I hope v0.2
will be out soon ; but you can clone the master in case of hurry.
Since this is implemented in the next release I am closing this. Please reopen if the problem re-surfaces.
I would like both the
create_map
's html and thedata_out
's json file to be created inmaps/
folder instead of the current working directory. Currently this is not possible because when Idata_out = 'maps/xyz.json'
and alsocreate_map(path='maps/xyz.html')
, then the produced html source has.defer(d3.json, 'maps/xyz.json')
(and the html file cannot find'maps/xyz.json
because itself is insidemaps/
too). Instead that part of the javascript in the html file should've been.defer(d3.json, 'xyz.json')
.So, my suggestion to fix this issue is that folium should consider the
data_out
's path, relative tocreate_html
's path. To achieve this, the path passed tocreate_html
needs to be parsed and the generated json file should be saved relative to this path. So, if thedata_out
is only a filename (without path/directory) then it should be placed in the same directory where html file is generated.