How to remove a particular pygone in BingMaps ? RRS feed

  • Question

  • Dear all,

    I am using in a bing map application the WPF control to interact with the map. I am actually dynamically draw circles on the map based on the area I am interrested in.

    For that I am using the following code snipet :

    public static LocationCollection DrawCircle(Location Loc, double dRadius,ShareTypes.BingMap.BingMapDistanceUnit Unit)
                var locCollection = new LocationCollection();
                var EarthRadius = GeoCodeCalc.EarthRadiusInMiles;
                if (Unit == ShareTypes.BingMap.BingMapDistanceUnit.Kilometers)
                    EarthRadius = GeoCodeCalc.EarthRadiusInKilometers;
                //Convert location to radians based on
                var latitude     =  GeoCodeCalc.ToRadian(Loc.Latitude);
                var longitude   =   GeoCodeCalc.ToRadian(Loc.Longitude);
                //Angular distance covered on earth surface
                var d = dRadius / EarthRadius;
                for (int x = 0; x < 360; x++)
                    var angle = GeoCodeCalc.ToRadian(x); //radians
                    var latRadians = Math.Asin(Math.Sin(latitude) * Math.Cos(d) + Math.Cos(latitude) * Math.Sin(d) * Math.Cos(angle));
                    var lngRadians = longitude + Math.Atan2(Math.Sin(angle) * Math.Sin(d) * Math.Cos(latitude), Math.Cos(d) - Math.Sin(latitude) * Math.Sin(latRadians)); 
                    //Get location of the point
                    var pt = new Location(180.0 * latRadians / Math.PI, 180.0 * lngRadians / Math.PI);
                    //Add the new calculatied poitn to the collection
                return locCollection;

    My circle collection gets dranw and render as follow :

    As you can see I can display successive circle on the map.

    Now is there a way to access a particular circle in the collection and remove it ?

    Thanks for help



    Tuesday, January 8, 2013 5:16 PM


  • The main way to do this is to have a reference to the circle you want to remove and pass it to the remove method of the layer. If removing based on a mouse event on the circle you will be able to get a reference from the circle in the event. If you want to be able to remove a circle based on an ID or some other feature you can store this data in the tag property of the circle and then loop through all shapes in the layer looking for the circle with that property and then passing that circle to the remove method.


    Monday, January 14, 2013 4:59 PM