Unfolding Maps — mapDisplay.getOuterPG() is not working!

edited September 2016 in Library Questions
import processing.core.PApplet;
import processing.core.PGraphics;

import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.providers.OpenStreetMap;
import de.fhpotsdam.unfolding.utils.MapUtils;


    private UnfoldingMap map;
    private PGraphics pg;

    private int n = 1000;

    public void setup() {

        size(n, n, P2D);
        map = new UnfoldingMap(this, new OpenStreetMap.OpenStreetMapProvider());
        MapUtils.createDefaultEventDispatcher(this, map);

    }

    public void draw() {

        background(0);
        pg = map.mapDisplay.getOuterPG();
        image(pg, 0, 0);

    }

Greetings! When I try to convert maps into PGraphics and display it, I see only black background :( Can anyone explain why it is so? Thank you!

Answers

  • Answer ✓

    I can get it to work when I called map.draw() To compare what map.draw does to what the pg object holds, I draw both of them side by side. You can see what pg holds if you save the frame (uncomment the line with the saving action)

    Kf

    import processing.core.PApplet; import processing.core.PGraphics;

    import de.fhpotsdam.unfolding.UnfoldingMap;
    import de.fhpotsdam.unfolding.providers.OpenStreetMap;
    import de.fhpotsdam.unfolding.utils.MapUtils;
    
    
    private UnfoldingMap map;
    private PGraphics pg;
    
    private int n = 1000;
    
    public void setup() {
    
      size(800, 400, P2D);
      map = new UnfoldingMap(this, 0, 0, width/2, height, new OpenStreetMap.OpenStreetMapProvider());
      MapUtils.createDefaultEventDispatcher(this, map);
    
    }
    
    public void draw() {
    
      map.draw();
      pg = map.mapDisplay.getOuterPG();  
    
      //pg.save("ob.jpg");
      image(pg, width/2, 0);
    }
    
  • edited September 2016

    Many thanks! But I can not understand why the

    pg = map.mapDisplay.getOuterPG(); 
    image(pg, x, y);`
    

    does not work without

    map.draw();

    Can you explain?

  • @listopad The only way I was able to get it to work was by calling draw first. I'm not too familiar with unfolding maps. However @tnagel could provide you an answer. I guess you don't want the actual unfolding map features which allows the user to work on the loaded map. What you want is to have access to the title displaying the map? Can you elaborate in the details of what you would like to accomplish? Maybe somebody in the forum could provide some other ideas to approach your challenge.

    Kf

  • I would like to mask the map into an ellipse. I achieved this by improving your method, but I had a problem - on canvas draws two maps (unfolding map and pg). I solved this problem by rendering unfolding map outside of the document.

Sign In or Register to comment.