Changeset 35224 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2019-11-04T23:17:38+01:00 (5 years ago)
Author:
wiktorn
Message:

Do not use zoom levels that lead to int overflows.

When fitting map to map elements do not use zoom levels that may lead to X/Y
coordinates to overflow. This prevents setting focus to place pointed by
overflown coordinates, when tile source allows higher zoom levels.

Now zoom level is capped based on tile size, so X/Y will not overflow.

See: #josm18289

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r35190 r35224  
    298298        int xMax = Integer.MIN_VALUE;
    299299        int yMax = Integer.MIN_VALUE;
    300         int mapZoomMax = tileController.getTileSource().getMaxZoom();
     300        /*
     301         *  Cap mapZoomMax at highest level that prevents overflowing int in X and Y coordinates. As int is from -2^31..2^31.
     302         *  Log_2(TileSize) is how many bits are used due to tile size. Math.log(TileSize) / Math.log(2) gives Log_2(TileSize)
     303         *  So 31 - tileSizeBits gives maximum zoom that can be handled without overflowing.
     304         *  It means 23 for 256 tile size or 22 for 512 tile size
     305         */
     306        int tileSizeBits = (int) (Math.log(tileController.getTileSource().getDefaultTileSize()) / Math.log(2));
     307        int mapZoomMax =  Math.min(31 - tileSizeBits, tileController.getTileSource().getMaxZoom());
    301308
    302309        if (markers && mapMarkerList != null) {
Note: See TracChangeset for help on using the changeset viewer.