Loading...
Logo
Processing Forum
When i create a map, i'd like to see displayed only the contents inside the map. So markers, lines, etc. with coordinates that are outside map boundaries should be clipped. To made the question clear, just see the GeoRSSMarkerApp example with map dimension modified to explain the problem:
Copy code
  1. import processing.opengl.*;
    import codeanticode.glgraphics.*;
    import de.fhpotsdam.unfolding.*;
    import de.fhpotsdam.unfolding.geo.*;
    import de.fhpotsdam.unfolding.utils.*;

    de.fhpotsdam.unfolding.Map map;

    List<Location> rssGeoLocations = new ArrayList<Location>();

    public void setup() {
      size(800, 600, GLConstants.GLGRAPHICS);
      smooth();

      map = new de.fhpotsdam.unfolding.Map(this,20, 20, 400, 520);
      map.zoomToLevel(2);
      MapUtils.createDefaultEventDispatcher(this, map);

      loadRSSGeoLocations();
    }

    public void loadRSSGeoLocations() {
      // Load RSS feed
      String url = "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M5.xml";
      XMLElement rss = new XMLElement(this, url);
      // Get all items
      XMLElement[] itemXMLElements = rss.getChildren("channel/item");
      for (int i = 0; i < itemXMLElements.length; i++) {
        // Adds lat,lon as locations for each item
        XMLElement latXML = itemXMLElements[i].getChild("geo:lat");
        XMLElement lonXML = itemXMLElements[i].getChild("geo:long");
        float lat = Float.valueOf(latXML.getContent());
        float lon = Float.valueOf(lonXML.getContent());

        rssGeoLocations.add(new Location(lat, lon));
      }
    }

    public void draw() {
      background(0);
      map.draw();

      for (Location location : rssGeoLocations) {
        float xy[] = map.getScreenPositionFromLocation(location);
        drawEarthquakeMarker(xy[0], xy[1]);
      }
    }

    public void drawEarthquakeMarker(float x, float y) {
      noStroke();
      fill(200, 200, 0, 100);
      ellipse(x, y, 40, 40);
      fill(255, 100);
      ellipse(x, y, 30, 30);
      fill(200, 200, 0, 100);
      ellipse(x, y, 20, 20);
      fill(255, 200);
      ellipse(x, y, 10, 10);
    }

There's a simple solution to only show markers inside the map?

Thanks,
  Giovanni

Replies(2)

You need to either handle that yourself, i.e. check for each marker whether it is inside the visible area of the map, or switch to Unfolding's own marker system and use the MarkerManager and own classes for your Marker. For now, there is no Processing example, but you can find some examples at GitHub, e.g.

https://github.com/tillnagel/unfolding/blob/master/examples/de/fhpotsdam/unfolding/examples/marker/InfoMarkerApp.java
Thanks for replying. I've made a simple example, but in fact i've already investigated a bit, taking the example at GitHub as a starting point. Currently i'm plotting marker using the drawOuter() method, because i'd like to maintain marker size constant with various zoom level. But using this method markers are drawn outside map boundaries too.
It's not to difficult to check for a marker's outside the map and so not displaying it, but things get more complicated if i try to plot, i.e. rivers or state boundaries, that are harder to clip. Don't know if it's possible, but i think will be quite handful to have the possibility to let the map clip what's drawn onto it.