首页 / 浏览问题 / WebGIS / 问题详情
地图中绘画一个多边形,绘画的图形给数据集中添加Polygon要素,报错
33EXP 2021年07月26日

在项目中,需要在地图中绘画功能,选中一片区域,然后将这片区域通过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就报这个错误;

有大佬知道啥原因吗,跪求解惑。。。。。

大佬往这看,求帮忙。。。。。。

1个回答

您好,您是想在地图上进行绘面操作吗
1,000EXP 2021年07月26日
是的,地图绘面是可以的,主要是绘面完成后,

将绘出的图形保存为Polygon的feature要素,

然后editFeatures这个方法修改数据集 就会报上面那个错误
您这个报错信息是说要提交的这个对象不存在,提交前打印pointFeature有值吗,对比一下官网打印的结果与您的打印结果
...