我试图显示一个矢量图层来显示一组geojson功能。GeoJSON数据没有显示在矢量图层上
当我尝试并添加层,虽然我得到的ol.js库是错误的“k.xd是不是一个函数”
var geoData = {"type":"FeatureCollection",
"features":
[
{"type":"Feature","properties":{"Name":"","Description":""},"geometry":{"type":"Point","coordinates":[0.0,0.0]}},
{"type":"Feature","properties":{"Name":"1","Description":""},"geometry":{"type":"Point","coordinates":[11.50728,3.87471,0.0]}},
]
};
// vector layer
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geoData)
}),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'red',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.2)'
})
})
});
我在这里一起砍死一个例子http://jsfiddle.net/dxt95yt6/1/,显示它不工作,但我无法弄清楚这与原来的教程有什么不同。
我在jsfiddle中玩过。我用openlayers geoJSON示例数据换出了数据,并且它工作正常,所以我会认为问题出在您的geojson数据本身。我注意到它缺少关于CRS顶部的代码片段,请参阅geojson示例上的示例数据顶部。我在NAD83的EPSG代码中添加了,仍然没有显示。对不起,我无法提供更多的帮助,但我可以告诉你,代码本身正在工作,它只是geojson源数据不起作用。 – 1saac