Drawing Shapes in Information Layer

1. Joshua Ault
7 posts
Member since:
Mar 2010

Posted 06 May 2010 Link to this post

Hello:

I am drawing a MapEllipse in an information layer. The Ellipse will appear at different locations based on where the user clicks. The problem I am having is the MapEllipse positions itself based on its top left corner. I need to position based on its center. How can I do this? Are there any examples for this kind of scenario?

I set up one location to work with the centering, but when you click on another location the ellipse was not set to the center anymore. The ellipse needs to be able to center on different locations and it will be a different size ellipse at different zoom levels.

Any thoughts or suggestions would be great.

Thank You.
2. Andrey
1681 posts

Posted 10 May 2010 Link to this post

Hi Joshua Ault,

The size of the MapEllipse is given in the kilomiters or miles depends on the DistanceUnit set for the RadMap control. You can convert metric size to the degree size using GetLatitudeLongitudeSize method of the RadMap control. Then you should set ellipse location so it will be shifted to the half of the degree size. As result you will have ellipse with center at the specified location. For example, following code add ellipse with center at the point of the mouse click:

`private` `void` `RadMapMapMouseClick(``object` `sender, MapMouseRoutedEventArgs eventArgs) `
`{ `
`    ``double` `ellipseWidth = 3; ``// 3 kilomiters `
`    ``double` `ellipseHeight = 3; ``// 3 kilomiters `
` `
`    ``// Calculate ellipse size in degrees (latitude-longitude). `
`    ``Size degreeSize = ``this``.radMap.GetLatitudeLongitudeSize(eventArgs.Location, ellipseWidth, ellipseHeight); `
` `
`    ``// Calculate new ellipse location.  `
`    ``// Shift from click-point on half of the ellipse size in degrees. `
`    ``Location ellipseLocation = ``new` `Location( `
`        ``eventArgs.Location.Latitude + degreeSize.Height / 2, `
`        ``eventArgs.Location.Longitude - degreeSize.Width / 2); `
` `
`    ``MapEllipse ellipse = ``new` `MapEllipse() `
`    ``{ `
`        ``Location = ellipseLocation, `
`        ``Width = ellipseWidth, `
`        ``Height = ellipseHeight, `
`        ``Fill = ``new` `SolidColorBrush(Color.FromArgb(128,0,255,0)) `
`    ``}; `
` `
`    ``this``.informationLayer.Items.Add(ellipse); `
`}`

Sincerely yours,
Andrey Murzov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
3. Joshua Ault
7 posts
Member since:
Mar 2010

Posted 11 May 2010 Link to this post

Hello:

I have implemented the new code that you supplied. It was a huge improvement and worked 50% better than what I had. However, as I begin to zoom out from the map the shape begins to be off center. This starts around zoom level 10 and on. Do you know what could be causing this? When I am zoomed into the map the shape stays centered.

Thank You.
4. Andrey
1681 posts

Posted 12 May 2010 Link to this post

Hi Joshua Ault,

I'm sorry, I can't reproduce it using the map providers which are shipped with RadMap control (Bing and Open Street). When I put the ellipse with center at the specific point (center of the city, for example) and zoom-in/out it stay over this point regardless of the zoom level (from 1 to 19). The center of the ellipse isn't shifted. Could you, please, clarify what map provider do you use and how can we reproduce the behavior?

Best wishes,
Andrey Murzov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.