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
"loading" as an attribute of TileLayer? #455
Comments
TileLayer
?
Hi! There is an def on_load(**kwargs):
# Do something
pass
my_tile_layer.on_load(on_load) Maybe that could suit your needs? |
Hi @martinRenou, I tried to make a separate widget that shows a red bar when loading tiles and a green bar when all tiles are loaded, but when you move, new tiles load but I need to "catch" this so I can make the bar red again. I though of using the map's events, but then I though it would be better to just have a |
I totally agree. It should not be too difficult to add. Would you like to take a shot? :) |
Yes, sure =) I will try |
Ok, I need some help @martinRenou .. in class TileLayer(RasterLayer):
...
loading = Bool(False).tag(sync=True, o=True) then in var LeafletTileLayerView = LeafletRasterLayerView.extend({
leaflet_events: function () {
LeafletTileLayerView.__super__.leaflet_events.apply(this, arguments);
var that = this;
this.obj.on('loading', function (e) {
that.model.set('loading', true); // this is how the attr center of Map is updated
if (that.model.get('show_loading'))
that.spinner = new Spinner().spin(that.map_view.el);
});
this.obj.on('load', function() {
that.model.set('loading', false); // set it to false when finished loading..
that.send({
event: 'load'
});
if (that.model.get('show_loading'))
that.spinner.stop();
});
},
}) Then I tested it with a listener: m = ipyleaflet.Map()
lay = TileLayer(url='https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png')
m.add_layer(lay)
def ob(change):
print('loading')
lay.observe(ob, names='loading') But it does not work. When logging in the console the value of Thanks! |
Did you try doing that.model.save_changes(); After |
I tried that indeed, but I will do it again just to be sure. |
BTW your Python code should look like: class TileLayer(RasterLayer):
...
loading = Bool(False).tag(sync=True) Without the |
And if you are using JupyterLab, you won't see the |
Ok, I'll take out the |
Well, non of this changes make it work 🤔 |
Would you mind opening a PR anyway? So that I can give it a try :) |
Another option, which is different but will archive what I am looking for, is to make an |
Yes. I don't understand why the boolean does not update though... I guess if we go for the boolean we would get rid of the IMO the |
With " |
I mean |
Ok, yes, I though it was a more consistent approach. But, I am not sure if removing |
So, it seems like the 'loading' boolean is correctly updated (I simulated a slow internet connection in order to have time to print the boolean before the tiles finished loading :P). It's the observation that does not seem to work 😕 |
No! the observation works too! It's the print statement that is not put on the page 😕 If you try this code with your PR it works like a charm! from ipyleaflet import *
from ipywidgets import Output
m = Map(center=(52, 10), zoom=8, basemap=basemaps.Hydda.Full)
x = m.layers[0]
out = Output()
@out.capture()
def on_load_change(change):
print('loading? ', x.loading)
x.observe(on_load_change, 'loading')
display(m)
display(out) |
You are right! It does work 😄 👏 |
Closed by #460 Thanks a lot! This print statement that does not show must be unrelated. |
Thank you @martinRenou! I hope I can keep contributing =) |
Hi all,
the new
show_loading
attribute added recently to theTileLayer
class shows an animation each time any tile is loading, it is fine, but wouldn't it be better if aloading
property (read only attribute) is set toTrue
each time any tile is loading? Therefore we could make use of it our own way.The text was updated successfully, but these errors were encountered: