[OpenLayers-Users] CORS

Tomas Straupis tomasstraupis at gmail.com
Tue Jan 3 16:40:10 EST 2012


Thank you for your answers.
Unfortunately it does not work yet...
I've added this to the php providing data:

<some functions here>
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    // return only the headers and not the content
    // only allow CORS if we're doing a GET - i.e. no saving for now.
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']) &&
              $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] == 'GET') {
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: X-Requested-With');
    }
    exit;
}
<other code calling functions above etc.>

Otherwise the php code is the same (fetching data and creating a
geoJSON output).

JS code for vector layer looks like this (MyVector is only overloading
drawFeature from Vector):

  var poi = new OpenLayers.Layer.MyVector("Istoriniai", {
      strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1.1})],
      protocol: new OpenLayers.Protocol.HTTP({
               url: "someserver.lt/poi.php?type=monument",
               format: new OpenLayers.Format.GeoJSON({ignoreExtraDims: true}),
           })
       });
  poi.setVisibility(false);
  map.addLayer(poi);

Browser used is firefox 9.0.1 on f16/f15. Everything works just fine
if I'm using a proxy or placing poi.php on the same domain (which is
only possible in development environment).

I will check http://openlayers.org/dev/examples/cross-origin.html to
see if I can use the code/ideas there.

Thank you

-- 
Tomas Straupis


More information about the Users mailing list