Applying Transforms to MapShapes

3 posts, 0 answers
  1. Simon
    Simon avatar
    35 posts
    Member since:
    Oct 2010

    Posted 17 Dec 2010 Link to this post

    I am trying to implement a selection mechanism to select a series of MapShapes from a particular layer.  The stategy that I use is to create a MapPath and set the Data item to be a MapGeometryGroup.

    For each shape that is selected (and these are either MapPaths or MapPolygons), I create a MapGeometry from it, and then add that geometry to the group.

    Works perfectly!

    However, I now need to shrink each of the geometries by 10%, and align them in the center of the original shapes.  So for each of the MapGeometries I have added a Transform

    LocationRect locationRect = mapShape.GeographicalBounds;
    locationRect.MapControl = MapControl;
    TransformGroup transformGroup = new TransformGroup();
    transformGroup.Children.Add(new TranslateTransform(-locationRect.Northwest.Latitude, locationRect.Northwest.Longitude));
    transformGroup.Children.Add(new ScaleTransform(0.9, 0.9));
    transformGroup.Children.Add(new TranslateTransform(locationRect.Center.Longitude, mapShape.GeographicalBounds.Center.Latitude));
    mapGeometry.Transform = transformGroup;

    I have two problems;

    1. The translate doesn't take me to the correct origin to apply the ScaleTransform so that I don't move my X, Y coordinates in the scale
    2. If I add two shapes to the Group, then the transform seems to be applied to both MapGeometries in the Group, rather than applying just to itself.

    Any help would be appreciated

  2. Simon
    Simon avatar
    35 posts
    Member since:
    Oct 2010

    Posted 17 Dec 2010 Link to this post

    In the end I found a post saying that it is not advisable to use transforms on MapShapes.  So I converted the shapes to native Geometry, nudged them, and converted back.  This works well

    public static Geometry Scale(Geometry geometry, double scale)
        if (scale == 1.0)
            return geometry;
        const double nudgeFactor = 0.001;
        TranslateTransform leftTransform = new TranslateTransform(geometry.Bounds.Width * nudgeFactor, 0.0);
        Geometry leftGeometry = Geometry.Combine(Geometry.Empty, geometry, GeometryCombineMode.Union, leftTransform);
        TranslateTransform rightTransform = new TranslateTransform(-geometry.Bounds.Width * nudgeFactor, 0.0);
        Geometry rightGeometry = Geometry.Combine(Geometry.Empty, geometry, GeometryCombineMode.Union, rightTransform);
        Geometry widthShrunkenGeometry = Geometry.Combine(geometry, leftGeometry, GeometryCombineMode.Intersect, null);
        widthShrunkenGeometry = Geometry.Combine(widthShrunkenGeometry, rightGeometry, GeometryCombineMode.Intersect, null);
        TranslateTransform upTransform = new TranslateTransform(0.0, geometry.Bounds.Height * nudgeFactor);
        Geometry upGeometry = Geometry.Combine(Geometry.Empty, geometry, GeometryCombineMode.Union, upTransform);
        TranslateTransform downTransform = new TranslateTransform(0.0, -geometry.Bounds.Height * nudgeFactor);
        Geometry downGeometry = Geometry.Combine(Geometry.Empty, geometry, GeometryCombineMode.Union, downTransform);
        Geometry heightShrunkenGeometry = Geometry.Combine(geometry, upGeometry, GeometryCombineMode.Intersect, null);
        heightShrunkenGeometry = Geometry.Combine(heightShrunkenGeometry, downGeometry, GeometryCombineMode.Intersect, null);
        return Geometry.Combine(widthShrunkenGeometry, heightShrunkenGeometry, GeometryCombineMode.Intersect, null); 

  3. Andrey
    Andrey avatar
    1681 posts

    Posted 22 Dec 2010 Link to this post

    Hi Simon,

    Thank your for the information. We are planning to implement support transformations for the map shape objects in the future releases of our RadMap control. You can check availability of this feature using our PITS:

    Best wishes,
    Andrey Murzov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
Back to Top