Hello All,
So I’ve been reading about wms layers and I see that it’s in different branches (maybe) or has been merged to main branch…
Can someone let me know if using a WMS layer is possible from the main branch, and if yes what it is I need to do?
Thanks all.
TOby
Hi Toby,
WMS layers are supported in master and in the b10 release that was just posted today (https://github.com/AnalyticalGraphicsInc/cesium/downloads). To see how to add a WMS layer to Cesium, take a look at the “Imagery Layers” example in Sandcastle. It uses two different layers loaded from a WMS source.
Kevin
Great, thanks Kevin.
Do you have any experience in creating a webGL proxy in php? I seem to be running into issues with passing through the images through mine, although it works fine for non webGL maps…
Toby
Hi Toby,
No, I don’t have any experience with PHP. Perhaps someone else here does? I can give you the general idea of what is necessary, though.
As a security precaution, WebGL requires that all textures used in rendering be loaded from the same origin as the HTML page, or via a valid CORS request. When using a WMS-based imagery layer, the images are almost always coming from a different origin. If you have control over the WMS server, the best solution by far is to configure it to allow CORS access. This page describes how to enable CORS access in various environments:
http://enable-cors.org/
If enabling CORS is not an option, the next best thing is to proxy requests to the WMS server through a service running on the same web server that hosts the HTML page. That way, from the standpoint of the browser, the images are coming from the same origin. This is what the “Imagery Layers” Sandcastle example does, by using a proxy service built into our Jetty-based development server. Recreating this proxy service in other environments like PHP should be fairly straightforward. It simply needs to accept a target URL as a parameter, request that URL itself, and then return the results to the original caller, taking care to preserve headers and such along the way. The really critical thing, though, is that it must run on the exact same hostname and port as the server that hosts the HTML pages in which Cesium is embedded.
I hope this helps,
Kevin
Hi Kevin,
That’s very helpful thanks. Cors isn’t an option sadly, so will do some more digging on the proxy side.
Thanks again.
Toby
Hi Kevin,
One more -
I managed to get the proxy working on my system, which is great - although there is one prob.
I can’t use the “Cesium.DefaultProxy()” because my proxy is in the format of /proxy.php?url=
and if I use that method above it’ll try and do "etc/proxy.php?url=?etcetc
So I have removed the proxy : new Cesium.DefaultProxy(’/proxy/’)
line in the layer set up, and pre-fixed the layer url with /proxy.php?url=http%3A%2F%2Fmesonet.agron.iastate.edu%2Fcgi-bin%2Fwms%2Fnexrad%2Fn0r.cgi%3F
but the rest of the url (when generated) doesn’t get encoded, which means it doesn’t work. If i take the decoded url, encode it and put it through the proxy I get what I want…
Am I doing things wrong? Can I somehow force the encoding? I presume it’ll encode if I use the “proxy” parameter, so can that be "proxy: “/proxy.php?url=”?
Toby
Hi Toby,
I’d say that’s a bug in the DefaultProxy, and the best solution is to fix the bug. Fortunately, DefaultProxy is just a few lines of code. As a quick fix for your needs, just take out the concatenation of the “?” in the getURL method. A more thorough fix is to check for the existence of the “?” and only add it if it doesn’t already exist.
Kevin