GeoMap into PGraphics

edited February 2018 in Library Questions

Hi, I would like to have the geoMap.draw () into a separat PGraphics buffer. I tried several things but I couldn't push it into PGraphics.

Is this possible?

import org.gicentre.geomap.*;
import org.gicentre.utils.move.*;


GeoMap geoMap;
PGraphics pg;


void setup()
{
  size(800, 400);

  pg = createGraphics(800, 400);

  geoMap = new GeoMap(this);  // Create the geoMap object.
  geoMap.readFile("world");   // Read shapefile.


}

void draw()
{
  pg.beginDraw();
  pg.background(0,0); 

  pg.geoMap.draw();              

  pg.endDraw(); 



  noLoop();            
}
Tagged:

Answers

  • Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    Notice: geoMap = new GeoMap(this); Here, the token thisrefers to current sketch. The drawing is done in the current sketch and checking the source code of the library, it does not provide any handle to draw on a separate pgraphics buffer. So what you are trying to do is not possible. If you describe what you want to do, you can get feedback or ideas how to implement your concept with the current lib design.

    Libraries follow certain design when deployed into processing. They are not mandated to provide handles to draw into an external buffer unfortunately.

    Kf

  • Hi, thank you for explaining. I would like to have several layers for the map and borders as well an design overlay. The problem, if I zoom the main sketch, all PG Layers above the main sketch scales, and some shouldn't scale.

  • and some shouldn't scale.

    Which parts shouldn't scale? The design overlay?

  • You need to post an MCVE to demonstrate your approach and your issue.

    Kf

  • Yes, just the overlay graphics shouldn't scale, so I tried to load this in a PGraphics above the Geomap layer, wich seem to be the sketch main layer.

  • Great. Did the PGraphics overlay work for you?

    If not, have you tried looking at the gicentreUtils zoomExample? It zooms, but has a non-zooming text overlay.

  • edited February 2018 Answer ✓

    @tom_tm -- Based on your earlier code, I feel like perhaps your question is the wrong one to solve your problem. You are trying to put the geoMap into its own layer -- but it is already drawn from its own layer. Instead, you need to isolate scaling of different drawn elements, and/or isolate your scaling.

    You haven't given an example of what kinds of scaling or zooming you are trying to do -- is it built-in to geomap, or separate -- and you haven't explained why you can't just:

    1. pushmatrix
    2. scale
    3. draw map
    4. popmatrix
    5. draw unscaled text overlay.

    Anyway, assuming that in addition to the above approach you need an independent "HUD" text layer, here is a working example:

    import org.gicentre.geomap.*;
    import org.gicentre.utils.move.*;
    
    GeoMap geoMap;
    PGraphics pg;
    
    void setup()
    {
      size(800, 400);
      geoMap = new GeoMap(this);  // Create the geoMap object.
      geoMap.readFile("world");   // Read shapefile.
      pg = createGraphics(width, height);
      hud(pg);
    }
    
    void draw()
    {
      background(192, 128, 128);
      if (keyPressed) {
        pushMatrix();
        scale(2);
        geoMap.draw();
        popMatrix();
      } else {
        geoMap.draw();
      }
      image(pg, 0, 0);
    }
    
    void hud(PGraphics pg)
    {
      pg.beginDraw();
      pg.clear();
      pg.fill(0, 127);
      pg.rect(0, 0, pg.width, 20);
      pg.fill(255);
      pg.text("Press space to zoom. This text is in an independent HUD layer", 10, 15);
      pg.endDraw();
    }
    
  • @jeremydouglass

    Hi, thank you a lot for showing me the push/pop Matrix trick. Now I could isolate the transformation and have an overlay.

    I will post later my sketch for other people looking into this.

    Thank you again Tom

Sign In or Register to comment.