【发布时间】:2015-10-17 11:59:43
【问题描述】:
我正在使用 Openlayers 3 并想添加一个层,其中 TurfJS 函数“合并”的答案应该是源。 直接在 OpenLayers 3 中添加 GeoJSON-Layer 没有问题并且工作正常。 但是当我在变量中加载 GeoJSON 文件并使用 turf.merge(source) 时,不能再将其添加到图层中。 我已经尝试将 turf.merge 的答案转换为 FeatureCollection 并将其添加为图层源,但这也不起作用
//define source (contains Polygons)
var source = new ol.source.Vector({
url: 'geb03_f_source.geojson',
format: new ol.format.GeoJSON({
})
});
//Merge source
var merged = turf.merge(source);
//define layer
var vectorLayer = new ol.layer.Vector({
source: merged,
projection: 'EPSG:3857'
});
//add layer to map
map.addLayer(vectorLayer);
我看到的问题是,在加载页面时,GeoJSON-File 没有加载,尽管它应该加载。
但只是加载和显示文件有效:
var source = new ol.source.Vector({
url: 'geb03_f_source.geojson',
format: new ol.format.GeoJSON({
})
});
var vectorLayer = new ol.layer.Vector({
source: source,
projection: 'EPSG:3857'
});
map.addLayer(vectorLayer);
使用草皮合并时,GeoJSON-Fomat 可能有问题? 我很高兴得到每一次帮助!
【问题讨论】:
-
控制台显示“TypeError: t.features is undefined”。加载的 GeoJSON-Feature 的格式似乎不对...
-
别忘了提供反馈。你得到了答案。
标签: json openlayers-3 geojson turfjs