Changeset 19220 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor
- Timestamp:
- 2024-09-11T21:33:23+02:00 (2 months ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledTiledMapRenderer.java
r19180 r19220 8 8 import java.awt.Font; 9 9 import java.awt.Graphics2D; 10 import java.awt.GraphicsConfiguration; 10 11 import java.awt.Image; 11 12 import java.awt.Point; … … 13 14 import java.awt.Transparency; 14 15 import java.awt.event.MouseEvent; 15 import java.awt.geom.AffineTransform;16 16 import java.awt.image.BufferedImage; 17 17 import java.util.ArrayList; … … 22 22 import java.util.Map; 23 23 import java.util.Objects; 24 import java.util.Optional;25 24 import java.util.Set; 26 25 import java.util.concurrent.Executor; 26 import java.util.concurrent.ExecutorService; 27 27 import java.util.function.Consumer; 28 28 import java.util.stream.Collectors; … … 52 52 private int zoom; 53 53 private Consumer<TileZXY> notifier; 54 private final ExecutorService worker; 54 55 55 56 /** … … 65 66 public StyledTiledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) { 66 67 super(g, nc, isInactiveMode); 68 this.worker = MainApplication.worker; 67 69 } 68 70 … … 74 76 return; 75 77 } 76 final Executor worker = MainApplication.worker;78 final Executor worker = this.worker; 77 79 final BufferedImage tempImage; 78 80 final Graphics2D tempG2d; 79 81 // I'd like to avoid two image copies, but there are some issues using the original g2d object 80 tempImage = nc.getGraphicsConfiguration().createCompatibleImage(this.nc.getWidth(), this.nc.getHeight(), Transparency.TRANSLUCENT);82 tempImage = createCompatibleImage(nc, this.nc.getWidth(), this.nc.getHeight()); 81 83 tempG2d = tempImage.createGraphics(); 82 84 tempG2d.setComposite(AlphaComposite.DstAtop); // Avoid tile lines in large areas … … 94 96 final Point min = this.nc.getPoint(box2.getMin()); 95 97 final Point max = this.nc.getPoint(box2.getMax()); 96 tileSize = max.x - min.x + BUFFER_PIXELS;98 tileSize = max.x - min.x; 97 99 } 98 100 … … 151 153 painted++; 152 154 } 153 // There seems to be an off-by-one error somewhere. 154 tempG2d.drawImage(tileImage, point.x + 1, point.y + 1, null, null); 155 // There seems to be an off-by-one error somewhere. Seems to be tied to sign of lat/lon 156 final int offset = (tile.lat() > 0 ? 1 : 0) + (tile.lon() >= 0 ? 1 : 0); 157 tempG2d.drawImage(tileImage, point.x + 1, point.y + offset, null, null); 155 158 } else { 156 159 Logging.trace("StyledMapRenderer did not paint tile {1}", tile); … … 250 253 251 254 temporaryView.zoomTo(bounds.getCenter().getEastNorth(ProjectionRegistry.getProjection()), mapState.getScale()); 252 BufferedImage bufferedImage = Optional.ofNullable(nc.getGraphicsConfiguration()) 253 .map(gc -> gc.createCompatibleImage(tileSize * xCount + xCount, tileSize * yCount + yCount, Transparency.TRANSLUCENT)) 254 .orElseGet(() -> new BufferedImage(tileSize * xCount + xCount, tileSize * yCount + yCount, BufferedImage.TYPE_INT_ARGB)); 255 BufferedImage bufferedImage = createCompatibleImage(nc, width, height); 255 256 Graphics2D g2d = bufferedImage.createGraphics(); 256 257 try { 257 258 g2d.setRenderingHints(Map.of(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); 258 g2d.setTransform(AffineTransform.getTranslateInstance(-BUFFER_TILES * (double) tileSize, -BUFFER_TILES * (double) tileSize));259 259 final AbstractMapRenderer tilePainter = MapRendererFactory.getInstance().createActiveRenderer(g2d, temporaryView, false); 260 260 tilePainter.render(data, true, bounds); … … 262 262 g2d.dispose(); 263 263 } 264 return bufferedImage; 264 final int bufferPixels = BUFFER_TILES * tileSize; 265 return bufferedImage.getSubimage(bufferPixels, bufferPixels, 266 width - 2 * bufferPixels + BUFFER_PIXELS, height - 2 * bufferPixels + BUFFER_PIXELS); 267 } 268 269 private static BufferedImage createCompatibleImage(NavigatableComponent nc, int width, int height) { 270 final GraphicsConfiguration gc = nc.getGraphicsConfiguration(); 271 if (gc == null) { 272 return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 273 } 274 return gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT); 265 275 } 266 276 … … 319 329 for (TileLoader loader : tileCollection) { 320 330 final TileZXY txy = loader.tile; 321 final int x = (txy.x() - minX) * (tileSize - BUFFER_PIXELS) + BUFFER_PIXELS / 2;322 final int y = (txy.y() - minY) * (tileSize - BUFFER_PIXELS) + BUFFER_PIXELS / 2;323 final int wh = tileSize - BUFFER_PIXELS / 2;324 325 final BufferedImage tileImage = tImage.getSubimage(x, y, wh , wh);331 final int x = (txy.x() - minX) * tileSize; 332 final int y = (txy.y() - minY) * tileSize; 333 final int wh = tileSize; 334 335 final BufferedImage tileImage = tImage.getSubimage(x, y, wh + BUFFER_PIXELS, wh + BUFFER_PIXELS); 326 336 loader.cacheTile(tileImage); 327 337 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/TileZXY.java
r19181 r19220 9 9 10 10 /** 11 * A record used for storing tile information for painting 11 * A record used for storing tile information for painting. 12 * The origin is upper-left, not lower-left (so more like Google tile coordinates than TMS tile coordinates). 12 13 * @since 19176 13 14 */ … … 144 145 */ 145 146 public static TileZXY latLonToTile(double lat, double lon, int zoom) { 146 int xCoord = (int) Math.floor(Math.pow(2, zoom) * (180 + lon) / 360); 147 int yCoord = (int) Math.floor(Math.pow(2, zoom) * 148 (1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2); 147 final double zoom2 = Math.pow(2, zoom); 148 final double latLog = Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))); 149 final int xCoord = (int) Math.floor(zoom2 * (180 + lon) / 360); 150 final int yCoord = (int) Math.floor(zoom2 * (1 - latLog / Math.PI) / 2); 149 151 return new TileZXY(zoom, xCoord, yCoord); 150 152 }
Note:
See TracChangeset
for help on using the changeset viewer.