New to Telerik UI for WinForms? Download free 30-day trial

Bounds ElevationType

ElevationType.Bounds ElevationRequest gets elevations at equally-spaced locations within an area on the Earth defined as a bounding box.

Figure 1: Bounds ElevationRequest

WinForms RadMap Bounds ElevationRequest

Bounds ElevationType request

ElevationRequest boundsRequest = new ElevationRequest();

public void SetupElevationRequest()
{
    //add pins to the map 
    Telerik.WinControls.UI.Map.PointG point1 = new Telerik.WinControls.UI.Map.PointG(36.114647, -115.172813);
    Telerik.WinControls.UI.Map.PointG point2 = new Telerik.WinControls.UI.Map.PointG(34.05223, -118.24368);
    Telerik.WinControls.UI.Map.PointG point3 = new Telerik.WinControls.UI.Map.PointG(37.77493, -122.41942);
    MapPin pin1 = new MapPin(point1);
    MapPin pin2 = new MapPin(point2);
    MapPin pin3 = new MapPin(point3);

    MapLayer pinsLayer = new MapLayer("Pins");
    this.radMap1.Layers.Add(pinsLayer);

    MapLayer calloutsLayer = new MapLayer("Callouts");
    this.radMap1.Layers.Add(calloutsLayer);
    this.radMap1.Layers["Pins"].Add(pin1);
    this.radMap1.Layers["Pins"].Add(pin2);
    this.radMap1.Layers["Pins"].Add(pin3);

    boundsRequest.ElevationType = ElevationType.Bounds;
    boundsRequest.Bounds = Telerik.WinControls.UI.Map.RectangleG.GetBoundingRectangle(new List<Telerik.WinControls.UI.Map.PointG>()
    {
        point1,
        point2,
        point3
    });
    boundsRequest.Rows = 2;
    boundsRequest.Columns = 3;

    BingRestMapProvider bingProvider = this.radMap1.Providers[0] as BingRestMapProvider;
    bingProvider.CalculateElevationCompleted += BingProviderBounds_CalculateBoundsElevationCompleted;
    bingProvider.CalculateElevationAsync(boundsRequest);
}

private void BingProviderBounds_CalculateBoundsElevationCompleted(object sender, ElevationCompletedEventArgs e)
{
    List<Telerik.WinControls.UI.Map.PointG> points = new List<Telerik.WinControls.UI.Map.PointG>();

    for (int i = 0; i < this.radMap1.Layers["Pins"].Overlays.Count; i++)
    {
        MapPin pin = this.radMap1.Layers["Pins"].Overlays[i] as MapPin;

        if (pin != null)
        {
            points.Add(pin.Location);
        }
    }
    this.radMap1.Layers["Pins"].Clear();

    Telerik.WinControls.UI.Map.RectangleG rect = Telerik.WinControls.UI.Map.RectangleG.GetBoundingRectangle(points);
    Telerik.WinControls.UI.Map.PointG[,] p = this.CalculateEquidistantPointsInRectangle(rect, this.radMap1.MapElement.ZoomLevel,
        boundsRequest.Rows, boundsRequest.Columns);

    int rows = p.GetLength(0);
    int flatIndex = 0;

    for (int i = p.GetLength(0) - 1; i >= 0; i--)
    {
        for (int j = 0; j < p.GetLength(1); j++)
        {
            MapPoint point = new MapPoint(p[i, j]);
            this.radMap1.Layers["Callouts"].Add(point);

            MapCallout callout = new MapCallout(point);
            callout.MaxWidth = 50;
            callout.Text = e.Elevations[0].Elevations[flatIndex++].ToString() + "m";
            this.radMap1.Layers["Callouts"].Add(callout);
        }
    }
}

private Telerik.WinControls.UI.Map.PointG[,] CalculateEquidistantPointsInRectangle(Telerik.WinControls.UI.Map.RectangleG rect, int zoomLevel, int rows, int columns)
{
    Telerik.WinControls.UI.Map.PointL topLeft = MapTileSystemHelper.LatLongToPixelXY(rect.North, rect.West, zoomLevel);
    Telerik.WinControls.UI.Map.PointL bottomRight = MapTileSystemHelper.LatLongToPixelXY(rect.South, rect.East, zoomLevel);
    Telerik.WinControls.UI.Map.RectangleL rectangle = new Telerik.WinControls.UI.Map.RectangleL(topLeft,
        new Telerik.WinControls.UI.Map.SizeL(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));

    Telerik.WinControls.UI.Map.PointG[,] result = new Telerik.WinControls.UI.Map.PointG[rows, columns];
    double xStep = (double)rectangle.Width / (columns - 1);
    double yStep = (double)rectangle.Height / (rows - 1);

    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            Telerik.WinControls.UI.Map.PointL point = new Telerik.WinControls.UI.Map.PointL((long)Math.Round(rectangle.X + j * xStep, MidpointRounding.AwayFromZero),
                (long)Math.Round(rectangle.Y + i * yStep, MidpointRounding.AwayFromZero));
            result[i, j] = MapTileSystemHelper.PixelXYToLatLong(point, zoomLevel);
        }
    }

    return result;
}