Select to view content in your preferred language

Area and Lengths

1081
3
10-02-2012 06:27 AM
jonataspovoas
Regular Contributor
Hi,

I'm building a measure tool and I have two maps in different Coordinate projections.

I'm using a geometry service to calculate the lengths and areas of geometries that the user draw on the map, and when I use the LengthsAsync mehtod everything works fine for both maps. But when I try to use the AreasAndLengthsAsync method, both the area and lengh comes wrong for both maps.

// code to call the AreasAndLengthsAsync Method
GeometryService geometryService = new GeometryService(geometryService.URL);
geometryService.AreasAndLengthsCompleted += this.MeasureFinished;
if (MapSpatialReference == "4326")
{
    geometryService.AreasAndLengthsAsync(new List<Graphic>() { draw }, LinearUnit.Meter, LinearUnit.Meter, CalculationType.Geodesic, draw);
    System.Windows.MessageBox.Show(this.objetoDedraw.Map.SpatialReference.WKID.ToString());
}
else if (MapSpatialReference == "29194")
{
    geometryService.AreasAndLengthsAsync(new List<Graphic>() { draw }, draw);
}

// Code that adds the draw and area text at the map
public void MedicaoTerminada(object sender, AreasAndLengthsEventArgs e)
{
    Graphic draw = e.UserState as Graphic;

    string area;
    if (MapSpatialReference == "4326")
    {
        area = string.Format("{0} km²", Math.Round(e.Results.Areas.First(), 0));
    }
    else if (MapSpatialReference == "29194")
    {
        area = string.Format("{0} m²", Math.Round(e.Results.Areas.First(), 0));
    }

    Graphic areaDraw = new Graphic();
    areaDraw.Geometry = draw.Geometry.Extent.GetCenter();
    areaDraw.Symbol = new TextSymbol() { Text = area.ToString(), Foreground = new SolidColorBrush(Colors.Blue) };

    (this.objetoDeDesenho.Map.Layers["MeasureGraphicLayer"] as GraphicsLayer).ClearGraphics();
    (this.objetoDeDesenho.Map.Layers["MeasureGraphicLayer"] as GraphicsLayer).Graphics.Add(draw);
    (this.objetoDeDesenho.Map.Layers["MeasureGraphicLayer"] as GraphicsLayer).Graphics.Add(areaDraw);
}
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
0 Kudos
jonataspovoas
Regular Contributor
Hi,

I've just read it, tryed everything the posts sugests, with no sucess...
0 Kudos
jonataspovoas
Regular Contributor
Hi,

I have done the coding of my application again, but I'm still with the problem.

Here's my new code:
private Map myMap;
private GeometryService geometryService;

public MeasureArea(Map myMap)
{
    this.myMap = myMap;
    this.geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/");
    this.geometryService.AreasAndLengthsCompleted += MeasureFinished;
}
        
public void Measuredraw(Graphic draw)
{
    geometryService.AreasAndLengthsAsync(new List<Graphic>() { draw },
                                                new List<Graphic>() { draw });
}
        
private void MeasureFinished(object sender, AreasAndLengthsEventArgs e)
{
    Graphic draw = (e.UserState as List<Graphic>).First();

    string area = string.Format("{0} km²", e.Results.Areas.First());

    Graphic drawMeasureTextSymbol = new Graphic();
    drawMeasureTextSymbol.Geometry = draw.Geometry.Extent.GetCenter();
    drawMeasureTextSymbol.Symbol = new TextSymbol() 
    { 
        Text = area.ToString(), 
        FontSize = 16, 
        Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue) 
    };

    (this.myMap.Layers["MedirGraphicLayer"] as GraphicsLayer).ClearGraphics();
    (this.myMap.Layers["MedirGraphicLayer"] as GraphicsLayer).Graphics.Add(draw);
    (this.myMap.Layers["MedirGraphicLayer"] as GraphicsLayer).Graphics.Add(drawMeasureTextSymbol);
}


And this is the result:
[ATTACH=CONFIG]18229[/ATTACH]

If I change the method parameters to the code below, the value returned is the same.
geometryService.AreasAndLengthsAsync(new List<Graphic>() { draw }, LinearUnit.Meter, LinearUnit.Meter, new List<Graphic>() { draw });
0 Kudos