[OpenLayers-Users] Users Digest, Vol 93, Issue 5

Zachary L. Stauber zachary at stauber.org
Mon Jun 9 14:10:52 PDT 2014


 

On Jun 9 2014 7:41 AM, openlayers-users-request at lists.osgeo.org
wrote: 

> OK, thanks for the recommendation on the PHP solution. I may
have to bite the bullet and start learning about PHP. I've seen that
HTML5Rocks page before, but it talks about GET and POST requests and
XmlHttpRequest, and I'm sure OpenLayers is doing that under the hood,
but it's all wrapped in the OpenLayers JavaScript as far as the user is
concerned, so I am not sure how to apply it in this case.
> 
> I was
hoping there was some way of enabling a flag on the JS parameter object
that creates the layer that just does makes CORS work. Somehow Esri's
JavaScript widgets are able to bring in data from any number of various
sources, and this issue never comes up, so they are be doing their own
enabling built into their widget methods I guess. This seems like a
really big limitation considering one of the main uses of OpenLayers is
to mash up layers from various sources.
> 
> -Zack Stauber
> 
> Date:
Mon, 09 Jun 2014 08:34:51 -0500
> From: Ryan Williams
<rwilliams at paqinteractive.com>
> To: openlayers-users at lists.osgeo.org
>
Subject: Re: [OpenLayers-Users] WFS layer
>
Cross-Origin-Resource-Sharing not working
> Message-ID:
<5395B7FB.5060608 at paqinteractive.com>
> Content-Type: text/plain;
charset="iso-8859-1"; Format="flowed"
> 
> Hi Zack,
> If you want to try
and keep all the code in JavaScript you can look at 
>
http://www.html5rocks.com/en/tutorials/cors/ [4]
> I use a PHP proxy
file here that uses CURL, partly because I had PHP 
> programmers to
help and partly because it avoids compatibility issues 
> with browsers
that can occur with the CORS options.
> I'm a GIS guy that learned Web,
and I can say the PHP proxy option 
> doesn't take a lot to implement.
It does require that you have PHP on 
> your Web server.
> Anyway, if
you're interested in trying this option I attached an example 
> of the
code I use. It has worked well for us for years.
> You'd modify it to
include your domain names or IPs, and save it in the 
> root folder of
your website.
> You would then modify the JavaScript that creates your
map to set 
> OpenLayers.ProxyHost to the URL of the proxy file:
> 
>
OpenLayers.ProxyHost="http://192.168.0.128:443/testproxy.php?url=
[5]";
> 
> I haven't tried the CORS methods described in the link above,
but I have 
> used JSONP to query databases directly and that works
well, but that 
> requires server-side programming as well.
> 
> -
Ryan
> 
> -- 
> Ryan Williams
> GIS Analyst / Programmer
> PAQ
Interactive Inc.
> 
> On 6/8/2014 3:29 PM, zachary at stauber.orgwrote:
>

>> Hello, I've been able to use OpenLayers to reference a KML file on
the same server as my OpenLayers script, inside an HTML file, but once
have it pointing to a WFS service on a GeoServer that references a
PostGIS table, it gives me the FireFox/FireBug error: "Cross-Origin
Request Blocked: The Same Origin Policy disallows reading the remote
resource at https://192.168.0.128:6443/geoserver/turner/wfs [1]. This
can be fixed by moving the resource to the same domain or enabling
CORS." Interesting thing is it is all, in fact, on the same server (all
same IP). But the HTML/OpenLayers file is served up via Apache2 on port
443, and the GeoServer is on Tomcat's port 6443. But it will be on
different servers eventually, so regardless I need to get this working.
Can anyone help? I'm a GIS guy, not a web guy (yet), not a PHP guy, so
I've seen some solutions suggesting a PHP proxy, but I don't understand
that, and I'd rather do it all in JS since I'm already using that for
OpenLayers and supposedly it can all work through JS. Here's the stuff
in my OpenLayers HTML file called earlyvoting2.html: var
earlyabsentee_wfs = new OpenLayers.Layer.Vector("Early Voting",{
strategies: [new OpenLayers.Strategy.Fixed()], projection:
map.displayProjection, protocol: new OpenLayers.Protocol.WFS({ version:
"1.1.0", srsName: "EPSG:4326", url:
"https://192.168.0.128:6443/geoserver/turner/wfs [1]", featureNS:
"https://192.168.0.128:6443/geoserver/turner [2]", featureType:
"brown:earlyabsentee", }) }); I'm using IP's because I haven't bought a
static IP certificate yet, but for purposes of this post let's say in my
intranet 192.168.0.128 is an Ubuntu 14.04 server named Turner, and
everything is on it (PostGIS, Apache2, Tomcat, GeoServer, etc.). I don't
quite understand, since I can bring the same layer in as a WMS link in a
stubbed out OpenLayers page with one layer from the Layer Preview page
in GeoServer, so it does CORS there. But it hates WFS. -Zack Stauber
_______________________________________________ Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users [3]
> 
>
-------------- next part --------------
> An HTML attachment was
scrubbed...
> URL:
<http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment.html
[6]>
> -------------- next part --------------
> An HTML attachment was
scrubbed...
> URL:
<http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment-0001.html
[7]>
> 
> ------------------------------
> 
>
_______________________________________________
> Users mailing list
>
Users at lists.osgeo.org
>
http://lists.osgeo.org/mailman/listinfo/openlayers-users [3]
> 
> End of
Users Digest, Vol 93, Issue 5
> ************************************




Links:
------
[1] https://192.168.0.128:6443/geoserver/turner/wfs
[2]
https://192.168.0.128:6443/geoserver/turner
[3]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
[4]
http://www.html5rocks.com/en/tutorials/cors/
[5]
http://192.168.0.128:443/testproxy.php?url=
[6]
http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment.html
[7]
http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment-0001.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/f133b81f/attachment.html>


More information about the Users mailing list