0

Processingで世界地図を表示し、対応する場所にツイートをプロットするのを手伝ってくれませんか?

4

1 に答える 1

1

This isn't an entire answer, but should show how to plot the locations on a world map. Note the getPoint() method that does the Cartesian coordinates (you could do the same with the map() function in Processing.Also note the constructor does the calculations to size the image of the earth you use to the sketch window...

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 に答える