Hi,
I am trying to get wms map from a server and depending on bounds value, map should be updated.
In the following code, the plot never updates even if change_range function operates and getting the wms image properly. In that function this has no effect. self.plot = tiles * self.jeo.opts(width=1050,height=700)
What am I doing wrong
import panel as pn
import param
import holoviews as hv
import numpy as np
import requests
from PIL import Image
from io import BytesIO
from holoviews.streams import RangeXY
hv.extension('bokeh')
pn.extension(throttled=True)
tiles = hv.element.tiles.OSM()
class Range(param.Parameterized):
def __init__(self, **params):
super().__init__(**params)
xmin=2866476
xmax=4981476 #
ymin=4293472
ymax=5168472 #
self.range_stream = RangeXY(source=tiles)
# Add the change_range method as a subscriber to the RangeXY stream
self.range_stream.add_subscriber(self.change_range)
self.x_range = self.range_stream.param.x_range
self.y_range = self.range_stream.param.y_range
### Replace the placeholders in the URL string with the bounding box values
self.url = "https://depmap.afad.gov.tr/ms/?map=/map/jeo_yas2wms.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&layers=jeo&styles=&SRS=EPSG:3857&WIDTH=1050&HEIGHT=700&FORMAT=image/png&bbox={XMIN},{YMIN},{XMAX},{YMAX}"
self.url = self.url.format(XMIN=xmin, YMIN=ymin, XMAX=xmax, YMAX=ymax)
response=requests.get(self.url)
img=Image.open(BytesIO(response.content))
self.jeo = hv.RGB(np.array(img),bounds=(xmin,ymin,xmax,ymax)).opts(alpha=0.5)
self.plot = tiles * self.jeo.opts(width=1050,height=700)
self.range_stream.source = self.plot
def _update(self):
self.plot = tiles * self.jeo.opts(width=1050, height=700)
self.range_stream.source = self.plot
@param.depends('x_range', 'y_range')
def change_range(self, x_range, y_range):
print(f"New x-axis range: {x_range[0]}, {x_range[1]}, New y-axis range: {y_range[0]}, {y_range[1]}")
### Define the bounding box values for the area of interest
xmin, xmax = x_range[0],x_range[1]
ymin, ymax = y_range[0],y_range[1]
if np.isnan(xmin) :
xmin, xmax, ymin, ymax = np.nan_to_num([xmin, xmax, ymin, ymax], nan=[2866476, 4981476, 4293472, 5168472])
### Replace the placeholders in the URL string with the bounding box values
url = "https://depmap.afad.gov.tr/ms/?map=/map/jeo_yas2wms.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&layers=jeo&styles=&SRS=EPSG:3857&WIDTH=1050&HEIGHT=700&FORMAT=image/png&bbox={XMIN},{YMIN},{XMAX},{YMAX}"
url = url.format(XMIN=xmin, YMIN=ymin, XMAX=xmax, YMAX=ymax)
print ("url ",url)
response=requests.get(url)
img=Image.open(BytesIO(response.content))
self.jeo = hv.RGB(np.array(img),bounds=(xmin,ymin,xmax,ymax)).opts(alpha=0.5)
self.plot = tiles * self.jeo.opts(width=1050,height=700)
self.range_stream.source = self.plot
def view(self):
self._update()
return pn.panel(self.plot)
app = Range()
range_param = Range(name="Axis Ranges")
pn.Column(app.param, app.view, width=1000, height=700).servable()