2

I want to use external SLD file in my OpenLayers application. So I created WMS layer like this:

     var ly= new OpenLayers.Layer.WMS("mylyer",
        serverurl,
        {
           layers: "PGS:geopoint",
           transparent:true,
           style:"",
           sld: "http://localhost/app/style/point.xml"
        },
        { 
           isBaseLayer: false,
           buffer:0
        });

This is not working. This is returning null images. If I send request from browser (not openlayers) it returns error:

java.net.ConnectException: Connection refused Connection refused

  • Is your server running? What do you get when you put http://localhost/app/style/point.xml into your browser address bar? Is it different if you add a port, like this: http://localhost:8080/app/style/point.xml – andytilia Nov 13 '14 at 13:25
3

http://localhost/ will be interpreted by the WMS server as its own host, but the SLD you want to use is on your app's host (let's say http://myapp.com/. So yo will have to change your SLD URL to the app's public URL (using its FQDN), e.g. http://myapp.com/style/point.xml:

    {
       layers: "PGS:geopoint",
       transparent:true,
       style:"",
       sld: "http://myapp.com/style/point.xml/point.xml"
    },

Depending on your WMS implementation, there may be a shortcut if both the WMS and the app run on the same host, e.g. a relative URL or a file URL, but using the FQDN of the app host is the safest way to go.

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.