AnsweredAssumed Answered

Retrieve the event of clicking on a MapView

Question asked by ManelKeddar on Aug 2, 2017
Latest reply on Aug 11, 2017 by ManelKeddar

i'm trying to make an application for adding a new feature .SO the user click on the map  to specify a new feature's location. i do this by listening to a click event on mymap view, which in turn will call a function for adding a new feature .but this doesn't work i think the problem is how i provide the listening event here's my code:

 

public MainWindow()
{
InitializeComponent();
MyMapView.Map = new Map();
MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
}

private void MyMapView_GeoViewTapped(object sender , Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
{
var mapClickPoint = e.Location;
//Appel de la fonction qui fait l'ajout d'un nouveau feature
addNewFeature(mapClickPoint);
}

private async void addNewFeature(MapPoint locationPoint)
{
var featureTableUri = new System.Uri("https://frpargeosidport.corp.capgemini.com/arcgis/rest/services/POCSynopsis/FeatureServer/0");
var table = new ServiceFeatureTable(featureTableUri);

await table.LoadAsync();
var builder = new PolygonBuilder(SpatialReference.Create(2154));

var pointPoly = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReference.Create(2154));
pointPoly.Add(locationPoint.X, locationPoint.Y);
pointPoly.Add(1500, 1400);
pointPoly.Add(1300, 1200);
pointPoly.Add(1300, 1200);
pointPoly.Add(locationPoint.X, locationPoint.Y);
var poly = new Esri.ArcGISRuntime.Geometry.Polygon(pointPoly);
var description = "description";
var attributes = new Dictionary<string, object>();
attributes.Add("SHAPE", poly);
if (table.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded)
{


var template = table.FeatureTemplates.FirstOrDefault() ?? table.FeatureTypes.FirstOrDefault(t => t.Templates.Any())?.Templates?.FirstOrDefault();
var feature = table.CreateFeature(template,poly);
await table.AddFeatureAsync(feature);

}
//await table.DeleteFeatureAsync(selectedFeatures);
// push this update (apply edits) to the feature service
IReadOnlyList<EditResult> editResults = await table.ApplyEditsAsync();
// check the results for errors
foreach (var r in editResults)
{
if (r.CompletedWithErrors)
{
Console.WriteLine("Edit to Object '" + r.ObjectId + "' failed: " + r.Error.Message);
}
}

var layer = new FeatureLayer(table);
MyMapView.Map.OperationalLayers.Add(layer);


}

 

This doesn't show me any result any one can help me please !

Thanks

Outcomes