【发布时间】:2020-06-27 14:21:36
【问题描述】:
我正在使用展开地图创建标记。当用户将鼠标悬停在标记上时,会显示标题。但其他标记与标题重叠,因此它隐藏了标题中显示的信息。为了防止这种情况,我使用 PGraphics 将标题绘制为:
public void showTitle(PGraphics pg, float x, float y)
{
String name = getCity() + " " + getCountry() + " ";
String pop = "Pop: " + getPopulation() + " Million";
/
/buffer is defined already.
buffer.beginDraw();
buffer.fill(255, 255, 255);
buffer.textSize(12);
buffer.rectMode(PConstants.CORNER);
buffer.rect(x, y-TRI_SIZE-39, Math.max(pg.textWidth(name), pg.textWidth(pop)) + 6, 39);
buffer.fill(0, 0, 0);
buffer.textAlign(PConstants.LEFT, PConstants.TOP);
buffer.text(name, x+3, y-TRI_SIZE-33);
buffer.text(pop, x+3, y - TRI_SIZE -18);
buffer.endDraw();
}
然后通过方法在屏幕上绘制缓冲区
public void draw() {
map.draw();
image(buffer, 0,0);
}
它解决了这个问题,现在标题没有与标记重叠,但它没有在标记的正下方绘制,而是在屏幕上随机绘制,如图所示 我该如何避免呢?请帮忙。
【问题讨论】:
-
请提供minimal reproducible example。您可以使用简化的硬编码示例而不是整个草图。
标签: java maps processing