我从FeatureOverlay获得了一个几何体,并从这个几何体创建了一个特征,当我将setId和setGeometryName设置为该特征时,我将无法写入该特征,这是一个错误吗?
var poly = featureOverlay.getFeatures().item(0);
if (poly != null) {
var feature = new ol.Feature({
geometry: poly
});
feature.setId('bd355df3fd916d30');
feature.setGeometryName('test');
var extent = [0, 0, 749, 638];
var projection = new ol.proj.Projection({
code: 'xkcd-image',
units: 'pixels',
extent: extent
});
var geoJSON = new ol.format.GeoJSON({
defaultDataProjection: projection
});
//this will be success
var geoJSONText = geoJSON.writeFeature(poly, {
featureProjection: projection,
dataProjection: projection
});
//this will be failed
var geoJSONText = geoJSON.writeFeature(feature, {
featureProjection: projection,
dataProjection: projection
});
}
Uncaught TypeError: Converting circular structure to JSON
l.qd @ openlayers?v=YGwTOEaGf-vdYCn0EwOqEIY8JyARvCDFTRAySewZwRI1:501
stopInteraction @ testedit?id=8b0d3745a6c1b46b:447
onclick @ testedit?id=8b0d3745a6c1b46b:230
答案 0 :(得分:0)
这是我的问题。
feature.setId('bd355df3fd916d30');
feature.setGeometryName('test');
修改为将被修复:
feature.setId('bd355df3fd916d30');
feature.setProperties(['test']);