1

I am drawing an OpenStreetMaps XML file onto a Swing Frame, and applying the following AffineTransform:

     transform.scale(.56 * scale, -scale);
     transform.translate(-model.bbox.getMinX(),
            -model.bbox.getMaxY());

If I however draw Strings directly onto this Transform, they will be both inverted and upside down. I am drawing the Strings based of related Point2Ds, that are in world coordinates, so I am looking for a way, to either get screen coordinates based of these Point2Ds, or the correct way of making a seperate AffineTransform for drawing the text. I have played around with making a seperate AffineTransform for the text, but have not been able to get values that make sense, so that the Strings fit onto the map correctly. Below is the code I use for drawing the Strings, resulting in inverted, upside down Strings, however drawn in correct places.

    for (Map.Entry<String, Point2D> amenity : model.getAmenityNames().entrySet()) {
            if(!amenity.getKey().equals("")){
                Point2D point = amenity.getValue();
                float X = (float)point.getX();
                float Y = (float)point.getY();

                g.setStroke(new BasicStroke(Float.MIN_VALUE+0.001f));
                g.setColor(Color.RED);

                Font font = getFont().deriveFont(0.0001f);
                g.setFont(font);
                g.drawString(amenity.getKey(), X ,Y);
            }
        }
Emil L.
  • 97
  • 10

0 Answers0