Ignore:
Timestamp:
2011-01-12T23:33:13+01:00 (15 years ago)
Author:
pieren
Message:

change the way we grab the small squares with a spiral algorithm to visualize the first square in the middle of the screen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r24955 r25033  
    108108        // if the layer is currently saving the images in the cache, wait until it's finished
    109109        grabThread.cancel();
     110        grabThread = null;
    110111        super.destroy();
    111112        images = null;
     
    141142                divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())));
    142143        }
    143 
    144144        grabThread.addImages(dividedBbox);
    145         Main.map.repaint();
    146     }
    147 
    148     /**
    149      * Divides the bounding box in smaller polygons.
     145    }
     146
     147    /**
     148     * Divides the bounding box in smaller squares. Their size (and quantity) is configurable in Preferences.
    150149     *
    151150     * @param b      the original bbox, usually the current bbox on screen
     
    172171        } else {
    173172            // divide to fixed size squares
    174             int cSquare = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100"));
    175             minEast = minEast - minEast % cSquare;
    176             minNorth = minNorth - minNorth % cSquare;
    177             for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare)
    178                 for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) {
    179                     dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth),
    180                                 new EastNorth(xEast + cSquare, xNorth + cSquare)));
    181             }
     173            // grab all square in a spiral starting from the center (usually the most interesting place)
     174            int c = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100"));
     175            lambertMin = lambertMin.add(- minEast%c, - minNorth%c);
     176            lambertMax = lambertMax.add(c - lambertMax.east()%c, c - lambertMax.north()%c);
     177            EastNorth mid = lambertMax.getCenter(lambertMin);
     178            mid = mid.add(-1, 1); // in case the boxes side is a pair, select the one one top,left to follow the rotation
     179            mid = mid.add(- mid.east()%c, - mid.north()%c);
     180            int x = (int)(lambertMax.east() - lambertMin.east())/100;
     181            int y = (int)(lambertMax.north() - lambertMin.north())/100;
     182            int dx[] = {+1, 0,-1, 0};
     183            int dy[] = {0,-1, 0,+1};
     184            int currDir = -1, lDir = 1, i = 1, j = 0, k = -1;
     185            if (x == 1)
     186                currDir = 0;
     187            dividedBbox.add(new EastNorthBound(mid, new EastNorth(mid.east()+c, mid.north()+c)));
     188            while (i < (x*y)) {
     189                i++;
     190                j++;
     191                if (j >= lDir) {
     192                    k++;
     193                    if (k > 1) {
     194                        lDir++;
     195                        k = 0;
     196                    }
     197                    j = 0;
     198                    currDir = (currDir+1)%4;
     199                } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? x-1 : y-1)) {
     200                    // the overall is a rectangle, not a square. Jump to the other side to grab next square.
     201                    k++;
     202                    if (k > 1) {
     203                        lDir++;
     204                        k = 0;
     205                    }
     206                    j = lDir-1;
     207                    currDir = (currDir+1)%4;
     208                    mid = new EastNorth(mid.east() + dx[currDir]*c*(lDir-1), mid.north() + dy[currDir]*c*(lDir-1));
     209                }
     210                mid = new EastNorth(mid.east() + dx[currDir]*c, mid.north() + dy[currDir]*c);
     211                dividedBbox.add(new EastNorthBound(mid, new EastNorth(mid.east()+c, mid.north()+c)));
     212            }
     213//            // simple algorithm to grab all squares
     214//            minEast = minEast - minEast % cSquare;
     215//            minNorth = minNorth - minNorth % cSquare;
     216//            for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare)
     217//                for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) {
     218//                    dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth),
     219//                                new EastNorth(xEast + cSquare, xNorth + cSquare)));
     220//            }
    182221        }
    183222    }
     
    231270            paintCrosspieces(g, mv);
    232271        }
    233         //        if (grabThread.getImagesToGrabSize() > 0) {
    234             grabThread.paintBoxesToGrab(g, mv);
    235             //        }
     272        grabThread.paintBoxesToGrab(g, mv);
    236273        if (this.adjustModeEnabled) {
    237274            WMSAdjustAction.paintAdjustFrames(g, mv);
     
    379416     */
    380417    public void write(ObjectOutputStream oos) throws IOException {
    381         // Set currentFormat to the serializeFormatVersion
    382418        currentFormat = this.serializeFormatVersion;
    383419        oos.writeInt(this.serializeFormatVersion);
Note: See TracChangeset for help on using the changeset viewer.