[Geoserver-users] Change WMS SLD Through OpenLayers For Cached Layers

Hello GeoServer List,

I just recently resolved the issue of changing my layers style through OpenLayers using:

myLayer.mergeNewParams({sld :‘file:///usr/local/geoserver-2.0.2/data_dir/styles/myLayerSLD.sld’, styles: null});

and that works great if I am using WMS layers which are not cached by GeoWebCache.

But if my layers are cached, using the above does not work. I have also tried using

myLayer.redraw(true);

Which is an OpenLayers library method that I believe is called automatically with the call to mergeNewParams, so I knew it wouldn’t work.

So now I am assuming that I have to set-up something in my GeoWebCache to accept dynamic SLD. Any ideas or hints?

I truly appreciate your help. Thank you,

elshae

On Fri, Jan 21, 2011 at 12:12 PM, IT Intern <itintern12@anonymised.com> wrote:

Hello GeoServer List,

I just recently resolved the issue of changing my layers style through
OpenLayers using:

myLayer.mergeNewParams({sld
:'file:///usr/local/geoserver-2.0.2/data_dir/styles/myLayerSLD.sld', styles:
null});

If you have installed your SLD file in the style directory you should
be able to refer to it directly using its name in the styles:
parameter. I think that will help with your cache problem too.

Ian

On Fri, Jan 21, 2011 at 12:12 PM, IT Intern <itintern12@anonymised.com> wrote:

I just recently resolved the issue of changing my layers style through
OpenLayers using:

myLayer.mergeNewParams({sld
:'file:///usr/local/geoserver-2.0.2/data_dir/styles/myLayerSLD.sld', styles:
null});

and that works great if I am using WMS layers which are not cached by
GeoWebCache.

But if my layers are cached, using the above does not work. I have also
tried using

myLayer.redraw(true);

Which is an OpenLayers library method that I believe is called automatically
with the call to mergeNewParams, so I knew it wouldn't work.

So now I am assuming that I have to set-up something in my GeoWebCache to
accept dynamic SLD. Any ideas or hints?

If you're going to be requesting layer images with dynamic styling
then you can't use the cached version of the layer; the cached version
is pre-rendered with whatever styles were set on the layer in
geoserver and/or gwc. GWC *can* be set up to cache multiple versions
of a layer based on the values in the STYLES= (or any other) wms
parameter, but that won't work if you are using truly dynamic styles;
for example if you let the user choose arbitrarily style parameters on
the client side and build an SLD from that.

If your SLD really is dynamic you're going to have to use the
non-cached version of the layer. If your GWC and Geoserver layers map
1:1 with each other (which is true for a standard install without a
geowebcache.xml file) then just removing "gwc/service/" from the layer
URL will get you the non-cached version. For example:

gwc url: http://localhost:8080/geoserver/gwc/service/wms
non-cached url: http://localhost:8080/geoserver/wms

Thanks again Joshua for guiding me through this.

“If you’re going to be requesting layer images with dynamic styling
then you can’t use the cached version of the layer; the cached version
is pre-rendered with whatever styles were set on the layer in
geoserver and/or gwc.”

I was afraid of this…that’s just too bad :(. I want to cache my layers and be able to switch the SLD with OpenLayers (I’m truly heartbroken here)

“GWC can be set up to cache multiple versions
of a layer based on the values in the STYLES= (or any other) wms
parameter, but that won’t work if you are using truly dynamic styles;
for example if you let the user choose arbitrarily style parameters on
the client side and build an SLD from that.”

How come? What I mean to ask is that even if the user does pick the SLD and it is built on the fly, wouldn’t that SLD still have to be set-up in the same format as that read from the file?

"If your SLD really is dynamic you’re going to have to use the
non-cached version of the layer. If your GWC and Geoserver layers map
1:1 with each other (which is true for a standard install without a
geowebcache.xml file) then just removing “gwc/service/” from the layer
URL will get you the non-cached version. For example:

gwc url: http://localhost:8080/geoserver/gwc/service/wms
non-cached url: http://localhost:8080/geoserver/wms"

Yes, I was first trying this with my non-cached layers. When you first helped me with this :), but I had forgotten about my cached layers and as I was working, realized that it’s probably not going to be a possibility :frowning:

Thanks so much for all your help!

Happy Mapping,

elshae

On Fri, Jan 21, 2011 at 3:47 PM, Joshua M. Thompson <joshua.thompson@anonymised.com> wrote:

On Fri, Jan 21, 2011 at 12:12 PM, IT Intern <itintern12@anonymised.com> wrote:

I just recently resolved the issue of changing my layers style through
OpenLayers using:

myLayer.mergeNewParams({sld
:‘file:///usr/local/geoserver-2.0.2/data_dir/styles/myLayerSLD.sld’, styles:
null});

and that works great if I am using WMS layers which are not cached by
GeoWebCache.

But if my layers are cached, using the above does not work. I have also
tried using

myLayer.redraw(true);

Which is an OpenLayers library method that I believe is called automatically
with the call to mergeNewParams, so I knew it wouldn’t work.

So now I am assuming that I have to set-up something in my GeoWebCache to
accept dynamic SLD. Any ideas or hints?

If you’re going to be requesting layer images with dynamic styling
then you can’t use the cached version of the layer; the cached version
is pre-rendered with whatever styles were set on the layer in
geoserver and/or gwc. GWC can be set up to cache multiple versions
of a layer based on the values in the STYLES= (or any other) wms
parameter, but that won’t work if you are using truly dynamic styles;
for example if you let the user choose arbitrarily style parameters on
the client side and build an SLD from that.

If your SLD really is dynamic you’re going to have to use the
non-cached version of the layer. If your GWC and Geoserver layers map
1:1 with each other (which is true for a standard install without a
geowebcache.xml file) then just removing “gwc/service/” from the layer
URL will get you the non-cached version. For example:

gwc url: http://localhost:8080/geoserver/gwc/service/wms
non-cached url: http://localhost:8080/geoserver/wms

On Fri, Jan 21, 2011 at 4:32 PM, IT Intern <itintern12@anonymised.com> wrote:

"GWC *can* be set up to cache multiple versions
of a layer based on the values in the STYLES= (or any other) wms
parameter, but that won't work if you are using truly dynamic styles;
for example if you let the user choose arbitrarily style parameters on
the client side and build an SLD from that."

How come? What I mean to ask is that even if the user does pick the SLD and
it is built on the fly, wouldn't that SLD still have to be set-up in the
same format as that read from the file?

It's because GWC only knows how to do this caching by the actual WMS
parameters. In this case the parameter is 'SLD' and its value is the
URL to an SLD file. GWC won't actually retrieve and interpret the
contents of that file though.

If you can make your dynamic SLD always have a unique filename based
on the file contents (perhaps using a SHA or MD5 hash of the contents
as the filename) you could possibly make it work like you want. You
would think this through carefully though because if you have a lot of
varying styles being used you could start to fill your cache with
stuff that is never used again, and if you have cache expiration set
up it's possible that you might start pushing out things you WANT to
save.

I've generally found that caching is best for things like base maps
that never change. Also, due to complications making labels work well
with tiles it's usually best to not cache layers that have labels in
them, unless you carefully place your labels. When I wrote LL-MAP we
ended up caching the actual base maps, but the overlays with country
borders & labels are done as a regular WMS layer. We also don't cache
or tile user-generated maps for similar reasons (plus, those maps
usually are usually very simple, and not worth the effort of making
them work with the cache.)

Just chiming in to add to Joshua's excellent explanations that you
(Joshua) might be interested in the new cache disk quota
functionality[1], as you mention certain concern about the cache growing
unbounded. Fear no more! set a cache disk quota and choose your
expiration policy :).

Cheers,
Gabriel
[1]
<http://docs.geoserver.org/stable/en/user/webadmin/server/geowebcache.html&gt;

PS: the writer of this message thoroughly warns you that despite de
marketing, the functionality mentioned could well be considered beta
quality... but what couldn't? (and that a couple mistakes in the
documentation above are going to get fixed asap)

On Fri, 2011-01-21 at 17:37 -0500, Joshua M. Thompson wrote:

On Fri, Jan 21, 2011 at 4:32 PM, IT Intern <itintern12@anonymised.com> wrote:
> "GWC *can* be set up to cache multiple versions
> of a layer based on the values in the STYLES= (or any other) wms
> parameter, but that won't work if you are using truly dynamic styles;
> for example if you let the user choose arbitrarily style parameters on
> the client side and build an SLD from that."
>
> How come? What I mean to ask is that even if the user does pick the SLD and
> it is built on the fly, wouldn't that SLD still have to be set-up in the
> same format as that read from the file?

It's because GWC only knows how to do this caching by the actual WMS
parameters. In this case the parameter is 'SLD' and its value is the
URL to an SLD file. GWC won't actually retrieve and interpret the
contents of that file though.

If you can make your dynamic SLD always have a unique filename based
on the file contents (perhaps using a SHA or MD5 hash of the contents
as the filename) you could possibly make it work like you want. You
would think this through carefully though because if you have a lot of
varying styles being used you could start to fill your cache with
stuff that is never used again, and if you have cache expiration set
up it's possible that you might start pushing out things you WANT to
save.

I've generally found that caching is best for things like base maps
that never change. Also, due to complications making labels work well
with tiles it's usually best to not cache layers that have labels in
them, unless you carefully place your labels. When I wrote LL-MAP we
ended up caching the actual base maps, but the overlays with country
borders & labels are done as a regular WMS layer. We also don't cache
or tile user-generated maps for similar reasons (plus, those maps
usually are usually very simple, and not worth the effort of making
them work with the cache.)

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

--
Gabriel Roldan
groldan@anonymised.com
Expert service straight from the developers

Thank you for the generous reply Joshua. I am sorry about the delay in reply, as I am away from my project on the weekends and yesterday was not feeling so well. I see that you said that it’s probably best to just go with regular WMS layers that have labels instead of cached ones. Interesting you say this, my next approach was going to be to make a cached layer for each SLD and then just switch between the cached layers. I guess this would not be a good idea and your suggesting that I use one WMS layer/fewer WMS layers and just switch the SLD as you showed me previously?

Maybe I should start a new topic for this, but I was also wondering what would be slower/cause more overhead…A WMS layer that is constructed from many views of the PostGIS database and then switching different SLDs or several different WMS layers that rely on different, smaller views (not consisting of as many joins etc) and switching SLDs (same amount of SLDs as the first case).

If you think I should open a new topic for this question, I will. I just don’t want to fill the forum up with topic of my curious mind :stuck_out_tongue:

Thank you so much for all your help and happy mapping!

elshae

On Fri, Jan 21, 2011 at 5:37 PM, Joshua M. Thompson <joshua.thompson@anonymised.com> wrote:

On Fri, Jan 21, 2011 at 4:32 PM, IT Intern <itintern12@anonymised.com> wrote:

“GWC can be set up to cache multiple versions
of a layer based on the values in the STYLES= (or any other) wms
parameter, but that won’t work if you are using truly dynamic styles;
for example if you let the user choose arbitrarily style parameters on
the client side and build an SLD from that.”

How come? What I mean to ask is that even if the user does pick the SLD and
it is built on the fly, wouldn’t that SLD still have to be set-up in the
same format as that read from the file?

It’s because GWC only knows how to do this caching by the actual WMS
parameters. In this case the parameter is ‘SLD’ and its value is the
URL to an SLD file. GWC won’t actually retrieve and interpret the
contents of that file though.

If you can make your dynamic SLD always have a unique filename based
on the file contents (perhaps using a SHA or MD5 hash of the contents
as the filename) you could possibly make it work like you want. You
would think this through carefully though because if you have a lot of
varying styles being used you could start to fill your cache with
stuff that is never used again, and if you have cache expiration set
up it’s possible that you might start pushing out things you WANT to
save.

I’ve generally found that caching is best for things like base maps
that never change. Also, due to complications making labels work well
with tiles it’s usually best to not cache layers that have labels in
them, unless you carefully place your labels. When I wrote LL-MAP we
ended up caching the actual base maps, but the overlays with country
borders & labels are done as a regular WMS layer. We also don’t cache
or tile user-generated maps for similar reasons (plus, those maps
usually are usually very simple, and not worth the effort of making
them work with the cache.)