Ticket #7872: wmsTileSize-0.patch

File wmsTileSize-0.patch, 4.9 KB (added by Cobra, 13 years ago)

patch for adjustable wms tile size, breaks saving and loading wms layers from/to files

  • src/org/openstreetmap/josm/gui/layer/WMSLayer.java

     
    105105    public static final BooleanProperty PROP_OVERLAP = new BooleanProperty("imagery.wms.overlap", false);
    106106    public static final IntegerProperty PROP_OVERLAP_EAST = new IntegerProperty("imagery.wms.overlapEast", 14);
    107107    public static final IntegerProperty PROP_OVERLAP_NORTH = new IntegerProperty("imagery.wms.overlapNorth", 4);
     108    public static final IntegerProperty PROP_IMAGE_SIZE = new IntegerProperty("imagery.wms.imageSize", 500);
    108109
    109110    public int messageNum = 5; //limit for messages per layer
    110111    protected String resolution;
     
    168169                }
    169170            }
    170171            if (cache == null) {
    171                 cache = new WmsCache(info.getUrl(), imageSize);
     172                cache = new WmsCache(info.getUrl(), PROP_IMAGE_SIZE.get());
    172173                cache.loadIndex();
    173174            }
    174175        }
     
    343344    }
    344345
    345346    public int getImageXIndex(double coord) {
    346         return (int)Math.floor( ((coord - dx) * info.getPixelPerDegree()) / imageSize);
     347        return (int)Math.floor( ((coord - dx) * info.getPixelPerDegree()) / PROP_IMAGE_SIZE.get());
    347348    }
    348349
    349350    public int getImageYIndex(double coord) {
    350         return (int)Math.floor( ((coord - dy) * info.getPixelPerDegree()) / imageSize);
     351        return (int)Math.floor( ((coord - dy) * info.getPixelPerDegree()) / PROP_IMAGE_SIZE.get());
    351352    }
    352353
    353354    public int getImageX(int imageIndex) {
    354         return (int)(imageIndex * imageSize * (getPPD() / info.getPixelPerDegree()) + dx * getPPD());
     355        return (int)(imageIndex * PROP_IMAGE_SIZE.get() * (getPPD() / info.getPixelPerDegree()) + dx * getPPD());
    355356    }
    356357
    357358    public int getImageY(int imageIndex) {
    358         return (int)(imageIndex * imageSize * (getPPD() / info.getPixelPerDegree()) + dy * getPPD());
     359        return (int)(imageIndex * PROP_IMAGE_SIZE.get() * (getPPD() / info.getPixelPerDegree()) + dy * getPPD());
    359360    }
    360361
    361362    public int getImageWidth(int xIndex) {
     
    371372     * @return Size of image in original zoom
    372373     */
    373374    public int getBaseImageWidth() {
    374         int overlap = PROP_OVERLAP.get() ? (PROP_OVERLAP_EAST.get() * imageSize / 100) : 0;
    375         return imageSize + overlap;
     375        int overlap = PROP_OVERLAP.get() ? (PROP_OVERLAP_EAST.get() * PROP_IMAGE_SIZE.get() / 100) : 0;
     376        return PROP_IMAGE_SIZE.get() + overlap;
    376377    }
    377378
    378379    /**
     
    380381     * @return Size of image in original zoom
    381382     */
    382383    public int getBaseImageHeight() {
    383         int overlap = PROP_OVERLAP.get() ? (PROP_OVERLAP_NORTH.get() * imageSize / 100) : 0;
    384         return imageSize + overlap;
     384        int overlap = PROP_OVERLAP.get() ? (PROP_OVERLAP_NORTH.get() * PROP_IMAGE_SIZE.get() / 100) : 0;
     385        return PROP_IMAGE_SIZE.get() + overlap;
    385386    }
    386387
    387388    public int getImageSize() {
    388         return imageSize;
     389        return PROP_IMAGE_SIZE.get();
    389390    }
    390391
    391392    public boolean isOverlapEnabled() {
     
    399400    public BufferedImage normalizeImage(BufferedImage img) {
    400401        if (isOverlapEnabled()) {
    401402            BufferedImage copy = img;
    402             img = new BufferedImage(imageSize, imageSize, copy.getType());
    403             img.createGraphics().drawImage(copy, 0, 0, imageSize, imageSize,
    404                     0, copy.getHeight() - imageSize, imageSize, copy.getHeight(), null);
     403            img = new BufferedImage(PROP_IMAGE_SIZE.get(), PROP_IMAGE_SIZE.get(), copy.getType());
     404            img.createGraphics().drawImage(copy, 0, 0, PROP_IMAGE_SIZE.get(), PROP_IMAGE_SIZE.get(),
     405                    0, copy.getHeight() - PROP_IMAGE_SIZE.get(), PROP_IMAGE_SIZE.get(), copy.getHeight(), null);
    405406        }
    406407        return img;
    407408    }
     
    413414     * @return Real EastNorth of given tile. dx/dy is not counted in
    414415     */
    415416    public EastNorth getEastNorth(int xIndex, int yIndex) {
    416         return new EastNorth((xIndex * imageSize) / info.getPixelPerDegree(), (yIndex * imageSize) / info.getPixelPerDegree());
     417        return new EastNorth((xIndex * PROP_IMAGE_SIZE.get()) / info.getPixelPerDegree(), (yIndex * PROP_IMAGE_SIZE.get()) / info.getPixelPerDegree());
    417418    }
    418419
    419420    protected void downloadAndPaintVisible(Graphics g, final MapView mv, boolean real){
     
    986987        } else if (
    987988                event.getKey().equals(PROP_OVERLAP.getKey())
    988989                || event.getKey().equals(PROP_OVERLAP_EAST.getKey())
    989                 || event.getKey().equals(PROP_OVERLAP_NORTH.getKey())) {
     990                || event.getKey().equals(PROP_OVERLAP_NORTH.getKey())
     991                || event.getKey().equals(PROP_IMAGE_SIZE.getKey())) {
    990992            for (int i=0; i<images.length; i++) {
    991993                for (int k=0; k<images[i].length; k++) {
    992994                    images[i][k] = new GeorefImage(this);