1

I had an issue with WMS requests from OpenLayers to Geoserver via Proxy.php. My OL version is 2.12 and my Geoserver is 2.4.0. I set the variable OpenLayers.ProxyHost as shown in OL documentation, but the requests go directly to the remote IP not passing through Proxy.php. I read on forums that OpenLayers WMS requests have this problem, and suggest to use this getURL class:

var proxyHost=OpenLayers.ProxyHost="proxy.php?url=";
var myWMS = OpenLayers.Class(OpenLayers.Layer.WMS, {

    getURL: function (bounds) {
        var url = OpenLayers.Layer.WMS.prototype.getURL.call(this, bounds);
        if (OpenLayers.ProxyHost && OpenLayers.String.startsWith(url, "http")) {
            url = OpenLayers.ProxyHost + encodeURIComponent(url);
        }
        return url;
    }
});

Are you aware of this? is it a bug of OpenLayers? Does OL need a fix?

1

This is the expected behavior of OpenLayers.ProxyHost. ProxyHost is there to get around the same-origin policy that prevent browser to do AJAX request to URL different from the application URL. If you look at the WFS OpenLayers example, you will notice that the WFS request go through the Proxy, but the WMS request don't. WFS queries are subject to this browser limitation and WMS request are not. This is why you have to this getURL function if you want to have your WMS request go throught the same proxy:

var myWMS = OpenLayers.Class(OpenLayers.Layer.WMS, {

  getURL: function (bounds) {
    var url = OpenLayers.Layer.WMS.prototype.getURL.call(this, bounds);
    if (OpenLayers.ProxyHost && OpenLayers.String.startsWith(url, "http")) {
        url = OpenLayers.ProxyHost + encodeURIComponent(url);
    }
    return url;
  }
});

The next question is, do you really need the WMS request go through this proxy? If yes, you could also use it as your WMS URL directly.

  • Also, if you try this and it doesn't seem to work and you are using the python proxy OL provides you will probably need to change line 62 from "print y.read()" to "sys.stdout.write(y.read))" and on Windows call the script with the -u flag. Otherwise it tries to do an implicit call to str() which might corrupt your image. – bshender Oct 11 '13 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.