Changeset 27924 in osm


Ignore:
Timestamp:
2012-02-23T00:20:31+01:00 (12 years ago)
Author:
clever
Message:

partialy using the index now

Location:
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java

    r27915 r27924  
    66import java.util.zip.ZipException;
    77import java.util.zip.ZipFile;
     8import java.util.regex.Pattern;
     9import java.util.regex.Matcher;
    810import org.openstreetmap.josm.Main;
    911import org.openstreetmap.josm.data.Bounds;
     
    2830        private ArrayList<CanVecTile> sub_tiles = new ArrayList<CanVecTile>();
    2931        private boolean sub_tiles_made = false;
     32
     33        private ArrayList<String> index;
     34        private int depth;
    3035       
    3136        int corda,cordc;
     
    4348                a = Integer.parseInt(parta);
    4449                c = Integer.parseInt(partc);
    45                 real_init(a,partb,c,partd,self);
    46         }
    47         public CanVecTile(int a,String b,int c,String d,canvec_helper self) {
    48                 real_init(a,b,c,d,self);
    49         }
    50         public void real_init(int a,String b,int c,String d,canvec_helper self) {
     50                real_init(a,partb,c,partd,self,new ArrayList<String>());
     51        }
     52        public CanVecTile(int a,String b,int c,String d,canvec_helper self,ArrayList<String> index) {
     53                real_init(a,b,c,d,self,index);
     54        }
     55        public void real_init(int a,String b,int c,String d,canvec_helper self, ArrayList<String> index) {
     56                this.index = index;
    5157                plugin_self = self;
    5258                corda = a;
     
    7278                                lat_span = 4;
    7379                                lon_span = 8;
     80                                depth = 1;
    7481                        } else {
    7582                                return;
     
    9299                        lat_span = lat_span / 4;
    93100                        lon_span = lon_span / 4;
     101                        depth = 2;
    94102                }
    95103
     
    102110                        lat_span = lat_span / 4;
    103111                        lon_span = lon_span / 4;
     112                        depth = 3;
    104113                }
    105114               
    106115                if (cordd != "") {
     116                        depth = 4;
    107117                        System.out.println("cordd: "+cordd);
    108118                        String foo[] = cordd.split("\\.");
     
    142152                else this.tileid = String.format("%03d%s%02d%s",corda,cordb,cordc,cordd);
    143153                valid = true;
    144                 System.out.println(this.tileid);
     154                debug("creating tileid: "+this.tileid);
    145155        }
    146156        public boolean isValid() { return valid; }
    147157        public String getTileId() {
    148158                return this.tileid;
     159        }
     160        private void debug(String line) {
     161                System.out.println(depth + "_" + tileid + ": " + line);
    149162        }
    150163        public boolean isVisible(Bounds view) {
     
    220233                switch (layer) {
    221234                case 1:
    222                         for (int i = 1; i < 17; i++) {
    223                                 char temp[] = { (char) (64 + i) };
    224                                 sub_tiles.add(new CanVecTile(corda,new String(temp),0,"",plugin_self));
    225                         }
     235                        ArrayList<String> buffer = new ArrayList<String>();
     236                        Pattern p = Pattern.compile("\\d\\d\\d([A-Z])(.*)");
     237                        String last_cell = "";
     238//                      for (int i = 1; i < 17; i++) {
     239                        for (int i = 0; i < index.size(); i++) {
     240                                debug(index.get(i));
     241                                Matcher m = p.matcher(index.get(i));
     242                                m.matches();
     243
     244                                String cell = m.group(1);
     245                                debug("a " + cell + last_cell);
     246                                if (cell.equals(last_cell)) {
     247                                        buffer.add(m.group(0));
     248                                } else if (last_cell == "") {
     249                                } else {
     250                                //char temp[] = { (char) (64 + i) };
     251                                        debug("b "+corda+" "+last_cell);
     252                                        debug(buffer.toString());
     253                                        sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer));
     254                                        buffer = new ArrayList<String>();
     255                                        buffer.add(m.group(0));
     256                                }
     257                                last_cell = cell;
     258                        }
     259                        debug("c "+corda+" "+last_cell);
     260                        debug(buffer.toString());
     261                        sub_tiles.add(new CanVecTile(corda,last_cell,0,"",plugin_self,buffer));
    226262                        break;
    227263                case 2:
    228264                        for (int i = 1; i < 17; i++) {
    229                                 sub_tiles.add(new CanVecTile(corda,cordb,i,"",plugin_self));
     265                                sub_tiles.add(new CanVecTile(corda,cordb,i,"",plugin_self,new ArrayList<String>())); // FIXME
    230266                        }
    231267                        break;
     
    236272                boolean show_sub_tiles = false;
    237273                if (!isVisible(bounds)) return;
    238                 if ((cordb != "") && (cordc > 0) && (cordd == "") && (bounds.getArea() < 0.5)) { // 022B01
     274                if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01
    239275                        downloadSelf();
    240                         System.out.println(sub_tile_ids.toString());
     276                        debug(sub_tile_ids.toString());
    241277                        show_sub_tiles = true;
    242                 } else if ((cordc == 0) && (bounds.getArea() < 20)) { // its a layer2 tile
     278                } else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile
    243279                        make_sub_tiles(2);
    244280                        show_sub_tiles = true;
    245                 } else if ((cordb == "") && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small
     281                } else if ((depth == 1) && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small
    246282                        // draw layer2 tiles for self
    247283                        make_sub_tiles(1);
  • applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java

    r27920 r27924  
    99import java.awt.Color;
    1010import java.awt.Toolkit;
     11import java.io.BufferedReader;
     12import java.io.InputStreamReader;
    1113import java.io.IOException;
    1214
     
    1719import org.openstreetmap.josm.data.Bounds;
    1820import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     21import org.openstreetmap.josm.io.MirroredInputStream;
    1922import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    2023import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    2225import java.util.ArrayList;
    2326import java.util.zip.ZipException;
     27import java.util.regex.Pattern;
     28import java.util.regex.Matcher;
    2429
    2530// most of the layout was copied from the openstreetbugs plugin to get things started
     
    3338                plugin_self = self;
    3439                this.setBackgroundLayer(true);
    35                 for (int i = 0; i < 119; i++) {
     40/*              for (int i = 0; i < 119; i++) {
    3641                        CanVecTile tile = new CanVecTile(i,"",0,"",plugin_self);
    3742                        if (tile.isValid()) tiles.add(tile);
     43                }*/
     44                layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png")));
     45                try {
     46                        long start = System.currentTimeMillis();
     47                        Pattern p = Pattern.compile("(\\d\\d\\d)([A-Z]\\d\\d).*");
     48                        MirroredInputStream index = new MirroredInputStream("http://ftp2.cits.rncan.gc.ca/osm/pub/ZippedOsm.txt");
     49                        BufferedReader br = new BufferedReader(new InputStreamReader(index));
     50                        String line;
     51                        int last_cell = -1;
     52                        ArrayList<String> list = new ArrayList<String>();
     53                        while ((line = br.readLine()) != null) {
     54                                Matcher m = p.matcher(line);
     55                                if (m.find()) {
     56                                        int cell = Integer.parseInt(m.group(1));
     57                                        if (cell == last_cell) {
     58                                                list.add(m.group(0));
     59                                        } else if (last_cell != -1) {
     60                                                CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
     61                                                if (tile.isValid()) tiles.add(tile);
     62                                                list = new ArrayList<String>();
     63                                                list.add(m.group(0));
     64                                        }
     65                                        last_cell = cell;
     66                                } else System.out.print("bad line '" + line + "'\n");
     67                        }
     68                        CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
     69                        if (tile.isValid()) tiles.add(tile);
     70
     71                        long end = System.currentTimeMillis();
     72                        System.out.println((end-start)+"ms spent");
     73                } catch (IOException e) {
     74                        System.out.println("exception getting index");
    3875                }
    39                 layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png")));
    4076        }
    4177        public Action[] getMenuEntries() {
     
    6096        public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    6197                long start = System.currentTimeMillis();
    62                 System.out.println("painting the area covered by "+bounds.toString());
     98                //System.out.println("painting the area covered by "+bounds.toString());
    6399                // loop over each canvec tile in the db and check bounds.intersects(Bounds)
    64100                g.setColor(Color.red);
     
    68104                }
    69105                long end = System.currentTimeMillis();
    70                 System.out.println((end-start)+"ms spent");
     106                //System.out.println((end-start)+"ms spent");
    71107        }
    72108        public void mouseExited(MouseEvent e) {}
Note: See TracChangeset for help on using the changeset viewer.