Page 1 of 1

Sector over maps

Posted: Thu Apr 25, 2013 4:31 pm
by SupportArchives
How to show a sector over a Maps?

Re: Sector over maps

Posted: Thu Apr 25, 2013 4:38 pm
by ArctionPasi
Use PolygonSeries and calculate the edge points.

The following method adds a red PolygonSeries in ViewXY, and calculates the edge points by using Sin and Cos.

Code: Select all

 
       void CreateSector(double centerLongitude,
            double centerLatitude, 
            double radius,
            double startAngle, 
            double sectorAngle, 
            int edgePointCount)
        {
            PolygonSeries polygon = new PolygonSeries(m_chart.ViewXY, m_chart.ViewXY.XAxes[0], m_chart.ViewXY.YAxes[0]);
            polygon.Fill.GradientFill = GradientFill.Solid;
            polygon.Fill.Color = Color.FromArgb(200, Color.Red); 

            m_chart.ViewXY.PolygonSeries.Add(polygon); 


            int iPointCount = edgePointCount +1; //1 is for center
            PointDouble2D[] aPoints = new PointDouble2D[iPointCount]; 

            aPoints[0] = new PointDouble2D(centerLongitude, centerLatitude);
            for (int i = 0; i < edgePointCount; i++)
            {
                double dAngle = startAngle + (double)i * sectorAngle / (double)(edgePointCount-1); 
                double dAngleRad = dAngle / 180.0 * Math.PI;
                aPoints[1 + i].X = radius * Math.Cos(dAngleRad) + centerLongitude;
                aPoints[1 + i].Y = radius * Math.Sin(dAngleRad) + centerLatitude;
  
            }

            polygon.Points = aPoints;


        } 
Then calling it

Code: Select all

CreateSector(20, 40, 50, -180, 135, 20);


produces a sector like this:
SectorOverMap.PNG
SectorOverMap.PNG (410.79 KiB) Viewed 9261 times