我正在尝试实现某种弹出窗口来显示给定国家/地区作者的信息,我设法做到了这一点。我加载了我的交互式地图,当我左键单击国家时,我确实收到了一条弹出消息。但是,一旦我释放按钮,弹出窗口就会消失。
我想弹出一个被吸引到那里的弹出窗口,直到我右键单击它应该消失。
所以我在实现它时遇到问题,以便在 mouseReleased() 方法中显示的弹出窗口保持绘制状态。
// Import libaries
import org.gicentre.geomap.io.*;
import org.gicentre.geomap.*;
// Instance new GeoMap
GeoMap geoMap;
PImage bgImage;
void setup()
{
size(1280, 768);
// Load background pattern img and implement AA for shapes
bgImage = loadImage("bg.jpg");
smooth();
// New GeoMap instance
geoMap = new GeoMap(this);
// Load map shape
geoMap.readFile("world");
}
void draw()
{
// Fill ocean with bg image
background(bgImage);
// Change stroke color
stroke(255, 255, 255);
// Fill the continents color and draw the map
fill(26, 117, 181);
geoMap.draw();
// Get country id by mouse location
int countryID = geoMap.getID(mouseX, mouseY);
// Offgrid: -1
if (countryID != -1)
{
// Listen for mouse event and trigger action
mouseReleased(countryID);
// Color the select country
fill(14, 96, 166);
geoMap.draw(countryID);
}
}
void mouseReleased(int countryID)
{
// Act on left clicks
if(mouseButton == LEFT)
{
println(getCountryName(countryID, 3));
noStroke();
fill(255, 192);
rect(0, 0, width, 20);
if (countryID != -1)
{
String name = getCountryName(countryID, 3);
fill(0);
textAlign(LEFT, CENTER);
text(name, 0, 0, width, 20);
}
}
}
// Returns country name by id
String getCountryName(int id, int offset)
{
// Get country name for query
// getString(int id, int offset), int id: country id, int offset:
// Example USA
// offset 0 = Country Code -> 257
// offset 1 = Country Short Tag -> US
// offset 2 = Country Short Name -> USA
// offset 3 = Official Name -> United States
String name = geoMap.getAttributes().getString(id, offset);
return name;
}