python-visualization / python-visualization/folium

GlifyLayer not defined when using .add_to(map)

Open
#1,982 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

not our bug work in progress
Dominant language
Python
Stars
7.4k
Forks
2.3k
Avg merge
17h 22m
Merged PRs (30d)
11

Description

When using GlifyLayer.add_to(map) an error appears:

Uncaught ReferenceError: glify_layer_xxxxxx is not defined

The issue being that calling add_to(map) generates the function twice

L.glify.layer(options).addTo(map_xxxxxx); 
glify_layer_xxxxxx.addTo(map_xxxxxx);

This prevents the rest of the map loading correctly.

To Reproduce
This can be reproduced using the GlifyLayer.ipynb by saving the resultant html to file and inspecting console

Environment:

  • Python version 3.12.4
  • folium version 0.17.0

Possible solutions
A workaround I have been implementing is to directly change the HTML directly by setting

var glify_layer_xxxxxx = L.glify.layer(options);
glify_layer_xxxxxx.addTo(map_xxxxxx);

folium is maintained by volunteers. Can you help making a fix for this issue?
Unsure of where the generation of the 2nd function glify_layer_xxxxxx.addTo(map_xxxxxx); is taking place, clearly not in init.py for GlifyLayer (Maybe constructor for GlifyLayer, but cannot be sure)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with GlifyLayer.ipynb and inspect the generated HTML and browser console. Trace how GlifyLayer.add_to(map) produces both the L.glify.layer(options).addTo(...) call and the glify_layer_xxxxxx.addTo(...) call, including the GlifyLayer init.py implementation. Done means the generated HTML emits one layer setup and the rest of the map loads without the ReferenceError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.