Removing Markers in Unfolding

Hi all,

I’m currently working on a map-based data visualization using Processing and Unfolding library. I’ve been able to add markers from my geojson file to the map. However I can’t figure out how I can remove markers. For example: how can I make markers appear/disappear on keyPressed or mousePressed.
By reading the library documentation I understood that there is a method called removeMarker() but I wasn’t able to get it to work.

Here’s my code:

import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import java.util.List;


UnfoldingMap map;
Location oaklandLocation = new Location(37.79, -122.23); // sets location to Oakland

List<Feature> features;
List<Marker> markers;

public void setup() {
  size(800, 600, P2D);
  noStroke();

  smooth();
  map = new UnfoldingMap(this); 
  MapUtils.createDefaultEventDispatcher(this, map);
  map.zoomAndPanTo(oaklandLocation, 12); //sets default to Oakland by zooming into that area
  float maxPanningDistance = 1; //defines maximum panning distance value in km. 
  map.setPanningRestriction(oaklandLocation, maxPanningDistance);//restricts panning
  map.setZoomRange(12, 15);//restircts zooming

  features = GeoJSONReader.loadData(this, "BART_Stations.geojson");
  MarkerFactory markerFactory = new MarkerFactory();
  markerFactory.setPointClass(pointStyle.class);
  markers = markerFactory.createMarkers(features);
  map.addMarkers(markers);
}

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

  //if (mouseX < width/2) {
  //  map.clearMarkers();
  //}
}

I also have a java class called **pointStyle.java** to customize the markers:

import processing.core.PGraphics;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.marker.SimplePointMarker;

public class pointStyle extends SimplePointMarker {

  public pointStyle(Location location) {
    super(location);
  }

  public void draw(PGraphics pg, float x, float y) {
    pg.pushStyle();
    pg.noStroke();
    pg.fill(245, 98, 30, 100);
    pg.ellipse(x, y, 20, 20);
    pg.popStyle();
  }
}

I appreciate any help! :slight_smile:

1 Like

Hello again!

I got help from Till Nagel who wrote the library and the issue is solved now. I’m posting it here in case someone comes across the same question in the future:

public void keyPressed() {
  MarkerManager&lt;Marker&gt; markerManager = map.getDefaultMarkerManager();
  if (key == 'c') {
    markerManager.clearMarkers();
  }
  if (key == 'r') {
    markerManager.addMarkers(markers);
  }
}
3 Likes