source: josm/src/org/openstreetmap/josm/gui/layer/WmsServerLayer.java@ 104

Last change on this file since 104 was 104, checked in by imi, 18 years ago
  • started i18n
  • started "download incomplete ways" action
  • added straight line selection mode
File size: 3.6 KB
Line 
1package org.openstreetmap.josm.gui.layer;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.Component;
6import java.awt.Graphics;
7import java.awt.Image;
8import java.awt.Point;
9
10import javax.swing.Icon;
11import javax.swing.JMenuItem;
12import javax.swing.JSeparator;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.coor.EastNorth;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
18import org.openstreetmap.josm.data.projection.Projection;
19import org.openstreetmap.josm.gui.MapView;
20import org.openstreetmap.josm.gui.dialogs.LayerList;
21import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
22import org.openstreetmap.josm.tools.ImageProvider;
23import org.openstreetmap.josm.tools.TileCache;
24
25/**
26 * This is a layer that grabs the current screen from an WMS server. The data
27 * fetched this way is tiled and cached to the disc to reduce server load.
28 */
29public class WmsServerLayer extends Layer {
30
31 private static Icon icon = ImageProvider.get("layer/wms");
32
33 private final TileCache cache;
34
35 private final String url;
36
37
38 public WmsServerLayer(String url) {
39 super(url.indexOf('/') != -1 ? url.substring(url.indexOf('/')+1) : url);
40
41 // to calculate the world dimension, we assume that the projection does
42 // not have problems with translating longitude to a correct scale.
43 // Next to that, the projection must be linear dependend on the lat/lon
44 // unprojected scale.
45 if (Projection.MAX_LON != 180)
46 throw new IllegalArgumentException(tr("Wrong longitude transformation for tile cache. Can't operate on {0}",Main.proj));
47
48 this.url = url;
49 cache = new TileCache(url);
50 }
51
52 @Override public Icon getIcon() {
53 return icon;
54 }
55
56 @Override public String getToolTipText() {
57 return tr("WMS layer: {0}", url);
58 }
59
60 @Override public boolean isMergable(Layer other) {
61 return false;
62 }
63
64 @Override public void mergeFrom(Layer from) {
65 }
66
67 @Override public void paint(Graphics g, final MapView mv) {
68// EastNorth max = mv.getEastNorth(mv.getWidth(),0);
69// EastNorth min = mv.getEastNorth(0,mv.getHeight());
70// double width = max.east() - min.east();
71// double height = max.north() - min.north();
72// double tilesX = mv.getWidth() / TileCache.TILESIZE;
73// double tilesY = mv.getHeight() / TileCache.TILESIZE;
74
75 // getting zoom level
76 int zoom = 0;
77 for (double w = mv.getScale(); w <= TileCache.worldDimension; w *= 2)
78 zoom++;
79 LatLon oneTile = Main.proj.eastNorth2latlon(new EastNorth(
80 TileCache.TILESIZE * mv.getScale(),
81 TileCache.TILESIZE * mv.getScale()));
82 if (oneTile.lat() > Projection.MAX_LAT || oneTile.lon() > Projection.MAX_LON) {
83 // just display the whole world
84 Image img = cache.get(0,0);
85 Point scr1 = mv.getPoint(Main.proj.latlon2eastNorth(new LatLon(Projection.MAX_LAT, -Projection.MAX_LON)));
86 Point scr2 = mv.getPoint(Main.proj.latlon2eastNorth(new LatLon(-Projection.MAX_LAT, Projection.MAX_LON)));
87 g.drawImage(img, scr1.x, scr1.y, scr2.x, scr2.y, 0, 0, TileCache.TILESIZE, TileCache.TILESIZE, null);
88 }
89
90// TileCache.TileInformation info = TileCache.pos2tile(min, zoom);
91 //System.out.println(url+"bbox="+info.min.lon()+","+info.min.lat()+","+info.max.lon()+","+info.max.lat());
92 }
93
94 @Override public void visitBoundingBox(BoundingXYVisitor v) {
95 // doesn't have a bounding box
96 }
97
98 @Override public Object getInfoComponent() {
99 return getToolTipText();
100 }
101
102 @Override public Component[] getMenuEntries() {
103 return new Component[]{
104 new JMenuItem(new LayerList.ShowHideLayerAction(this)),
105 new JMenuItem(new LayerList.DeleteLayerAction(this)),
106 new JSeparator(),
107 new JMenuItem(new LayerListPopup.InfoAction(this))};
108 }
109}
Note: See TracBrowser for help on using the repository browser.