On Wednesday, October 6, 2010, Mak Kolybabi <[email protected]> wrote:
> Here's my situation: I have two servers, one of which I want to serve my main 
> OpenLayers page from, and another server which I want to serve tiles and 
> features from. Serving tiles from another host is easy, of course. However 
> pulling features stored in JSON files that describe the vector layers doesn't 
> work due to the same origin restrictions.
>
> To get around the same origin restriction, I can write a static <script 
> src="foo.json"> tag into my HTML. And then I could make the JSON file be in 
> the format of foo = {};
>
> The thing I can't figure out is, if I had the JSON data already in GeoJSON 
> format, in a Javascript variable, how do I make an OpenLayers layer out of it?


var format = new OpenLayers.Format.GeoJSON();
var features = format.read(foo);
vectorLayer.addFeatures(features);

Have you considered using a callback function? If your response looks
like "callback(...)" your JS code will be

function callback(geojson) {
     var format = new OpenLayers.Format.GeoJSON();
    var features = format.read(geojson);
    vectorLayer.addFeatures(features);
}

Cheers,

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to