0

有人可以帮我在 Processing 上显示世界地图,然后在相应位置绘制推文吗?

4

1 回答 1

1

这不是一个完整的答案,但应该显示如何在世界地图上绘制位置。请注意执行笛卡尔坐标的 getPoint() 方法(您可以对 Processing 中的 map() 函数执行相同的操作。另请注意,构造函数会进行计算以将您使用的地球图像调整为草图窗口的大小......

WorldMap world;
Point[] cities = new Point[6];

void setup() {
  size(800, 480);
  background(255);
  stroke(0);
  strokeWeight(1.5);
  ellipseMode(CENTER);
  smooth();

  // World
  world = new WorldMap(0, 0, width, height);

  // Cities
  cities[0] = world.getPoint(45.24, -75.43);  // Ottawa
  cities[1] = world.getPoint(38.53, -77.02);  // Washington
  cities[2] = world.getPoint(51.32, 0.50);    // London
  cities[3] = world.getPoint(48.48, 2.20);    // Paris
  cities[4] = world.getPoint(39.55, 116.25);  // Beijing
  cities[5] = world.getPoint(35.40, 139.45);  // Tokyo

}

void draw() {

  world.drawBackground();

  for (int i = 0; i < cities.length; i++) {
    ellipse(cities[i].x, cities[i].y, 10, 10);
  }

}

//-------------------------------

class WorldMap {

  int x, y, w, h;
  PImage raster;

   WorldMap(int x, int y, int w, int h) {
     // Scale Image
     if (h >= w/2) {
       this.w = w;
       this.h = w/2;
       this.x = x;
       this.y = (h - this.h)/2;
     } 
     else {
       this.h = h;
       this.w = 2*h;
       this.x = (w - this.w)/2;
       this.y = y;
     }

     // Load Image
     raster = loadImage("world_longlatwgs3.png");
  }

 void drawBackground() {
   image(raster, x, y, w, h);
  }

 Point getPoint(float phi, float lambda) {
   Point pt = new Point(x + ((180 + lambda) / 360) * w, y + h - ((90 + phi) / 180) * h);
   return pt;
  }

}

//-------------------------------

class Point extends Point2D {
  Point(float x, float y) { 
    super(x, y); 
  }
}

class Point2D {
  float x, y;
  Point2D(float x, float y) {
    this.x = x; this.y = y;
  }
}
于 2013-06-19T22:21:29.640 回答