简体   繁体   English

在Java中从边缘和顶点绘制地图

[英]Drawing a map from edges and vertices in Java

Given a large amount of vertices and edges. 给定大量的顶点和边缘。 The vertices are given x and y coordinates and every edge will have two vertices. 顶点被赋予x和y坐标,并且每个边都有两个顶点。

For zooming, the easy solution is to just draw all the edges that have a vertex in the given x and y coordinate, that the screen is zoomed in on, instead of drawing every single edge on the map. 对于缩放,简单的解决方案是仅绘制在给定的x和y坐标中具有顶点的所有边缘,然后放大屏幕,而不是在地图上绘制每个边缘。 But how will I draw the edges that just run through the area that I am zoomed in on? 但是,如何绘制刚穿过放大区域的边缘?

The only solution I can come up with is to linearly go through every edge and calculate whether the edge will enter the area I am zoomed in on, by finding the x and y coordinate for each end of the edge. 我能想到的唯一解决方案是,通过找到边缘的每个末端的x和y坐标,线性遍历每个边缘并计算该边缘是否会进入我放大的区域。 Does anyone have a sneaky solution to this? 有人对此有偷偷摸摸的解决方案吗?

Also, regarding panning, would the best solution not be to load 8 boxes around the area, that the user sees, with the same size? 此外,关于平移,最好的解决方案不是在用户看到的区域周围以相同的大小加载8个盒子吗?

EDIT: I forgot to say, the different edges have information in them, so according to each zoom level, different types of edges will be drawn, which is why I prefer to make my own zoom. 编辑:我忘了说,不同的边缘中都有信息,因此根据每个缩放级别,将绘制不同类型的边缘,这就是为什么我更喜欢进行自己的缩放。

So you want to do it with Java but you didn't tell what graphics library you want to use. 因此,您想使用Java来做到这一点,但没有告诉您要使用的图形库。 When drawing is getting more complicated and intensive like in your example you should use something more sophisticated like OpenGL instead of thinking of calculating a zoom by yourself. 当绘图变得更加复杂和密集时(例如在您的示例中),您应该使用诸如OpenGL之类的更复杂的工具,而不是自己考虑计算缩放比例。 To use it with Java, there is a wrapper library: JOGL . 要将其与Java一起使用,有一个包装器库: JOGL

OpenGL provides the tools to draw vertices and shapes and you use a camera to organize the view and zoom. OpenGL提供了绘制顶点和形状的工具,您可以使用相机来组织视图和缩放。

So first I suggest to get familiar with graphics programming (and it doesn't really matter in which programming language or with which library). 因此,首先我建议您熟悉图形编程(实际上,使用哪种编程语言或使用哪种库都没有关系)。

I found these tutorials helpful: 我发现这些教程很有帮助:

Update 更新

  • OpenGL is perfectly suitable for drawing 2D (as you will learn in the tutorials). OpenGL非常适合绘制2D(您将在本教程中学习)。
  • Especially if your things to draw change according to zoom level a graphics library is useful because the whole scene will be rendered at least every time the content changes. 特别是如果您要绘制的内容根据缩放级别而变化,则图形库很有用,因为至少每次内容更改时都会渲染整个场景。 You can simply check the zoom level before rendering and draw things according to it. 您可以在渲染之前简单地检查缩放级别并根据它绘制事物。

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

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