This is a migrated thread and some comments may be shown as answers.

Applying Transforms to MapShapes

2 Answers 107 Views
Map
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 17 Dec 2010, 11:59 AM
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

Thanks
Simon

2 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 17 Dec 2010, 03:02 PM
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); 
}

0
Andrey
Telerik team
answered on 22 Dec 2010, 01:11 PM
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:

http://www.telerik.com/support/pits.aspx#/public/wpf/4404

Best wishes,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
Map
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or