ThinkGeo.com    |     Documentation    |     Premium Support

WmsAsyncLayer - change CRS

Hello,
what’s the correct way to change the Crs of WMS Layer after it is loaded.
The following code doesn’t work (version 14.2.1) :

    async Task changeSrid(int newSrid)
    {
        if (srid == newSrid) return;
        srid = newSrid;
        var wasOpen = this.IsOpen;
        await this.OpenAsync(); // doesn't matter
        this.Crs = $"EPSG:{newSrid}";
    }

If I check the requested url in SendingHttpRequest - the Crs is no changed.

Regards
Torsten

Hi Torsten,

You can close the layer, set the property, and then open it, something like the following:

class MyWmsWmsAsyncLayer : WmsAsyncLayer
{
    private int srid = 3857;

    public MyWmsWmsAsyncLayer(Uri uri)
        : base(uri)
    {
    }

    public async Task ChangeSrid(int newSrid)
    {
        if (srid == newSrid) return;
        srid = newSrid;
        
        await this.CloseAsync(); // doesn't matter
        this.Crs = $"EPSG:{newSrid}";
        await this.OpenAsync(); // doesn't matter
    }
}

Thanks,
Ben

Hi Ben,

that works perfect!
Thanks Torsten

That’s awesome! :+1: