Changeset 1553 in osm for utils/josm/plugins/landsat


Ignore:
Timestamp:
2006-11-07T23:33:22+01:00 (18 years ago)
Author:
nick
Message:

Added ability to move landsat layer

Location:
utils/josm/plugins/landsat
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • utils/josm/plugins/landsat/src/landsat/DownloadLandsatTask.java

    r1477 r1553  
    1818        private JCheckBox checkBox = new JCheckBox(tr("Landsat background images"));
    1919
    20         public DownloadLandsatTask() {
     20        public DownloadLandsatTask(LandsatLayer landsatLayer) {
    2121                super(tr("Downloading data"));
    22                 landsatLayer = new LandsatLayer
    23                 ("http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&"+
    24                                 "layers=global_mosaic&styles=&srs=EPSG:4326&"+
    25                 "format=image/jpeg");
     22                this.landsatLayer = landsatLayer;
    2623        }
    2724
  • utils/josm/plugins/landsat/src/landsat/LandsatImage.java

    r1436 r1553  
    2121        Image theImage;
    2222        double grabbedScale;
    23         EastNorth topLeft;
     23        EastNorth topLeft, bottomRight;
     24        double dEast, dNorth;   
     25        double minLat,minLon,maxLat,maxLon;
    2426
    2527        public LandsatImage(String constURL)
     
    5658
    5759                topLeft = Main.proj.latlon2eastNorth(new LatLon(maxlat,minlon));
    58                 EastNorth bottomRight = Main.proj.latlon2eastNorth
     60                bottomRight = Main.proj.latlon2eastNorth
    5961                (new LatLon(minlat,maxlon));
    6062
     
    6769                        URL url =  doGetURL(p,p2,widthPx,heightPx);
    6870                        doGrab(url);
     71                        this.minLat=minlat;
     72                        this.minLon=minlon;
     73                        this.maxLat=maxlat;
     74                        this.maxLon=maxlon;
    6975                }
    7076                catch(MalformedURLException e)
     
    7278                        System.out.println("Illegal url. Error="+e);
    7379                }
    74                         }
     80        }
    7581
    7682        private URL getURL(NavigatableComponent nc) throws MalformedURLException
     
    103109        }
    104110
    105         public void paint(Graphics g,NavigatableComponent nc) /*,EastNorth bottomLeft,
    106                    int x1, int y1, int x2, int y2) */
     111        public void displace (double dEast, double dNorth)
     112        {
     113                this.dEast += dEast;   
     114                this.dNorth += dNorth; 
     115        }
     116
     117        public boolean contains(EastNorth eastNorth)
     118        {
     119                double e1 = topLeft.east()+dEast,
     120                           e2 = bottomRight.east()+dEast,
     121                           n1 = bottomRight.north()+dNorth,
     122                           n2 = topLeft.north()+dNorth;
     123
     124                boolean b =  eastNorth.east()>=e1 && eastNorth.east()<=e2 &&
     125                                eastNorth.north()>=n1 && eastNorth.north()<=n2;
     126                return b;
     127        }
     128
     129        public void paint(Graphics g,NavigatableComponent nc)
    107130        {
    108131                if(theImage!=null)
    109132                {
    110                         /*
    111                         System.out.println("x1="+x1+" y1="+y1+" x2="+x2+" y2="+y2+
    112                                                                 " img w="+theImage.getWidth(null) +
    113                                                                 " img h="+theImage.getHeight(null)) ;
    114                          */
    115133                        double zoomInFactor = grabbedScale / nc.getScale();
    116134
     
    119137                        // grabbed scale in EastNorth/pixel.
    120138
    121                         /*
    122                         double ix = (bottomLeft.east()-this.bottomLeft.east())/grabbedScale,
    123                                    iy = theImage.getHeight(null) -
    124                                  ((bottomLeft.north() - this.bottomLeft.north())/grabbedScale);
    125 
    126                         g.drawImage(theImage,x1,y1,x2,y2,(int)ix,(int)iy,
    127                                         (int)(ix+((x2-x1)/zoomInFactor)),
    128                                         (int)(iy+((y2-y1)/zoomInFactor)), null);
    129                          */
    130139                        int w = theImage.getWidth(null), h=theImage.getHeight(null);
    131                         Point p = nc.getPoint(topLeft);
    132                         /*
    133                         System.out.println("topleft: e=" + topLeft.east() + " n="+
    134                                                         topLeft.north());
    135                         System.out.println("Drawing at "+p.x+","+p.y);
    136                          */
    137                         g.drawImage(theImage,p.x,p.y,
    138                                         (int)(p.x+w*zoomInFactor),
    139                                         (int)(p.y+h*zoomInFactor),
     140                        EastNorth topLeftDisplaced  =
     141                                new EastNorth(topLeft.east()+dEast, topLeft.north()+dNorth);
     142                        Point displacement = Main.map.mapView.getPoint(topLeftDisplaced);
     143                        g.drawImage(theImage,displacement.x,displacement.y,
     144                                        (int)(displacement.x+w*zoomInFactor),
     145                                        (int)(displacement.y+h*zoomInFactor),
    140146                                        0,0,w,h,null);
    141147                }
    142148        }
     149
    143150}
  • utils/josm/plugins/landsat/src/landsat/LandsatLayer.java

    r1443 r1553  
    77import java.awt.Toolkit;
    88import java.io.IOException;
     9import java.util.ArrayList;
    910
    1011import javax.swing.Icon;
     
    2021import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    2122import org.openstreetmap.josm.gui.layer.Layer;
     23import org.openstreetmap.josm.data.coor.EastNorth;
    2224
    2325/**
     
    2931        private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(LandsatPlugin.class.getResource("/images/wms.png")));
    3032
    31         private final LandsatImage landsatImage;
     33        private final ArrayList<LandsatImage> landsatImages;
    3234
    3335        private final String url;
     
    4749
    4850                this.url = url;
    49                 landsatImage = new LandsatImage(url);
     51                //landsatImage = new LandsatImage(url);
     52                landsatImages = new ArrayList<LandsatImage>();
    5053        }
    5154
     
    5356        {
    5457                MapView mv = Main.map.mapView;
     58                LandsatImage landsatImage = new LandsatImage(url);
    5559                landsatImage.grab(mv);
     60                landsatImages.add(landsatImage);
    5661        }
    5762
     
    6065        {
    6166                MapView mv = Main.map.mapView;
     67                LandsatImage landsatImage = new LandsatImage(url);
    6268                landsatImage.grab(mv,minlat,minlon,maxlat,maxlon);
     69                landsatImages.add(landsatImage);
    6370        }
    6471
     
    7986
    8087        @Override public void paint(Graphics g, final MapView mv) {
    81                 landsatImage.paint(g,mv);
     88                for(LandsatImage landsatImage : landsatImages) {
     89                        landsatImage.paint(g,mv);
     90                }
    8291        }
    8392
     
    97106                                new JMenuItem(new LayerListPopup.InfoAction(this))};
    98107        }
     108
     109        public LandsatImage findImage(EastNorth eastNorth)
     110        {
     111                for(LandsatImage landsatImage : landsatImages) {
     112                        if (landsatImage.contains(eastNorth))  {
     113                                return landsatImage;
     114                        }
     115                }
     116                return null;
     117        }
    99118}
  • utils/josm/plugins/landsat/src/landsat/LandsatPlugin.java

    r1477 r1553  
    44import org.openstreetmap.josm.plugins.Plugin;
    55import org.openstreetmap.josm.gui.MapFrame;
     6import org.openstreetmap.josm.gui.IconToggleButton;
    67
    78// NW 151006 only add the landsat task when the map frame is initialised with
     
    1112
    1213        DownloadLandsatTask task;
     14        LandsatLayer landsatLayer;
     15        boolean addedAction;
    1316
    1417        public LandsatPlugin() {
    15                 task = new DownloadLandsatTask();
     18                landsatLayer = new LandsatLayer
     19                ("http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&"+
     20                                "layers=global_mosaic&styles=&srs=EPSG:4326&"+
     21                "format=image/jpeg");
     22                task = new DownloadLandsatTask(landsatLayer);
    1623                task.setEnabled(false);
    1724                Main.main.menu.download.downloadTasks.add(task);
     25
    1826        }
    1927
    2028        public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     29                if(!addedAction) {
     30                        Main.map.toolBarActions.addSeparator();
     31                        Main.map.toolBarActions.add(new IconToggleButton
     32                                                (new LandsatAdjustAction(Main.map)));
     33                        addedAction=true;
     34                }
    2135                if(oldFrame==null && newFrame!=null) {
    2236                        task.setEnabled(true);
Note: See TracChangeset for help on using the changeset viewer.