The plot never updates

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()


Hi @Ahmet

The app looks like below to me.

I’m not sure what you would expect from the map or your code. Could you make it clearer?

Looking at your code you have @param.depends('x_range', 'y_range'). But x_range and y_range are not defined as parameters. They are just normal python attributes. I.e. you cannot pn.depends on them. Furthermore there is no watch=True, so it would not be triggered any ways.

You also have self.range_stream.add_subscriber(self.change_range). This might be working though.

But again I don’t understand how you expect this to work :+1:

Thank you…

Using zoombox tool, I am trying to get bounding_box values through range_x/y for bbox parameter of map request to remote map server. I am getting the new wms image but I cannot replace it with existing layer. or I cannot update jeo layer.
I will review the code as you have suggested.

There is:
self.x_range = self.range_stream.param.x_range

This seems to be working.I am getting x_range and y_range values.
@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]}")

However , I am doing some wrong.

kind regards