-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add example pattern for pulling JsCode snippets from external javascript files #1942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Very interesting idea. I have noticed the same drawbacks of having javascript as strings inside python. (And I would add there is no editor support or linting of javascript from inside python). I don't know of a library that does exactly this, but there are javascript parsers available in python. E.g. https://github.com/PiotrDabkowski/pyjsparser. And there is pythonmonkey. This serves a totally different purpose, but also does javascript parsing. I think with either we could hack up a PoC that does what you want. Do you have an example of how you would want to use this library to be? |
Agreed: lack of editor and linting support are also painful.
Maybe something like: pointToLayer.js
plugin.js
folium.py
|
Would a preprocessor be acceptable? Something that takes as input a javascript module and generates the required python code? |
Maybe. What would the usage look like? |
I created a small PoC in javascript that creates JsCode definitions for each function inside a javascript module. It creates a file
From python you would be able to use this as follows:
|
That's pretty cool! Seems useful to me. Can you post the javascript module too? It's defining non-lambda functions |
This is the code I used for the PoC. It needs to be tweaked to accept arguments.
This is the code for
|
@thomasegriffith Is this sufficient for you? If you are okay with it, I'd like to close the issue. I don't think the example I wrote is sufficiently mature to be included in the Folium core library (even as a documentation.) I checked with the PythonMonkey development team. They have plans to make javascript source code directly accessible. We can revisit this issue when that happens. |
Sounds good @hansthen. Thanks for the discussion and example!! |
Is your feature request related to a problem? Please describe.
I have found myself embedding a lot of javascript code via
JsCode
when using theRealtime
plugin. This gets messy for a few reasons:I'm wondering if there's a recommended way to solve this.
Describe the solution you'd like
A solution would allow one to reference specific functions from external javascript files within a
JsCode
object.It's not clear to me what would be better: whether to do this from within
folium
(using the API) or to use some external library to populate the string of javascript code that's passed toJsCode
based on some javascript file and function. In either case, having an example in theexamples
folder would be great.Describe alternatives you've considered
If nothing is changed about the
folium
API, this could just be done external tofolium
. As in, another library interprets a javascript file, and given a function name, the function's definition is returned as a string. Is this preferable to building the functionality intofolium
? If so, does anybody know of an existing library that can already do this?Additional context
n/a
Implementation
n/a
The text was updated successfully, but these errors were encountered: