简体   繁体   English

在WPF中用数千行快速绘制地图

[英]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. 我正在WPF中制作路线规划程序,我需要显示一个地图,它是一个有数万条边的图形对象。 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. 我试过的所有选项都变成了hova,但渲染性能却很慢。

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. 你可以使用Shape ,与这些对象交互特别简单,但如果你处理成千上万的边缘,我建议使用DrawingVisual类,一个可用于在屏幕上渲染矢量图形的可视对象,以及它的RenderOpen方法。 I had a similar problem to yours and I have improved the performance of my application using DrawingContext to draw my edges. 我遇到了类似的问题 ,我使用DrawingContext绘制了边缘,提高了应用程序的性能。

To zoom you have to work with transformations, in particular ScaleTrasnform and apply the transformation to your panel or to your shapes. 要进行缩放,您必须使用转换,特别是ScaleTrasnform ,并将转换应用于面板或形状。

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 . DrawingVisual不提供事件handlig,因此如果使用Shape,您可以使用事件与边缘交互,使用DrawingVisual,您需要实现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. 如果必须使用WPF,请查看DrawingVisual类。 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: 在这里查看DrawingVisuals上的msdn条目:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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