问题描述
我打算使用 FeatureLayer 和 java API 在 arcgis 地图上插入点。
使用arcgis rest api,我可以添加一个新点,参见>>>> arcgis rest api ...
但是当我使用 java API 在特征层中添加新点时,该函数永远不会被调用,featureTable.addDoneLoadingListener
谁能告诉我是否可以这样做?
enter code here
public class AddPoints {
private ServiceFeatureTable featureTable;
private final String SERVICE_LAYER_URL = "https://services.../FeatureServer/0";
CountDownLatch latch = new CountDownLatch(1);
public void init() {
String yourAPIKey = "... yourAPIKey ...";
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
// create a map with the streets basemap style
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_STREETS);
featureTable = new ServiceFeatureTable(SERVICE_LAYER_URL);
FeatureLayer featureLayer = new FeatureLayer(featureTable);
map.getoperationalLayers().add(featureLayer);
featureTable.addDoneLoadingListener(() -> addPoints(featureTable));
}
private void addPoints(ServiceFeatureTable featureTable) {
Map<String,Object> attributes = new HashMap<>();
attributes.put("EntityType","test");
attributes.put("Name","test");
attributes.put("Address","test");
attributes.put("City","test");
attributes.put("ZIP","xxx");
double x = -10.318673997173935;
double y = 39.68805765789006;
Point pt = new Point(x,y,SpatialReference.create(4326));
// creates a new feature using default attributes and point
Feature feature = featureTable.createFeature(attributes,pt);
// check if feature can be added to feature table
if (featureTable.canAdd()) {
// add the new feature to the feature table and to server
featureTable.addFeatureAsync(feature).addDoneListener(() -> applyEdits(featureTable));
} else {
// displayMessage(null,"Cannot add a feature to this feature table");
}
// addFeaturePoint(featureTable);
latch.countDown();
}
public void launcheme() {
try {
init();
latch.await();
} catch (InterruptedException e) {
e.printstacktrace();
}
}
//addpoint with the api arcgis rest
const featureServiceLayerUrl ="https://***"
const featuretoAdd = {
attributes: {
EntityType: 'test',Name: 'test',Address: 'test',City: 'test',ZIP: '-'
},geometry: {
x: -10.339787163524841,y: 40.683707245441305,spatialReference: {
wkid: 4326
}
}
};
arcgisRest.addFeatures({
url: featureServiceLayerUrl,features: [featuretoAdd],authentication
})
.then(handleAdded);
function handleAdded(response) {
console.log(response);
document.getElementById("result-add").textContent = JSON.stringify(response,null,2);
if (!response.addResults[0].success) {
// stop early if adding a new feature was not successful
return;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)