Ignore:
Timestamp:
2009-06-26T20:27:43+02:00 (15 years ago)
Author:
lvarga
Message:

Commited first 3 of 14 patches from Dave Hansen <dave@…>. His info to patches from mailinglist "josm-dev" <josm-dev@…> posted at 2009-06-13 23:04.

This makes the scaling calculator work even if the image passed in
to it is not currently loaded. It will try to use the last image
passed in as an approximation. If *that* doesn't work, it assumes
sane values until an image loads.
image-scaling

This lets SlippyMapTiles keep track of whether they have
an image in the process of being downloaded. This is
because we sometimes want to abort a download in progress
but we don't want to clear the image if it has already
been fully downloaded. Also let the zoom level be
queried.

I introduced a couple of bugs because of this and it was
my fault anyway from an earlier patch.
This makes the argument order consistent.

Location:
applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapKey.java

    r14732 r16153  
    1212 * @author LuVar <lubomir.varga@freemap.sk>
    1313 * @author Dave Hansen <dave@sr71.net>
     14 * @author Dave Hansen <dave@linux.vnet.ibm.com>
    1415 *
    1516 */
     
    2930         */
    3031        public final boolean valid;
    31         public SlippyMapKey(int level, int x, int y) {
     32        public SlippyMapKey(int x, int y, int level) {
    3233                this.x = x;
    3334                this.y = y;
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java

    r15707 r16153  
    4040 * @author LuVar <lubomir.varga@freemap.sk>
    4141 * @author Dave Hansen <dave@sr71.net>
    42  *
     42 * @author Dave Hansen <dave@linux.vnet.ibm.com>
     43 *
    4344 */
    4445public class SlippyMapLayer extends Layer implements ImageObserver,
     
    279280        for (int x = z12x0 - 1; x <= z12x1; x++) {
    280281            for (int y = z12y0 - 1; y <= z12y1; y++) {
    281                 SlippyMapKey key = new SlippyMapKey(currentZoomLevel, x, y);
     282                SlippyMapKey key = new SlippyMapKey(x, y, currentZoomLevel);
    282283                SlippyMapTile tile = tileStorage.get(key);
    283284                if (!key.valid) {
     
    295296    }
    296297
    297     /*
    298      * Attempt to approximate how much the image is
    299      * being scaled.  For instance, a 100x100 image
    300      * being scaled to 50x50 would return 0.25.
    301      */
    302     double getImageScaling(Image img, Point p0, Point p1)
    303     {
    304         int realWidth = img.getWidth(this);
    305         int realHeight = img.getHeight(this);
    306         if (realWidth == -1 || realHeight == -1)
    307                 return 1.0;
    308         int drawWidth = p1.x - p0.x;
    309         int drawHeight = p1.x - p0.x;
    310 
    311         double drawArea = drawWidth * drawHeight;
     298        /*
     299         * Attempt to approximate how much the image is being scaled. For instance,
     300         * a 100x100 image being scaled to 50x50 would return 0.25.
     301         */
     302        Image lastScaledImage = null;
     303
     304        double getImageScaling(Image img, Point p0, Point p1) {
     305                int realWidth = img.getWidth(this);
     306                int realHeight = img.getHeight(this);
     307                if (realWidth == -1 || realHeight == -1) {
     308                        /*
     309                         * We need a good image against which to work. If
     310                         * the current one isn't loaded, then try the last one.
     311                         * Should be good enough. If we've never seen one, then
     312                         * guess.        
     313                         */
     314                        if (lastScaledImage != null) {
     315                                return getImageScaling(lastScaledImage, p0, p1);
     316                        }
     317                        realWidth = 256;
     318                        realHeight = 256;
     319                } else {
     320                        lastScaledImage = img;
     321                }
     322                /*
     323                 * If the zoom scale gets really, really off, these can get into
     324                 * the millions, so make this a double to prevent integer
     325                 * overflows.        
     326                 */
     327                double drawWidth = p1.x - p0.x;
     328                double drawHeight = p1.x - p0.x;
     329                // stem.out.println("drawWidth: " + drawWidth + " drawHeight: " +
     330                // drawHeight);
     331
     332                double drawArea = drawWidth * drawHeight;
    312333        double realArea = realWidth * realHeight;
    313334
     
    384405        for (int x = z12x0 - 1; x <= z12x1; x++) {
    385406            for (int y = z12y0 - 1; y <= z12y1; y++) {
    386                 SlippyMapKey key = new SlippyMapKey(currentZoomLevel, x, y);
     407                SlippyMapKey key = new SlippyMapKey(x, y, currentZoomLevel);
    387408                SlippyMapTile tile;
    388409                tile = tileStorage.get(key);
     
    532553        }
    533554
    534         SlippyMapKey key = new SlippyMapKey(currentZoomLevel, tilex, tiley);
     555        SlippyMapKey key = new SlippyMapKey(tilex, tiley, currentZoomLevel);
    535556        if (!key.valid) {
    536557            System.err.println("getTileForPixelpos("+px+","+py+") made invalid key");
     
    561582                new JSeparator(),
    562583                // color,
    563                 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
     584                new JMenuItem(new RenameLayerAction(this.getAssociatedFile(), this)),
    564585                new JSeparator(),
    565586                new JMenuItem(new LayerListPopup.InfoAction(this)) };
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapTile.java

    r14732 r16153  
    1717 * @author LuVar <lubomir.varga@freemap.sk>
    1818 * @author Dave Hansen <dave@sr71.net>
     19 * @author Dave Hansen <dave@linux.vnet.ibm.com>
    1920 *
    2021 */
     
    2223{
    2324    private Image  tileImage;
    24         long timestamp;
     25        private long timestamp;
    2526
    26     int x;
    27     int y;
    28     int z;
     27        private int x;
     28        private int y;
     29        private int z;
     30   
     31    private boolean imageDownloaded = false;
    2932
    3033    private String metadata;
     
    6568    }
    6669
     70    public Image getImageNoTimestamp() {
     71        return tileImage;
     72    }
     73   
    6774    public Image getImage()
    6875    {
     
    7178    }
    7279
     80    public int getZoom() {
     81        return z;
     82    }
     83   
    7384    public void dropImage()
    7485    {
     86                if(tileImage != null) {
     87                        tileImage.flush();
     88                }
    7589                tileImage = null;
    7690                //  This should work in theory but doesn't seem to actually
    7791                //  reduce the X server memory usage
    7892                //tileImage.flush();
     93    }
     94   
     95    public void markAsDownloaded() {
     96        imageDownloaded = true;
     97    }
     98   
     99    public boolean isDownloaded() {
     100        return imageDownloaded;
     101    }
     102   
     103    public void abortDownload() {
     104        if (imageDownloaded) {
     105                return;
     106        }
     107        dropImage();
    79108    }
    80109
Note: See TracChangeset for help on using the changeset viewer.