this code works with local kml files, but not when the kml files are on my other server, I got 3 error :
OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml 404 (Not Found) XMLHttpRequest.js:220
OPTIONS http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml Origin http://localhost is not allowed by Access-Control-Allow-Origin. XMLHttpRequest.js:220
XMLHttpRequest cannot load http://192.168.0.150:9000/files/anonymous/AVGHDOP.kml. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
so, I try to put headers in the OpenLayers.Protocol.HTTP. but it still is not working -_-. here is my code:
map = new OpenLayers.Map('map');
osm = new OpenLayers.Layer.OSM();
vectors = new OpenLayers.Layer.Vector("KML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: url_file,//the file is on an other_server(a play server).
headers: {
"Access-Control-Allow-Origin":"*",
"Access-Control-Allow-Headers":"Access-Control-Allow-Origin"},
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
})
});
map.addLayers([osm, vectors]);
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.EditingToolbar(osm));
vectors .events.register("loadend", vectors , function (e) {
map.zoomToExtent(vectors .getDataExtent());
});
I dont know if I can configure a proxy. So if I can solve this problem without it it would be great :)
No comments:
Post a Comment