I have the following two classes and I want to update the map view with the parameters selected as country/continent in the parameterized class.
import panel as pn
import param
from panel.viewable import Viewer
pn.extension()
class MapCountry(param.Parameterized):
continent = param.ObjectSelector(default="Asia", objects=["Africa", "Asia", "Europe"])
country = param.ObjectSelector(default="China", objects=["China", "Thailand", "Japan"])
settings_panel = param.Parameter()
_countries = {
"Africa": ["Ghana", "Togo", "South Africa", "Tanzania"],
"Asia": ["China", "Thailand", "Japan"],
"Europe": ["Austria", "Bulgaria", "Greece", "Portugal", "Switzerland"],
}
def __init__(self, **params):
super().__init__(**params)
self.settings_panel = pn.Param(self, parameters=["continent", "country"])
@param.depends("continent", watch=True)
def _update_countries(self):
countries = self._countries[self.continent]
self.param["country"].objects = countries
self.country = countries[0]
class GoogleView(Viewer):
map_panel = param.Parameter()
country = param.String()
def __init__(self, **params):
super().__init__(**params)
self.map_panel = pn.pane.HTML()
self._update_map()
@param.depends("country", watch=True)
def _update_map(self):
iframe = f"""
<iframe width="100%" height="100%" src="https://maps.google.com/maps?q={self.country}&z=6&output=embed"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
"""
self.map_panel.object = iframe
map = MapCountry(name="Country Selection")
view = GoogleView(name="Google Map viewer")
app = pn.Column(map.settings_panel,
view.map_panel)
app.servable()