Select to view content in your preferred language

Rotate, Scale Geometry Programmatically

2328
1
Jump to solution
10-03-2018 12:27 PM
Labels (1)
ArnelLedo
Occasional Contributor

I need to implement a way to rotate/scale a polygon graphic on the MapView and SceneView. I couldn't fine a way using the API to apply these transformations to the geometries so I have tried different approaches, all of them involve modifying the vertices to calculate the position of each vertex after the transformation in order to obtain the new geometry.

My first implementation uses the WPF RotateTransform/ScaleTransform class to transform each individual point using a specific angle and the center of the polygon as the CenterX, CenterY of the transformations. The rotate method receives all the points in screen coordinates, so I have to convert the MapPoints using the LocationToScreen method and after getting the result I convert back to MapPoint using the ScreenToLocation(MapView) and ScreenToBaseSurface (SceneView).

On the second implementation I don't use the WPF Transform class, instead I use  trigonometry to get the position of each point after the rotation using the center of the polygon as anchor point.

Both approaches seems to rotate the polygon, however, it isn't working fine. The position of the polygon changes, the center should stay in the same place. The geometry gets deformed after a few rotations.

Any help will be highly appreciated.

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
ArnelLedo
Occasional Contributor

I got this working fine. The main issue was that I was applying the transformations to screen coordinates instead of transforming the real map point (LatLong). After that both approaches worked fine.

View solution in original post

0 Kudos
1 Reply
ArnelLedo
Occasional Contributor

I got this working fine. The main issue was that I was applying the transformations to screen coordinates instead of transforming the real map point (LatLong). After that both approaches worked fine.

0 Kudos