Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Openlayers 5中加载Vanilla GeoJSON_Openlayers_Openlayers 5 - Fatal编程技术网

无法在Openlayers 5中加载Vanilla GeoJSON

无法在Openlayers 5中加载Vanilla GeoJSON,openlayers,openlayers-5,Openlayers,Openlayers 5,我从我使用的一些有效的GeoJSON开始。我的愿望是将其加载到Openlayers 5地图中 我从开始,并尝试使用远程源来代替本地源。相关块如下所示: var映射=新映射({ 图层:[ 新瓦工({ 资料来源:新OSM() }) ], 目标:“地图”, 视图:新视图({ 中心:[-13739617.9393466179221.917031], 缩放:11 }) }); map.once(“postrender”,()=>{ get(jsonUrl).then({data}={})=>{ cons

我从我使用的一些有效的GeoJSON开始。我的愿望是将其加载到Openlayers 5地图中

我从开始,并尝试使用远程源来代替本地源。相关块如下所示:


var映射=新映射({
图层:[
新瓦工({
资料来源:新OSM()
})
],
目标:“地图”,
视图:新视图({
中心:[-13739617.9393466179221.917031],
缩放:11
})
});
map.once(“postrender”,()=>{
get(jsonUrl).then({data}={})=>{
const jsonSource=新矢量源({
功能:新建GeoJSON().readFeatures(数据、{
功能投影:“EPSG:4326”
})
});
const jsonLayer=新矢量层({
资料来源:jsonSource,
样式:jsonStyleFunction
});
addLayer(jsonLayer);
});
});
当我加载失败时,我可以使用控制台日志来确定断点不是get请求。我还能够看到,在
jsonSource
const中,有相同数量的
featureChangeKeys\uuu
,因为我的JSON对象中有一些功能:

featureChangeKeys_:
39: (2) [{…}, {…}]
41: (2) [{…}, {…}]
43: (2) [{…}, {…}]
45: (2) [{…}, {…}]
47: (2) [{…}, {…}]

问题在于,您试图将数据加载到与地图本身不同的坐标参考系(CRS)中。默认情况下,地图加载在EPSG:3857投影中,而大多数GeoJSON加载在EPSG:4326中

您可以通过“查找空岛”来测试这一点。将地图平移到latlong(0,0),您可能会看到一个小点,如下所示:

如果您看到上面这样的小斑点,那么这肯定是问题所在。要解决此问题,可以通过定义
featureProjection
dataProjection
属性,让Openlayers动态转换数据:

constjsonsource=newvectorsource({
功能:新建GeoJSON().readFeatures(数据、{
数据投影:“EPSG:4326”,
功能投影:“EPSG:3857”
})
});