Draw points within map boundaries

edited February 2015 in Library Questions

Hi, I'm plotting points onto a map, but they display outside the map boundaries. I have 2 side-by -side maps, so points form one overlap onto the other. How can I draw these points and limit them to the map? Or is there a way to say that if points are outside the map area, draw them with noFill()?

This is my code:

      import de.fhpotsdam.unfolding.*;
      import de.fhpotsdam.unfolding.geo.*;
      import de.fhpotsdam.unfolding.utils.*;
      import de.fhpotsdam.unfolding.providers.*;
      import de.fhpotsdam.unfolding.data.*;``
      import de.fhpotsdam.unfolding.mapdisplay.MapDisplayFactory;

      import de.bezier.data.sql.*;

      UnfoldingMap map1;
      UnfoldingMap map2;
      MySQL msql;

      ArrayList<Events> aevents = new ArrayList();    //2 arraylists for points in 2 areas
      ArrayList<Events> bevents = new ArrayList();

      public void setup() {
          size(1300, 650, P2D);
          smooth();

      map1 = new UnfoldingMap(this, "map1", 250, 10, 515, 630, true, false, new Google.GoogleTerrainProvider());
      map2 = new UnfoldingMap(this, "map2", 775, 10, 515, 630, true, false, new Google.GoogleTerrainProvider());
      MapUtils.createDefaultEventDispatcher(this, map1, map2);

      map1.zoomAndPanTo(new Location(-37.7f, 144.8f), 11);
      map2.zoomAndPanTo(new Location(-37.8f, 145.1f), 11);
      float maxPanningDistance = 30;   // in km
      map1.setPanningRestriction(new Location(-37.7f, 144.8f), maxPanningDistance);
      map2.setPanningRestriction(new Location(-37.8f, 145.1f), maxPanningDistance);

          //connect to MySQL database
          String user = "****";
          String pass = "****";
          String database = "database";

          msql = new MySQL(this, "localhost", database, user, pass);

          if (msql.connect())
          { //Events a
            msql.query("select ... etc;");
            while (msql.next ())
            {
              String l = msql.getString("locationType");
              int id = msql.getInt("participant_id");
              float lat = msql.getFloat("lat"); 
              float lon = msql.getFloat("lon");
              println("A " + l + "   " + id + "   " + lat + "   " + lon);

              //create new empty object to store data
              Events aevent = new Events();
              // Add to list of all events
              aevents.add(aevent); 
              //location of events
              Location location = new Location(lat, lon);
              }
          } 

          if (msql.connect())     
          { //Events b
            msql.query("select ... etc;");
            while (msql.next ())
            {   
              String l = msql.getString("locationType");
              int id = msql.getInt("participant_id");
              float lat = msql.getFloat("lat"); 
              float lon = msql.getFloat("lon");
              println("B " + l + "   " + id + "   " + lat + "   " + lon);

              //create new empty object to store data
              Events bevent = new Events();
              // Add to list of all events
              bevents.add(bevent);
              //location of events
              Location location = new Location(lat, lon);

            }
            println("Number of events for A: " + aevents.size());
            println("Number of events for B: " + bevents.size());
          } else {
            //connection failed
          }
        }

        public void draw() {
          background(230);
          map1.draw();
          map2.draw();
          //Darken map slightly
          fill(0, 100);
          rect(0, 0, width, height);

          noStroke();

          // Iterate over all A events
          for (Events aevent : aevents) {
            // Convert geo locations to screen positions
            ScreenPosition pos = map1.getScreenPosition(aevent.location);
            // Draw circle for events
            fill(255, 0, 255, 50);
            ellipse(pos.x, pos.y, 8, 8);
          }
          // Iterate over all B events
          for (Events bevent : bevents) {
            // Convert geo locations to screen positions
            ScreenPosition pos = map2.getScreenPosition(bevent.location);
            // Draw circle for events
            fill(50, 255, 100, 50);
            ellipse(pos.x, pos.y, 8, 8);
          }
        }

        class Events {

          int participant_id;
          String locationType;
          double lat;
          double lon;
          Location location;

        }
Tagged:

Answers

  • Answer ✓

    Moved to Library Questions as the answer is probably dependent on this library.

Sign In or Register to comment.