Changeset 8349 in josm


Ignore:
Timestamp:
2015-05-14T13:26:49+02:00 (9 years ago)
Author:
stoecker
Message:

see #11419 - support different tile sizes better (patch by wiktorn)

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/maps.xsd

    r8344 r8349  
    671671                                                                </xs:complexType>
    672672                                                        </xs:element>
     673                                                        <!-- list of HTTP headers, that indicate "no tile at this zoom level" situation -->
    673674                                                        <xs:element name="no-tile-header" minOccurs="0" maxOccurs="unbounded">
    674675                                                                <xs:complexType>
     
    677678                                                                </xs:complexType>
    678679                                                        </xs:element>
     680                                                        <!-- tile size provided by imagery source. Default - 256 -->
     681                                                        <xs:element name="tile-size" minOccurs="0" maxOccurs="1" type="xs:positiveInteger" />
    679682                                                </xs:choice>
    680683                                        </xs:sequence>
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r8344 r8349  
    1919
    2020import org.openstreetmap.gui.jmapviewer.Coordinate;
     21import org.openstreetmap.gui.jmapviewer.OsmMercator;
    2122import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
    2223import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource;
     
    225226        @pref String description;
    226227        @pref Map<String, String> noTileHeaders;
     228        @pref int tileSize = OsmMercator.DEFAUL_TILE_SIZE;
    227229
    228230        /**
     
    281283                noTileHeaders = i.noTileHeaders;
    282284            }
     285
     286            tileSize = i.getTileSize();
    283287        }
    284288
     
    402406            noTileHeaders = e.noTileHeaders;
    403407        }
     408        setTileSize(e.tileSize);
    404409    }
    405410
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r8344 r8349  
    150150        for (ImageryInfo def : defaultLayers) {
    151151            // temporary migration code, so all user preferences will get updated with new settings from JOSM site (can be removed ~Dez. 2015)
    152             if (def.getNoTileHeaders() != null) {
     152            if (def.getNoTileHeaders() != null || def.getTileSize() > 0) {
    153153                for (ImageryInfo i: layers) {
    154154                    if (isSimilar(def,  i)) {
    155                         i.setNoTileHeaders(def.getNoTileHeaders());
     155                        if (def.getNoTileHeaders() != null) {
     156                            i.setNoTileHeaders(def.getNoTileHeaders());
     157                        }
     158                        if (def.getTileSize() > 0) {
     159                            i.setTileSize(def.getTileSize());
     160                        }
    156161                        changed = true;
    157162                    }
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r8308 r8349  
    125125
    126126    // upper left and lower right corners of the selection rectangle (x/y on ZOOM_MAX)
    127     private Point iSelectionRectStart;
    128     private Point iSelectionRectEnd;
     127    private Coordinate iSelectionRectStart;
     128    private Coordinate iSelectionRectEnd;
    129129
    130130    /**
     
    210210            // draw selection rectangle
    211211            if (iSelectionRectStart != null && iSelectionRectEnd != null) {
    212 
    213                 int zoomDiff = MAX_ZOOM - zoom;
    214                 Point tlc = getTopLeftCoordinates();
    215                 int x_min = (iSelectionRectStart.x >> zoomDiff) - tlc.x;
    216                 int y_min = (iSelectionRectStart.y >> zoomDiff) - tlc.y;
    217                 int x_max = (iSelectionRectEnd.x >> zoomDiff) - tlc.x;
    218                 int y_max = (iSelectionRectEnd.y >> zoomDiff) - tlc.y;
    219 
    220                 int w = x_max - x_min;
    221                 int h = y_max - y_min;
     212                Rectangle box = new Rectangle(getMapPosition(iSelectionRectStart, false));
     213                box.add(getMapPosition(iSelectionRectEnd, false));
     214
    222215                g.setColor(new Color(0.9f, 0.7f, 0.7f, 0.6f));
    223                 g.fillRect(x_min, y_min, w, h);
     216                g.fillRect(box.x, box.y, box.width, box.height);
    224217
    225218                g.setColor(Color.BLACK);
    226                 g.drawRect(x_min, y_min, w, h);
     219                g.drawRect(box.x, box.y, box.width, box.height);
    227220            }
    228221        } catch (Exception e) {
     
    257250        Point p_min = new Point(Math.min(aEnd.x, aStart.x), Math.min(aEnd.y, aStart.y));
    258251
    259         Point tlc = getTopLeftCoordinates();
    260         int zoomDiff = MAX_ZOOM - zoom;
    261         Point pEnd = new Point(p_max.x + tlc.x, p_max.y + tlc.y);
    262         Point pStart = new Point(p_min.x + tlc.x, p_min.y + tlc.y);
    263 
    264         pEnd.x <<= zoomDiff;
    265         pEnd.y <<= zoomDiff;
    266         pStart.x <<= zoomDiff;
    267         pStart.y <<= zoomDiff;
    268 
    269         iSelectionRectStart = pStart;
    270         iSelectionRectEnd = pEnd;
    271 
    272         Coordinate l1 = getPosition(p_max); // lon may be outside [-180,180]
    273         Coordinate l2 = getPosition(p_min); // lon may be outside [-180,180]
     252        iSelectionRectStart = getPosition(p_min);
     253        iSelectionRectEnd =   getPosition(p_max);
     254
    274255        Bounds b = new Bounds(
    275256                new LatLon(
    276                         Math.min(l2.getLat(), l1.getLat()),
    277                         LatLon.toIntervalLon(Math.min(l1.getLon(), l2.getLon()))
     257                        Math.min(iSelectionRectStart.getLat(), iSelectionRectEnd.getLat()),
     258                        LatLon.toIntervalLon(Math.min(iSelectionRectStart.getLon(), iSelectionRectEnd.getLon()))
    278259                        ),
    279260                        new LatLon(
    280                                 Math.max(l2.getLat(), l1.getLat()),
    281                                 LatLon.toIntervalLon(Math.max(l1.getLon(), l2.getLon())))
     261                                Math.max(iSelectionRectStart.getLat(), iSelectionRectEnd.getLat()),
     262                                LatLon.toIntervalLon(Math.max(iSelectionRectStart.getLon(), iSelectionRectEnd.getLon())))
    282263                );
    283264        Bounds oldValue = this.bbox;
     
    332313        }
    333314
    334         int y1 = tileSource.LatToY(bbox.getMinLat(), MAX_ZOOM);
    335         int y2 = tileSource.LatToY(bbox.getMaxLat(), MAX_ZOOM);
    336         int x1 = tileSource.LonToX(minLon, MAX_ZOOM);
    337         int x2 = tileSource.LonToX(maxLon, MAX_ZOOM);
    338 
    339         iSelectionRectStart = new Point(Math.min(x1, x2), Math.min(y1, y2));
    340         iSelectionRectEnd = new Point(Math.max(x1, x2), Math.max(y1, y2));
     315        iSelectionRectStart = new Coordinate(bbox.getMinLat(), bbox.getMinLon());
     316        iSelectionRectEnd = new Coordinate(bbox.getMaxLat(), bbox.getMaxLon());
    341317
    342318        // calc the screen coordinates for the new selection rectangle
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r8345 r8349  
    6666import org.openstreetmap.josm.data.preferences.StringProperty;
    6767import org.openstreetmap.josm.data.projection.Projection;
     68import org.openstreetmap.josm.gui.ExtendedDialog;
    6869import org.openstreetmap.josm.gui.MapFrame;
    6970import org.openstreetmap.josm.gui.MapView;
     
    423424
    424425    private final int getBestZoom() {
    425         double factor = getScaleFactor(1);
     426        double factor = getScaleFactor(1); // check the ratio between area of tilesize at zoom 1 to current view
    426427        double result = Math.log(factor)/Math.log(2)/2+1;
    427         // In general, smaller zoom levels are more readable.  We prefer big,
    428         // block, pixelated (but readable) map text to small, smeared,
    429         // unreadable underzoomed text.  So, use .floor() instead of rounding
    430         // to skew things a bit toward the lower zooms.
     428        /*
     429         * Math.log(factor)/Math.log(2) - gives log base 2 of factor
     430         * We divide result by 2, as factor contains ratio between areas. We could do Math.sqrt before log, or just divide log by 2
     431         * In general, smaller zoom levels are more readable.  We prefer big,
     432         * block, pixelated (but readable) map text to small, smeared,
     433         * unreadable underzoomed text.  So, use .floor() instead of rounding
     434         * to skew things a bit toward the lower zooms.
     435         * Remember, that result here, should correspond to TMSLayer.paint(...)
     436         * getScaleFactor(...) is supposed to be between 0.75 and 3
     437         */
    431438        int intResult = (int)Math.floor(result);
    432439        if (intResult > getMaxZoomLvl())
     
    514521            public void actionPerformed(ActionEvent ae) {
    515522                if (clickedTile != null) {
    516                     showMetadataTile = clickedTile;
    517                     redraw();
     523                    ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Tile Info"), new String[]{tr("OK")});
     524                    ed.setIcon(JOptionPane.INFORMATION_MESSAGE);
     525                    StringBuilder content = new StringBuilder();
     526                    content.append("Tile name: ").append(clickedTile.getKey()).append("\n");
     527                    try {
     528                        content.append("Tile url: ").append(clickedTile.getUrl()).append("\n");
     529                    } catch (IOException e) {
     530                    }
     531                    content.append("Tile size: ").append(clickedTile.getTileSource().getTileSize()).append("x").append(clickedTile.getTileSource().getTileSize()).append("\n");
     532                    Rectangle displaySize = tileToRect(clickedTile);
     533                    content.append("Tile display size: ").append(displaySize.width).append("x").append(displaySize.height).append("\n");
     534                    ed.setContent(content.toString());
     535                    ed.showDialog();
    518536                }
    519537            }
     
    13841402            myDrawString(g, tr("Display zoom: {0}", displayZoomLevel), 50, 155);
    13851403            myDrawString(g, tr("Pixel scale: {0}", getScaleFactor(currentZoomLevel)), 50, 170);
    1386             myDrawString(g, tr("Best zoom: {0}", Math.log(getScaleFactor(1))/Math.log(2)/2+1), 50, 185);
     1404            myDrawString(g, tr("Best zoom: {0}", getBestZoom()), 50, 185);
    13871405            if(tileLoader instanceof TMSCachedTileLoader) {
    13881406                TMSCachedTileLoader cachedTileLoader = (TMSCachedTileLoader)tileLoader;
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r8347 r8349  
    138138                        "country-code",
    139139                        "icon",
     140                        "tile-size",
    140141                }).contains(qName)) {
    141142                    newState = State.ENTRY_ATTRIBUTE;
     
    300301                    entry.setIcon(accumulator.toString());
    301302                    break;
     303                case "tile-size":
     304                    Integer tileSize = null;
     305                    try {
     306                        tileSize  = Integer.parseInt(accumulator.toString());
     307                    } catch(NumberFormatException e) {
     308                        tileSize = null;
     309                    }
     310                    if (tileSize == null) {
     311                        skipEntry = true;
     312                    } else {
     313                        entry.setTileSize(tileSize.intValue());
     314                    }
     315                    break;
    302316                }
    303317                break;
Note: See TracChangeset for help on using the changeset viewer.