Skip to content
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

Tile sources as param widgets #330

Closed
kcpevey opened this issue May 10, 2019 · 5 comments
Closed

Tile sources as param widgets #330

kcpevey opened this issue May 10, 2019 · 5 comments

Comments

@kcpevey
Copy link

@kcpevey kcpevey commented May 10, 2019

I wrote this bit of code so that I can display the tile sources as widgets. It seems like it might be useful in geoviews itself:

import geoviews as gv
import geoviews.tile_sources as gvts
import param
import panel as pn

class GVTS(param.Parameterized):
    
    source = param.ObjectSelector(default=list(gvts.tile_sources.keys())[0], objects=list(gvts.tile_sources.keys()), label='Web Map Tile Services')
        
    def widget(self):
        return pn.panel(self.param, parameters=['source'])
    
    @param.depends('source')
    def view(self):
        return gvts.tile_sources[self.source]
    
    def panel(self):
        return pn.Column(self.widget, self.view)

image

I'm not super happy with the syntax on the tile sources in the ObjectSelector. I wanted to do something like this:
source = param.ObjectSelector(default=gvts.tile_sources['EsriImagery'], objects=gvts.tile_sources, label='Web Map Tile Services')

But that gave me extra widgets that I didn't want to expose to the user and I couldn't see a way around it. I suspect its due to the use of dict as ObjectSelector.

@kcpevey

This comment has been minimized.

Copy link
Author

@kcpevey kcpevey commented May 10, 2019

Even if you didn't want to add panel as a requirement for gv, just a parameterized class would be useful.

@jbednar

This comment has been minimized.

Copy link
Member

@jbednar jbednar commented May 13, 2019

This approach seems cleaner:

import geoviews as gv, geoviews.tile_sources as gvts, param, panel as pn
gv.extension('bokeh')
pn.extension()

class GVTS(param.Parameterized):
    source = param.Selector(gvts.tile_sources, label='Web Map Tile Services')
    
    @param.depends('source')
    def view(self):
        return self.source

    def panel(self):
        return pn.Column(pn.panel(self.param, expand_button=False), self.view)

GVTS().panel()

We currently recommend using Selector rather than ObjectSelector, because it behaves more reasonably for the typical case of having a long list of items and just wanting the first item as the default. This syntax seems fine to me, as it is.

The part that avoids the widgets is expand_button=False, as the tile source's internal parameters aren't very useful to edit. @philippjfr, could we mark all those parameters as hidden by default, and then hide the button by default if there are no non-hidden parameters?

Finally, what were you suggesting we do at the GeoViews level? Would it be good to have this bit of code in the GeoViews docs, so that you can select tile sources on the web page to see how each behaves? Or are you wanting something reusable that you can put into your own notebooks, and if so how would you use it?

@kcpevey

This comment has been minimized.

Copy link
Author

@kcpevey kcpevey commented May 13, 2019

@jbednar Thanks for the edits and the explanation.

I was thinking that it was handy enough that I'm putting it a util file in all of my repos. I thought it might be something other users could use as well. If it were implemented in gv it would prevent me duplicating code. I was going to leave how and where it got implemented in gv to you guys since you would know better than I. Or if you say a docs example would suffice, that's fine with me too.

As far as application goes, a good example is the grabcut demo notebook. It would replace the messiness of this (earthsim/grabcut.py lines 281+).

@jbednar

This comment has been minimized.

Copy link
Member

@jbednar jbednar commented May 14, 2019

I'm a bit confused; to me the grabcut.py files seem messy because they are using string URLs rather than gvts.tile_sources, but that's a matter of updating grabcut.py rather than GeoViews. I'm not able to see just what would go into GeoViews that would be reusable, beyond tile_sources that's already in GeoViews. I must be missing something?

@jsignell

This comment has been minimized.

Copy link
Member

@jsignell jsignell commented Oct 16, 2019

I just came across this issue and think it should be closed. Unless someone wants to add a snippet to the docs. Here is an (arguably) simpler version using @pn.depends

import panel as pn
import geoviews.tile_sources as gvts

tiles_widget = pn.widgets.Select(options=gvts.tile_sources, name='Web Map Tile Services')

@pn.depends(tiles_widget)
def tile_plot(tile): 
    return tile

pn.Row(tiles_widget, tile_plot)
@jsignell jsignell closed this Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.