Ignore:
Timestamp:
2012-02-23T03:11:27+01:00 (12 years ago)
Author:
clever
Message:

it now has a max-zoom control, and defaults to a level that wont download zips

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

Legend:

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

    r27925 r27926  
    152152                else this.tileid = String.format("%03d%s%02d%s",corda,cordb,cordc,cordd);
    153153                valid = true;
    154                 debug(index.toString());
    155                 debug("creating tileid: "+this.tileid);
     154                //debug(index.toString());
     155                //debug("creating tileid: "+this.tileid);
    156156        }
    157157        public boolean isValid() { return valid; }
     
    257257                        break;
    258258                case 2:
    259                         debug("making layer2 tiles, index: "+index.toString());
    260259                        p = Pattern.compile("\\d\\d\\d[A-Z](\\d\\d).*");
    261260                        int last_cell2 = -1;
    262261                        for (int i = 0; i < index.size(); i++) {
    263                                 debug(index.get(i));
    264262                                Matcher m = p.matcher(index.get(i));
    265263                                m.matches();
     
    271269                                        buffer.add(m.group(0));
    272270                                } else {
    273                                         debug(buffer.toString());
    274                                         debug(""+last_cell2);
    275271                                        sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",plugin_self,buffer));
    276272                                        buffer = new ArrayList<String>();
     
    284280                sub_tiles_made = true;
    285281        }
    286         public void paint(Graphics2D g, MapView mv, Bounds bounds) {
     282        public void paint(Graphics2D g, MapView mv, Bounds bounds, int max_zoom) {
    287283                boolean show_sub_tiles = false;
    288284                if (!isVisible(bounds)) return;
    289285                if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01
    290                         downloadSelf();
    291                         debug(sub_tile_ids.toString());
     286                        if (max_zoom == 4) downloadSelf();
    292287                        show_sub_tiles = true;
    293288                } else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile
     
    298293                        make_sub_tiles(1);
    299294                        show_sub_tiles = true;
     295                }
     296                if (show_sub_tiles && (depth < max_zoom)) {
     297                        for (int i = 0; i < sub_tiles.size(); i++) {
     298                                CanVecTile tile = sub_tiles.get(i);
     299                                tile.paint(g,mv,bounds,max_zoom);
     300                        }
    300301                } else {
    301302                        Point corners[] = getCorners(mv);
     
    306307                        g.drawString(getTileId(),corners[0].x,corners[0].y);
    307308                }
    308                 if (show_sub_tiles) {
    309                         for (int i = 0; i < sub_tiles.size(); i++) {
    310                                 CanVecTile tile = sub_tiles.get(i);
    311                                 tile.paint(g,mv,bounds);
    312                         }
    313                 }
    314309        }
    315310}
  • applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecHelperAction.java

    r27920 r27926  
    22
    33import org.openstreetmap.josm.actions.JosmAction;
    4 import org.openstreetmap.josm.plugins.Plugin;
    54import org.openstreetmap.josm.Main;
    65
  • applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_helper.java

    r27920 r27926  
    1313        }
    1414        public void mapFrameInitialized(MapFrame old, MapFrame new1) {
    15                 System.out.println("mapFrame made!");
    1615                updateLayer();
    1716        }
  • applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java

    r27924 r27926  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44import org.openstreetmap.josm.gui.layer.Layer;
     5import java.awt.Component;
    56import java.awt.Graphics2D;
     7import java.awt.event.ActionEvent;
    68import java.awt.event.MouseEvent;
    79import java.awt.event.MouseListener;
     
    1315import java.io.IOException;
    1416
     17import javax.swing.AbstractAction;
    1518import javax.swing.Action;
    1619import javax.swing.Icon;
    1720import javax.swing.ImageIcon;
     21import javax.swing.JMenu;
     22import javax.swing.JMenuItem;
    1823import org.openstreetmap.josm.actions.RenameLayerAction;
    1924import org.openstreetmap.josm.data.Bounds;
     
    2732import java.util.regex.Pattern;
    2833import java.util.regex.Matcher;
     34import java.util.List;
    2935
    3036// most of the layout was copied from the openstreetbugs plugin to get things started
    3137public class canvec_layer extends Layer implements MouseListener {
    3238        private Icon layerIcon = null;
     39        private int max_zoom = 3;
    3340        canvec_helper plugin_self;
    3441        private ArrayList<CanVecTile> tiles = new ArrayList<CanVecTile>();
     
    8087                        LayerListDialog.getInstance().createDeleteLayerAction(),
    8188                        SeparatorLayerAction.INSTANCE,
    82                         new LayerListPopup.InfoAction(this)};
     89                        new LayerListPopup.InfoAction(this),
     90                        new MaxZoomAction(this)};
     91        }
     92        public class MaxZoomAction extends AbstractAction implements LayerAction {
     93                private canvec_layer parent;
     94                public MaxZoomAction(canvec_layer parent) {
     95                        this.parent = parent;
     96                }
     97                public void actionPerformed(ActionEvent e) {}
     98                public boolean supportLayers(List<Layer> layers) {
     99                        return false;
     100                }
     101                public Component createMenuComponent() {
     102                        JMenu max_zoom = new JMenu("max zoom");
     103                        max_zoom.add(new JMenuItem(new SetMaxZoom(parent,1)));
     104                        max_zoom.add(new JMenuItem(new SetMaxZoom(parent,2)));
     105                        max_zoom.add(new JMenuItem(new SetMaxZoom(parent,3)));
     106                        max_zoom.add(new JMenuItem(new SetMaxZoom(parent,4)));
     107                        return max_zoom;
     108                }
     109        }
     110        public void setMaxZoom(int max_zoom) {
     111                this.max_zoom = max_zoom;
    83112        }
    84113        public Object getInfoComponent() {
     
    101130                for (int i = 0; i < tiles.size(); i++) {
    102131                        CanVecTile tile = tiles.get(i);
    103                         tile.paint(g,mv,bounds);
     132                        tile.paint(g,mv,bounds,max_zoom);
    104133                }
    105134                long end = System.currentTimeMillis();
Note: See TracChangeset for help on using the changeset viewer.