简体   繁体   中英

Drawing a map fast with thousands of lines in WPF

I'm making a route planner program in WPF and I need to display a map that is a graph object with tens of thousands of edges. What would be the best option for drawing these lines if I also want to interact with this map (like zooming, moving, selecting edges)? All the options I tried turned out to hova really slow rendering performance.

You can use the Shape , interact with these object is particularly simple, but if you are dealing with thousands of edges I suggest to use the DrawingVisual class, a visual object that can be used to render vector graphics on the screen, and its RenderOpen method. I had a similar problem to yours and I have improved the performance of my application using DrawingContext to draw my edges.

To zoom you have to work with transformations, in particular ScaleTrasnform and apply the transformation to your panel or to your shapes.

DrawingVisual does not provide event handlig, so if with Shape you can use events to interact with edges, with DrawingVisual you need to implement Hit-Testing .

To improve drawing performance you have to avoid rendering all lines at once. You could not improve your performance even using lower level visuals.

You have to follow these things:

  1. If you have those lines in one layer then split that layer in different layers.You can split them on the base of lines related to Motorways, Highways, Local roads, Streets etc.
  2. You have to find mechanism to spatially index those layers. By using spatial indexing you can index your lines according to their bounding box.
  3. Get lines on the base of bounding box and only render those lines which lie in that bounding box
  4. Render important lines (Motorways, Highways) on higher zoom level and then gradually show other lines(Low importance roads,streets) on zooming in the map.

If you have to use WPF, then take a look at the DrawingVisual class. This gives access to low-level drawing primitives which will give faster performance. However, as you are dealing with lower level objects, you'll have to deal with things like focus and hit-testing yourself. Take a look here for msdn entries on DrawingVisuals:

http://msdn.microsoft.com/en-us/library/system.windows.media.drawingvisual.aspx http://msdn.microsoft.com/en-us/library/ms742254.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM