GeoJSON数据没有显示在矢量图层上
我试图显示一个矢量图层来显示一组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/,显示它不工作,但我无法弄清楚这与原来的教程有什么不同。
给定样式对象不正确的点,因此功能只是不显示。尝试:
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 8,
stroke: new ol.style.Stroke({
color: 'red',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.2)'
})
})
})
请注意,在原始代码中,还有另一个问题。坐标必须转换到EPSG:3857:
features: (new ol.format.GeoJSON()).readFeatures(
geoData,
{featureProjection: ol.proj.get('EPSG:3857')}
)
就是这样。因为我不是一个圆圈而是一个点,它不会显示任何东西。 – Saurbaum
这jsfiddle示例jsfiddle.net/zqx6644q/不能正常工作......两点绘制在0 lat 0 lon。我试图解决这个问题。
这实在是一个评论,而不是一个答案。有了更多的代表,[你将能够发表评论](// *.com/privileges/comment)。 –
对不起,男人,刚开始在这个网站的路径...我怎样才能赚取代表? – Koba
这些坐标位于WGS,而地图位于EPSG:3857。您需要将坐标从EPSG:4326转换为EPSG:3857,这里更新了小提琴:http://jsfiddle.net/zqx6644q/8/ – user1702401
我在jsfiddle中玩过。我用openlayers geoJSON示例数据换出了数据,并且它工作正常,所以我会认为问题出在您的geojson数据本身。我注意到它缺少关于CRS顶部的代码片段,请参阅geojson示例上的示例数据顶部。我在NAD83的EPSG代码中添加了,仍然没有显示。对不起,我无法提供更多的帮助,但我可以告诉你,代码本身正在工作,它只是geojson源数据不起作用。 – 1saac