arcgis for javascript api 新增要素

 arcgis for javascript api feature class applyedits 将自定义坐标系新增到图层


其中遇到的坑:

1.未开启feature server
2.arcgis默认为地理坐标系统(我们需要将地理坐标系转换成投影坐标系)即SpatialReference wkid=4326需要改成与sde中新建feature class中坐标系一致

发布featureserver服务
1、在ARCCatalog中连接sde数据库在数据库中新建featureclass
2、右键新建featureclass加载shp数据
3、在ARCMap中新建空白模板,拖动ARCCatalog新建的featureclass到图层layers中
4、修改图层属性
5、发布服务

6、编辑要素


arcgis for javascript代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试</title>
<script src="https://js.arcgis.com/4.9/"></script>
<script>

function addFeature(){
	var polygon={
	type: "polygon", // autocasts as new Polygon()
        rings: [
            [465373.67283938953, 4574685.605095486],
			[465448.7368793035, 4574662.143328166],
			[465442.06908027834, 4574640.809887505],
			[465367.0048759384, 4574664.271654826],
			[465373.67283938953, 4574685.605095486]
        ]
	};
	
	var url="http://localhost:6080/arcgis/rest/services/BP/BP/FeatureServer/0";
	
	applyEdits(polygon,url);
}
function applyEdits(polygon,url){
	 require(['esri/layers/FeatureLayer',
		 "esri/geometry/Point",
		 "esri/geometry/Polygon",
            "esri/geometry/SpatialReference",
			'esri/Graphic']
			, function(FeatureLayer,Point,Polygon,SpatialReference,Graphic){
		 var _layer = new FeatureLayer(url,{
			mode: FeatureLayer.MODE_ONDEMAND,
			outFields: ["*"]
          });
		  //102100
		  polygon.spatialReference = new SpatialReference({ wkid: 102100 });
		  var graphics = new Graphic({geometry: polygon});
		 const addFeature = {
				 addFeatures: [graphics]
		 };
		 _layer.applyEdits(addFeature).then(function(editsResult) {
			    if (editsResult.addFeatureResults.length > 0) {
			      const objectId = editsResult.addFeatureResults[0].objectId;
			    }
			    
			  }).catch(function(error) {
			    console.error("[ applyEdits ] FAILURE: ", error.code, error.name,
			      error.message);
			    console.log("error = ", error);
			  });

	 })
}
</script>
</head>
<body>
<a href="#" onclick="addFeature()">添加图元</a>
</body>
</html>

arcgis java中请求,注意设置 request contenttype为application/x-www-form-urlencoded

String params = "f=json&adds=[{\"geometry\":{\"spatialReference\":{\"wkid\":"+wkid+"},\"rings\":["+ gson.toJson(ring) + "]},\"attributes\":null}]";
				
String rep = HttpUtils.post(url, params, "application/x-www-form-urlencoded");


最后效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值