Changeset 23190 in osm for applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/FakeMapView.java
- Timestamp:
- 2010-09-15T18:54:18+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/FakeMapView.java
r21477 r23190 26 26 27 27 class fake_map_view extends MapView { 28 public ProjectionBounds view_bounds;29 public MapView parent;28 public ProjectionBounds view_bounds; 29 public MapView parent; 30 30 31 public Graphics2D graphics;32 public BufferedImage ground_image;33 public int ground_width = -1;34 public int ground_height = -1;35 public double scale;36 public double max_east_west;31 public Graphics2D graphics; 32 public BufferedImage ground_image; 33 public int ground_width = -1; 34 public int ground_height = -1; 35 public double scale; 36 public double max_east_west; 37 37 38 public fake_map_view(MapView parent, double scale) {39 super(null); //TODO MapView constructor contains registering listeners and other code, that probably shouldn't be called in fake map view40 this.parent = parent;41 this.scale = scale;38 public fake_map_view(MapView parent, double scale) { 39 super(null); //TODO MapView constructor contains registering listeners and other code, that probably shouldn't be called in fake map view 40 this.parent = parent; 41 this.scale = scale; 42 42 43 ProjectionBounds parent_bounds = parent.getProjectionBounds();44 max_east_west =45 parent_bounds.max.east() - parent_bounds.min.east();46 }43 ProjectionBounds parent_bounds = parent.getProjectionBounds(); 44 max_east_west = 45 parent_bounds.max.east() - parent_bounds.min.east(); 46 } 47 47 48 public void setProjectionBounds(ProjectionBounds bounds) {49 view_bounds = bounds;48 public void setProjectionBounds(ProjectionBounds bounds) { 49 view_bounds = bounds; 50 50 51 if (bounds.max.east() - bounds.min.east() > max_east_west) {52 max_east_west = bounds.max.east() - bounds.min.east();51 if (bounds.max.east() - bounds.min.east() > max_east_west) { 52 max_east_west = bounds.max.east() - bounds.min.east(); 53 53 54 /* We need to set the parent MapView's bounds (i.e.55 * zoom level) to the same as ours max possible56 * bounds to avoid WMSLayer thinking we're zoomed57 * out more than we are or it'll pop up an annoying58 * "requested area is too large" popup.59 */60 EastNorth parent_center = parent.getCenter();61 parent.zoomTo(new ProjectionBounds(62 new EastNorth(63 parent_center.east() -64 max_east_west / 2,65 parent_center.north()),66 new EastNorth(67 parent_center.east() +68 max_east_west / 2,69 parent_center.north())));54 /* We need to set the parent MapView's bounds (i.e. 55 * zoom level) to the same as ours max possible 56 * bounds to avoid WMSLayer thinking we're zoomed 57 * out more than we are or it'll pop up an annoying 58 * "requested area is too large" popup. 59 */ 60 EastNorth parent_center = parent.getCenter(); 61 parent.zoomTo(new ProjectionBounds( 62 new EastNorth( 63 parent_center.east() - 64 max_east_west / 2, 65 parent_center.north()), 66 new EastNorth( 67 parent_center.east() + 68 max_east_west / 2, 69 parent_center.north()))); 70 70 71 /* Request again because NavigatableContent adds72 * a border just to be sure.73 */74 ProjectionBounds new_bounds =75 parent.getProjectionBounds();76 max_east_west =77 new_bounds.max.east() - new_bounds.min.east();78 }71 /* Request again because NavigatableContent adds 72 * a border just to be sure. 73 */ 74 ProjectionBounds new_bounds = 75 parent.getProjectionBounds(); 76 max_east_west = 77 new_bounds.max.east() - new_bounds.min.east(); 78 } 79 79 80 Point vmin = getPoint(bounds.min);81 Point vmax = getPoint(bounds.max);82 int w = vmax.x + 1;83 int h = vmin.y + 1;80 Point vmin = getPoint(bounds.min); 81 Point vmax = getPoint(bounds.max); 82 int w = vmax.x + 1; 83 int h = vmin.y + 1; 84 84 85 if (w <= ground_width && h <= ground_height) {86 graphics.setClip(0, 0, w, h);87 return;88 }85 if (w <= ground_width && h <= ground_height) { 86 graphics.setClip(0, 0, w, h); 87 return; 88 } 89 89 90 if (w > ground_width)91 ground_width = w;92 if (h > ground_height)93 ground_height = h;90 if (w > ground_width) 91 ground_width = w; 92 if (h > ground_height) 93 ground_height = h; 94 94 95 ground_image = new BufferedImage(ground_width,96 ground_height,97 BufferedImage.TYPE_INT_RGB);98 graphics = ground_image.createGraphics();99 graphics.setClip(0, 0, w, h);100 }95 ground_image = new BufferedImage(ground_width, 96 ground_height, 97 BufferedImage.TYPE_INT_RGB); 98 graphics = ground_image.createGraphics(); 99 graphics.setClip(0, 0, w, h); 100 } 101 101 102 public ProjectionBounds getProjectionBounds() {103 return view_bounds;104 }102 public ProjectionBounds getProjectionBounds() { 103 return view_bounds; 104 } 105 105 106 public Point getPoint(EastNorth p) {107 double x = p.east() - view_bounds.min.east();108 double y = view_bounds.max.north() - p.north();109 x /= this.scale;110 y /= this.scale;106 public Point getPoint(EastNorth p) { 107 double x = p.east() - view_bounds.min.east(); 108 double y = view_bounds.max.north() - p.north(); 109 x /= this.scale; 110 y /= this.scale; 111 111 112 return new Point((int) x, (int) y);113 }112 return new Point((int) x, (int) y); 113 } 114 114 115 public EastNorth getEastNorth(int x, int y) {116 return new EastNorth(117 view_bounds.min.east() + x * this.scale,118 view_bounds.min.north() - y * this.scale);119 }115 public EastNorth getEastNorth(int x, int y) { 116 return new EastNorth( 117 view_bounds.min.east() + x * this.scale, 118 view_bounds.min.north() - y * this.scale); 119 } 120 120 121 public boolean isVisible(int x, int y) {122 return true;123 }121 public boolean isVisible(int x, int y) { 122 return true; 123 } 124 124 125 public Graphics getGraphics() {126 return graphics;127 }125 public Graphics getGraphics() { 126 return graphics; 127 } 128 128 129 public void repaint() {130 }129 public void repaint() { 130 } 131 131 }
Note:
See TracChangeset
for help on using the changeset viewer.
