0
我想在我的地图上显示一些多边形,我是新的整个OpenLayers地图geojson的东西,所以请温柔请:)。OpenLayers 2,GeoJSON不能获得坐标
首先哪些工作:
vector1 = new OpenLayers.Layer.Vector("GeoJSON1",
{
projection : "EPSG:4326",
strategies : [new OpenLayers.Strategy.Fixed()],
protocol : new OpenLayers.Protocol.HTTP({
url: "test.php",
format: new OpenLayers.Format.GeoJSON()
})
});
这段代码工作,从test.php的显示在服务器上,在位置,应该是GeoJSON的。但我试图达到的geojson是在另一台服务器上,它会抛出错误(我知道我可以设置标题,它会工作),但我不想这样做。
这不工作:
var geojs_format = new OpenLayers.Format.GeoJSON();
var geojsval= {
"type": "Polygon",
"coordinates":
[[[11.0878902207, 45.1602390564],
[14.931640625, 40.9228515625],
[0.8251953125, 41.0986328125],
[7.63671875, 48.96484375],
[11.0878902207, 45.1602390564]]]
};
vector = new OpenLayers.Layer.Vector("GeoJSON",{projection:"EPSG:4326"});
vector.addFeatures(geojs_format.read(geojsval));
这不工作 - 它在不同的地方显示的多边形即使投射在同样的方式指定(或至少对我来说...)。
今后请不要交叉提问。有关更多信息,请参阅[这里](http://meta.stackexchange.com/q/64068)。 – Matt