在项目中,需要在地图中绘画功能,选中一片区域,然后将这片区域通过editFeatures方法,添加到数据集中,
但是提交的时候经常报错: the number of 'fieldNames' and 'fieldValues' are not equal or Geometry is null
代码如下:
// 绘面
function addMark() {
if (isOn) {
addPointsSource.clear()
isOn = false;
}
draw = new ol.interaction.Draw({
source: addPointsSource,
type: 'Polygon',
snapTolerance: 20,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#00FECD',
width: 3,
}),
fill: new ol.style.Fill({
color: 'rgba(0, 290, 195, 0.8)'
})
})
});
map.addInteraction(draw);
draw.on('drawend', function (e) {
let range = e.target.sketchCoords_[0]; //图形范围
var extent = ol.extent.boundingExtent(range[0]); //获取一个坐标数组的边界,格式为[minx,miny,maxx,maxy]
var center = ol.extent.getCenter(extent); //获取边界区域的中心位置
range.push(range[0])
/* 提交到数据服务的面数据 */
let geomOne = new ol.geom.Polygon([range])
pointFeature = new ol.Feature(geomOne);
addPointsSource.addFeature(pointFeature);
console.log(pointFeature);
})
isOn = true;
}
// 提交
function commitMark() {
var addFeatureParams = new SuperMap.EditFeaturesParameters({
features: pointFeature,
dataSourceName: "ceshi",
dataSetName: "gaoxin",
editType: "add",
returnContent: true
});
console.log(addFeatureParams);
editFeaturesService.editFeatures(addFeatureParams, function (serviceResult) {
console.log(serviceResult);
});
}
这里我按照官网上的地物编辑的示例添加point点状要素时是可以的,但添加Polygon就报这个错误;
有大佬知道啥原因吗,跪求解惑。。。。。
大佬往这看,求帮忙。。。。。。