Answered by:
Displaying PathGeometry into canvas take too long time

Question
-
Hi every one,
I am working on spatial data with an application WPF and I would like to draw a map from data queries.
I got my data and I am able to draw them on a canvas with scroll bar and zoom.
My problem is when I want to zoom or scroll the canvas take a long time before draw the map.
The big problem is there :
Dim poly As New Polygon poly.Stroke = Brushes.Red poly.Fill = Brushes.Orange poly.StrokeThickness = 5 Dim colPoint As New PointCollection For i = 1 To geo.STNumPoints Dim ls As New LineSegment() colPoint.Add(New Point(geo.STPointN(i).STX.Value - extentA, geo.STPointN(i).STY.Value - extentB)) Next colPoint.Add(New Point(geo.STPointN(1).STX.Value - extentA, geo.STPointN(1).STY.Value - extentB)) poly.Points = colPoint masterCanvas.Children.Add(poly)
so the canvas is "masterCanvas" and i add each Polygon one by one. I would like if it is possible to gather all polygon into one "image" and then when it will refresh the canvas it will draw only one thing.
Regards.
- Moved by Carl Cai Monday, April 21, 2014 5:34 AM has posted with http://social.msdn.microsoft.com/Forums/vstudio/en-US/e2d50b4e-0d76-4a3c-b229-521b648b54b3/displaying-pathgeometry-into-canvas-take-too-long-time?forum=wpf#e2d50b4e-0d76-4a3c-b229-521b648b54b3
Friday, April 18, 2014 2:43 PM
Answers
-
I am working on spatial data with an application WPF and I would like to draw a map from data queries.
I got my data and I am able to draw them on a canvas with scroll bar and zoom.
My problem is when I want to zoom or scroll the canvas take a long time before draw the map.
Drawing to a canvas using WPF has very high overheads, but there are specific procedures you can apply to reduce this. Information about these procedures would be available from people who are familiar with WPF, and if you ask your question at the correc tplace you will have a better chance of answers. See: Windows Presentation Foundation (WPF)
Friday, April 18, 2014 9:38 PM
All replies
-
How many points are there?
Do the values in geo.STPointN(i).STX.Value - extentA change? Which ones and why?
Although I have not tested it I think you will gain some speed by using a simple array and adding points to it yourself ie
colPoint.x = geo.STPointN(i).STX.Value - extentA
However unless you have thousands of points I dont see where speed of this code would be an issue? Maybe I am missing something?
It seems there may be something else causing the delay? How do you zoom in? How to the coordinates get changed from one zoomed view to the next?
Have you thought about using ScaleTransform rather than reloading/calcing your point data each time?
Maybe show more of your drawing code.
Friday, April 18, 2014 3:02 PM -
Hi,
ExtentA and Extenb are value to reduce the disance from the origine (corner top left). Because a point for a polygon is like (18118500 3877472) so I use that values to reduce and be able to display it into a container.
Then this is another code that I use to draw my linestring:
Dim lsfig As New PathFigure() 'EXTENT 18118500 3877472 lsfig.StartPoint = New Point(geo.STPointN(1).STX.Value - extentA, geo.STPointN(1).STY.Value - extentB) For i = 1 To geo.STNumPoints Dim ls As New LineSegment() ls.Point = New Point(geo.STPointN(i).STX.Value - extentA, geo.STPointN(i).STY.Value - extentB) lsfig.Segments.Add(ls) Next result.Figures.Add(lsfig)
When I test separately to display linestring and polygon there is clearly a difference. LineString is like instantaneously and polygon very not.
Friday, April 18, 2014 8:56 PM -
I am working on spatial data with an application WPF and I would like to draw a map from data queries.
I got my data and I am able to draw them on a canvas with scroll bar and zoom.
My problem is when I want to zoom or scroll the canvas take a long time before draw the map.
Drawing to a canvas using WPF has very high overheads, but there are specific procedures you can apply to reduce this. Information about these procedures would be available from people who are familiar with WPF, and if you ask your question at the correc tplace you will have a better chance of answers. See: Windows Presentation Foundation (WPF)
Friday, April 18, 2014 9:38 PM -
Thanks for your helps :)Saturday, April 19, 2014 9:53 AM
-
Hi,
I found that you have posted it in the forum Acamar suggested.
Please just focus on that thread, and you could mark if any reply which is helpful as answer.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Monday, April 21, 2014 5:37 AM