source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java@ 19267

Last change on this file since 19267 was 19267, checked in by pieren, 15 years ago

Several minor improvements.

  • Property svn:eol-style set to native
File size: 24.6 KB
Line 
1// License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
2package cadastre_fr;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7import java.awt.Component;
8import java.awt.Graphics;
9import java.awt.Graphics2D;
10import java.awt.Image;
11import java.awt.Point;
12import java.awt.Toolkit;
13import java.awt.image.BufferedImage;
14import java.awt.image.ImageObserver;
15import java.io.EOFException;
16import java.io.IOException;
17import java.io.ObjectInputStream;
18import java.io.ObjectOutputStream;
19import java.util.ArrayList;
20import java.util.Vector;
21
22import javax.swing.Icon;
23import javax.swing.ImageIcon;
24import javax.swing.JMenuItem;
25import javax.swing.JOptionPane;
26
27import org.openstreetmap.josm.Main;
28import org.openstreetmap.josm.data.Bounds;
29import org.openstreetmap.josm.data.coor.EastNorth;
30import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
31import org.openstreetmap.josm.gui.MapView;
32import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
33import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
34import org.openstreetmap.josm.gui.layer.Layer;
35import org.openstreetmap.josm.io.OsmTransferException;
36
37/**
38 * This is a layer that grabs the current screen from the French cadastre WMS
39 * server. The data fetched this way is tiled and managed to the disc to reduce
40 * server load.
41 */
42public class WMSLayer extends Layer implements ImageObserver {
43
44 Component[] component = null;
45
46 private int lambertZone = -1;
47
48 protected static final Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(
49 CadastrePlugin.class.getResource("/images/cadastre_small.png")));
50
51 protected Vector<GeorefImage> images = new Vector<GeorefImage>();
52
53 protected final int serializeFormatVersion = 2;
54
55 private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>();
56
57 private CacheControl cacheControl = null;
58
59 private String location = "";
60
61 private String codeCommune = "";
62
63 public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0));
64
65 private boolean isRaster = false;
66
67 private boolean isAlreadyGeoreferenced = false;
68
69 public double X0, Y0, angle, fX, fY;
70
71 private EastNorth rasterMin;
72 private EastNorth rasterMax;
73 private double rasterRatio;
74
75 private JMenuItem saveAsPng;
76
77 public WMSLayer() {
78 this(tr("Blank Layer"), "", -1);
79 }
80
81 public WMSLayer(String location, String codeCommune, int lambertZone) {
82 super(buildName(location, codeCommune));
83 this.location = location;
84 this.codeCommune = codeCommune;
85 this.lambertZone = lambertZone;
86 // enable auto-sourcing option
87 CadastrePlugin.pluginUsed = true;
88 }
89
90 public void destroy() {
91 super.destroy();
92 images = null;
93 dividedBbox = null;
94 System.out.println("Layer "+location+" destroyed");
95 }
96
97 private static String buildName(String location, String codeCommune) {
98 String ret = new String(location.toUpperCase());
99 if (codeCommune != null && !codeCommune.equals(""))
100 ret += "(" + codeCommune + ")";
101 return ret;
102 }
103
104 private String rebuildName() {
105 return buildName(this.location.toUpperCase(), this.codeCommune);
106 }
107
108 public void grab(CadastreGrabber grabber, Bounds b) throws IOException {
109 grab(grabber, b, true);
110 }
111
112 public void grab(CadastreGrabber grabber, Bounds b, boolean useFactor) throws IOException {
113 if (useFactor) {
114 if (isRaster) {
115 b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax));
116 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider",
117 CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)));
118 } else
119 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())));
120 } else
121 divideBbox(b, 1);
122
123 for (EastNorthBound n : dividedBbox) {
124 GeorefImage newImage;
125 try {
126 newImage = grabber.grab(this, n.min, n.max);
127 } catch (IOException e) {
128 System.out.println("Download action cancelled by user or server did not respond");
129 break;
130 } catch (OsmTransferException e) {
131 System.out.println("OSM transfer failed");
132 break;
133 }
134 if (grabber.getWmsInterface().downloadCancelled) {
135 System.out.println("Download action cancelled by user");
136 break;
137 }
138 if (CadastrePlugin.backgroundTransparent) {
139 for (GeorefImage img : images) {
140 if (img.overlap(newImage))
141 // mask overlapping zone in already grabbed image
142 img.withdraw(newImage);
143 else
144 // mask overlapping zone in new image only when new
145 // image covers completely the existing image
146 newImage.withdraw(img);
147 }
148 }
149 images.add(newImage);
150 saveToCache(newImage);
151 Main.map.mapView.repaint();
152 }
153 }
154
155 /**
156 *
157 * @param b the original bbox, usually the current bbox on screen
158 * @param factor 1 = source bbox 1:1
159 * 2 = source bbox divided by 2x2 smaller boxes
160 * 3 = source bbox divided by 3x3 smaller boxes
161 * 4 = hard coded size of boxes (100 meters) rounded allowing
162 * grabbing of next contiguous zone
163 */
164 private void divideBbox(Bounds b, int factor) {
165 EastNorth lambertMin = Main.proj.latlon2eastNorth(b.getMin());
166 EastNorth lambertMax = Main.proj.latlon2eastNorth(b.getMax());
167 double minEast = lambertMin.east();
168 double minNorth = lambertMin.north();
169 double dEast = (lambertMax.east() - minEast) / factor;
170 double dNorth = (lambertMax.north() - minNorth) / factor;
171 dividedBbox.clear();
172 if (factor < 4 || isRaster) {
173 for (int xEast = 0; xEast < factor; xEast++)
174 for (int xNorth = 0; xNorth < factor; xNorth++) {
175 dividedBbox.add(new EastNorthBound(new EastNorth(minEast + xEast * dEast, minNorth + xNorth * dNorth),
176 new EastNorth(minEast + (xEast + 1) * dEast, minNorth + (xNorth + 1) * dNorth)));
177 }
178 } else {
179 // divide to fixed size squares
180 int cSquare = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100"));
181 minEast = minEast - minEast % cSquare;
182 minNorth = minNorth - minNorth % cSquare;
183 for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare)
184 for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) {
185 dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth),
186 new EastNorth(xEast + cSquare, xNorth + cSquare)));
187 }
188 }
189 }
190
191 @Override
192 public Icon getIcon() {
193 return icon;
194 }
195
196 @Override
197 public String getToolTipText() {
198 String str = tr("WMS layer ({0}), {1} tile(s) loaded", getName(), images.size());
199 if (isRaster) {
200 str += "\n"+tr("Is not vectorized.");
201 str += "\n"+tr("Raster size: {0}", communeBBox);
202 } else
203 str += "\n"+tr("Is vectorized.");
204 str += "\n"+tr("Commune bbox: {0}", communeBBox);
205 return str;
206 }
207
208 @Override
209 public boolean isMergable(Layer other) {
210 return false;
211 }
212
213 @Override
214 public void mergeFrom(Layer from) {
215 }
216
217 @Override
218 public void paint(Graphics2D g, final MapView mv, Bounds bounds) {
219 synchronized(this){
220 for (GeorefImage img : images)
221 img.paint(g, mv, CadastrePlugin.backgroundTransparent,
222 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries);
223 }
224 if (this.isRaster) {
225 paintCrosspieces(g, mv);
226 }
227 }
228
229 @Override
230 public void visitBoundingBox(BoundingXYVisitor v) {
231 for (GeorefImage img : images) {
232 v.visit(img.min);
233 v.visit(img.max);
234 }
235 }
236
237 @Override
238 public Object getInfoComponent() {
239 return getToolTipText();
240 }
241
242 @Override
243 public Component[] getMenuEntries() {
244 saveAsPng = new JMenuItem(new MenuActionSaveRasterAs(this));
245 saveAsPng.setEnabled(isRaster);
246 component = new Component[] { new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
247 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
248 new JMenuItem(new MenuActionLoadFromCache()),
249 saveAsPng,
250 new JMenuItem(new LayerListPopup.InfoAction(this)),
251
252 };
253 return component;
254 }
255
256 public GeorefImage findImage(EastNorth eastNorth) {
257 // Iterate in reverse, so we return the image which is painted last.
258 // (i.e. the topmost one)
259 for (int i = images.size() - 1; i >= 0; i--) {
260 if (images.get(i).contains(eastNorth)) {
261 return images.get(i);
262 }
263 }
264 return null;
265 }
266
267 public boolean isOverlapping(Bounds bounds) {
268 GeorefImage georefImage =
269 new GeorefImage(new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB ), // not really important
270 Main.proj.latlon2eastNorth(bounds.getMin()),
271 Main.proj.latlon2eastNorth(bounds.getMax()));
272 for (GeorefImage img : images) {
273 if (img.overlap(georefImage))
274 return true;
275 }
276 return false;
277 }
278
279 public void saveToCache(GeorefImage image) {
280 if (CacheControl.cacheEnabled && !isRaster()) {
281 getCacheControl().saveCache(image);
282 }
283 }
284
285 public void saveNewCache() {
286 if (CacheControl.cacheEnabled) {
287 getCacheControl().deleteCacheFile();
288 for (GeorefImage image : images)
289 getCacheControl().saveCache(image);
290 }
291 }
292
293 public CacheControl getCacheControl() {
294 if (cacheControl == null)
295 cacheControl = new CacheControl(this);
296 return cacheControl;
297 }
298
299 /**
300 * Convert the eastNorth input coordinates to raster coordinates.
301 * The original raster size is [0,0,12286,8730] where 0,0 is the upper left corner and
302 * 12286,8730 is the approx. raster max size.
303 * @return the raster coordinates for the wms server request URL (minX,minY,maxX,maxY)
304 */
305 public String eastNorth2raster(EastNorth min, EastNorth max) {
306 double minX = (min.east() - rasterMin.east()) / rasterRatio;
307 double minY = (min.north() - rasterMin.north()) / rasterRatio;
308 double maxX = (max.east() - rasterMin.east()) / rasterRatio;
309 double maxY = (max.north() - rasterMin.north()) / rasterRatio;
310 return minX+","+minY+","+maxX+","+maxY;
311 }
312
313
314 public String getLocation() {
315 return location;
316 }
317
318 public void setLocation(String location) {
319 this.location = location;
320 setName(rebuildName());
321 }
322
323 public String getCodeCommune() {
324 return codeCommune;
325 }
326
327 public void setCodeCommune(String codeCommune) {
328 this.codeCommune = codeCommune;
329 setName(rebuildName());
330 }
331
332 public boolean isRaster() {
333 return isRaster;
334 }
335
336 public void setRaster(boolean isRaster) {
337 this.isRaster = isRaster;
338 if (saveAsPng != null)
339 saveAsPng.setEnabled(isRaster);
340 }
341
342 public boolean isAlreadyGeoreferenced() {
343 return isAlreadyGeoreferenced;
344 }
345
346 public void setAlreadyGeoreferenced(boolean isAlreadyGeoreferenced) {
347 this.isAlreadyGeoreferenced = isAlreadyGeoreferenced;
348 }
349
350 /**
351 * Set raster positions used for grabbing and georeferencing.
352 * rasterMin is the Eaast North of bottom left corner raster image on the screen when image is grabbed.
353 * The bounds width and height are the raster width and height. The image width matches the current view
354 * and the image height is adapted.
355 * Required: the communeBBox must be set (normally it is catched by CadastreInterface and saved by DownloadWMSPlanImage)
356 * @param bounds the current main map view boundaries
357 */
358 public void setRasterBounds(Bounds bounds) {
359 EastNorth rasterCenter = Main.proj.latlon2eastNorth(bounds.getCenter());
360 EastNorth eaMin = Main.proj.latlon2eastNorth(bounds.getMin());
361 EastNorth eaMax = Main.proj.latlon2eastNorth(bounds.getMax());
362 double rasterSizeX = communeBBox.max.getX() - communeBBox.min.getX();
363 double rasterSizeY = communeBBox.max.getY() - communeBBox.min.getY();
364 double ratio = rasterSizeY/rasterSizeX;
365 // keep same ratio on screen as WMS bbox (stored in communeBBox)
366 rasterMin = new EastNorth(eaMin.getX(), rasterCenter.getY()-(eaMax.getX()-eaMin.getX())*ratio/2);
367 rasterMax = new EastNorth(eaMax.getX(), rasterCenter.getY()+(eaMax.getX()-eaMin.getX())*ratio/2);
368 rasterRatio = (rasterMax.getX()-rasterMin.getX())/rasterSizeX;
369 }
370
371 /**
372 * Called by CacheControl when a new cache file is created on disk.
373 * Save only primitives to keep cache independent of software changes.
374 * @param oos
375 * @throws IOException
376 */
377 public void write(ObjectOutputStream oos) throws IOException {
378 oos.writeInt(this.serializeFormatVersion);
379 oos.writeObject(this.location); // String
380 oos.writeObject(this.codeCommune); // String
381 oos.writeInt(this.lambertZone);
382 oos.writeBoolean(this.isRaster);
383 if (this.isRaster) {
384 oos.writeDouble(this.rasterMin.getX());
385 oos.writeDouble(this.rasterMin.getY());
386 oos.writeDouble(this.rasterMax.getX());
387 oos.writeDouble(this.rasterMax.getY());
388 oos.writeDouble(this.rasterRatio);
389 }
390 oos.writeDouble(this.communeBBox.min.getX());
391 oos.writeDouble(this.communeBBox.min.getY());
392 oos.writeDouble(this.communeBBox.max.getX());
393 oos.writeDouble(this.communeBBox.max.getY());
394 }
395
396 /**
397 * Called by CacheControl when a cache file is read from disk.
398 * Cache uses only primitives to stay independent of software changes.
399 * @param ois
400 * @throws IOException
401 * @throws ClassNotFoundException
402 */
403 public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException {
404 int sfv = ois.readInt();
405 if (sfv != this.serializeFormatVersion) {
406 JOptionPane.showMessageDialog(Main.parent, tr("Unsupported cache file version; found {0}, expected {1}\nCreate a new one.",
407 sfv, this.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE);
408 return false;
409 }
410 this.setLocation((String) ois.readObject());
411 this.setCodeCommune((String) ois.readObject());
412 this.lambertZone = ois.readInt();
413 this.setRaster(ois.readBoolean());
414 if (this.isRaster) {
415 double X = ois.readDouble();
416 double Y = ois.readDouble();
417 this.rasterMin = new EastNorth(X, Y);
418 X = ois.readDouble();
419 Y = ois.readDouble();
420 this.rasterMax = new EastNorth(X, Y);
421 this.rasterRatio = ois.readDouble();
422 }
423 double minX = ois.readDouble();
424 double minY = ois.readDouble();
425 double maxX = ois.readDouble();
426 double maxY = ois.readDouble();
427 this.communeBBox = new EastNorthBound(new EastNorth(minX, minY), new EastNorth(maxX, maxY));
428 if (this.lambertZone != currentLambertZone && currentLambertZone != -1) {
429 JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+
430 "incompatible with current Lambert zone {1}",
431 this.lambertZone+1, currentLambertZone), tr("Cache Lambert Zone Error"), JOptionPane.ERROR_MESSAGE);
432 return false;
433 }
434 synchronized(this){
435 boolean EOF = false;
436 try {
437 while (!EOF) {
438 GeorefImage newImage = (GeorefImage) ois.readObject();
439 for (GeorefImage img : this.images) {
440 if (CadastrePlugin.backgroundTransparent) {
441 if (img.overlap(newImage))
442 // mask overlapping zone in already grabbed image
443 img.withdraw(newImage);
444 else
445 // mask overlapping zone in new image only when
446 // new image covers completely the existing image
447 newImage.withdraw(img);
448 }
449 }
450 this.images.add(newImage);
451 }
452 } catch (EOFException ex) {
453 // expected exception when all images are read
454 }
455 }
456 System.out.println("Cache loaded for location "+location+" with "+images.size()+" images");
457 return true;
458 }
459
460 /**
461 * Join the grabbed images into one single.
462 * Works only for images grabbed from non-georeferenced images (Feuilles cadastrales)(same amount of
463 * images in x and y)
464 */
465 public void joinRasterImages() {
466 if (images.size() > 1) {
467 EastNorth min = images.get(0).min;
468 EastNorth max = images.get(images.size()-1).max;
469 int oldImgWidth = images.get(0).image.getWidth();
470 int oldImgHeight = images.get(0).image.getHeight();
471 int newWidth = oldImgWidth*(int)Math.sqrt(images.size());
472 int newHeight = oldImgHeight*(int)Math.sqrt(images.size());
473 BufferedImage new_img = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
474 Graphics g = new_img.getGraphics();
475 // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left
476 int rasterDivider = (int)Math.sqrt(images.size());
477 for (int h = 0; h < rasterDivider; h++) {
478 for (int v = 0; v < rasterDivider; v++) {
479 int newx = h*oldImgWidth;
480 int newy = newHeight - oldImgHeight - (v*oldImgHeight);
481 int j = h*rasterDivider + v;
482 g.drawImage(images.get(j).image, newx, newy, this);
483 }
484 }
485 synchronized(this) {
486 images.clear();
487 images.add(new GeorefImage(new_img, min, max));
488 }
489 }
490 }
491
492 /**
493 * Image cropping based on two EN coordinates pointing to two corners in diagonal
494 * Because it's coming from user mouse clics, we have to sort de positions first.
495 * Works only for raster image layer (only one image in collection).
496 * Updates layer georeferences.
497 * @param en1
498 * @param en2
499 */
500 public void cropImage(EastNorth en1, EastNorth en2){
501 // adj1 is corner bottom, left
502 EastNorth adj1 = new EastNorth(en1.east() <= en2.east() ? en1.east() : en2.east(),
503 en1.north() <= en2.north() ? en1.north() : en2.north());
504 // adj2 is corner top, right
505 EastNorth adj2 = new EastNorth(en1.east() > en2.east() ? en1.east() : en2.east(),
506 en1.north() > en2.north() ? en1.north() : en2.north());
507 // s1 and s2 have 0,0 at top, left where all EastNorth coord. have 0,0 at bottom, left
508 int sx1 = (int)((adj1.getX() - images.get(0).min.getX())*images.get(0).getPixelPerEast());
509 int sy1 = (int)((images.get(0).max.getY() - adj2.getY())*images.get(0).getPixelPerNorth());
510 int sx2 = (int)((adj2.getX() - images.get(0).min.getX())*images.get(0).getPixelPerEast());
511 int sy2 = (int)((images.get(0).max.getY() - adj1.getY())*images.get(0).getPixelPerNorth());
512 int newWidth = Math.abs(sx2 - sx1);
513 int newHeight = Math.abs(sy2 - sy1);
514 BufferedImage new_img = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
515 Graphics g = new_img.getGraphics();
516 g.drawImage(images.get(0).image, 0, 0, newWidth-1, newHeight-1,
517 sx1, sy1, sx2, sy2,
518 this);
519 images.set(0, new GeorefImage(new_img, adj1, adj2));
520 // important: update the layer georefs !
521 rasterMin = adj1;
522 rasterMax = adj2;
523 rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX());
524 setCommuneBBox(new EastNorthBound(new EastNorth(0,0), new EastNorth(newWidth-1,newHeight-1)));
525 }
526
527 public EastNorthBound getCommuneBBox() {
528 return communeBBox;
529 }
530
531 public void setCommuneBBox(EastNorthBound entireCommune) {
532 this.communeBBox = entireCommune;
533// if (Main.proj instanceof LambertCC9Zones)
534// setLambertCC9Zone(communeBBox.min.north());
535 }
536
537 /**
538 * Method required by ImageObserver when drawing an image
539 */
540 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
541 return false;
542 }
543
544 public int getLambertZone() {
545 return lambertZone;
546 }
547
548// public void setLambertCC9Zone(double north) {
549// int lambertZone = LambertCC9Zones.north2ZoneNumber(north);
550// this.lambertZone = lambertZone;
551// if (((LambertCC9Zones)Main.proj).getLayoutZone() != lambertZone) {
552// String currentZone = MenuActionLambertZone.lambert9zones[((LambertCC9Zones)Main.proj).getLayoutZone()+1];
553// String destZone = MenuActionLambertZone.lambert9zones[lambertZone+1];
554// if (Main.map.mapView.getAllLayers().size() == 1) {
555// /* Enable this code below when JOSM will have a proper support of dynamic projection change
556// *
557// System.out.println("close all layers and change current Lambert zone from "+LambertCC9Zones.layoutZone+" to "+lambertZone);
558// Bounds b = null;
559// if (Main.map != null && Main.map.mapView != null)
560// b = Main.map.mapView.getRealBounds();
561// LambertCC9Zones.layoutZone = lambertZone;
562// Main.map.mapView.zoomTo(b);
563// */
564// } else {
565// JOptionPane.showMessageDialog(Main.parent, tr("Current layer is in Lambert CC9 Zone \"{0}\"\n"+
566// "where the commune is in Lambert CC9 Zone \"{1}\".\n"+
567// "Upload your changes, close all layers and change\n"+
568// "manually the Lambert zone from the Cadastre menu"
569// , currentZone, destZone));
570// }
571// }
572// }
573
574 public EastNorth getRasterCenter() {
575 return new EastNorth((images.get(0).max.east()+images.get(0).min.east())/2,
576 (images.get(0).max.north()+images.get(0).min.north())/2);
577 }
578
579 public void displace(double dx, double dy) {
580 this.rasterMin = new EastNorth(rasterMin.east() + dx, rasterMin.north() + dy);
581 images.get(0).shear(dx, dy);
582 }
583
584 public void resize(EastNorth rasterCenter, double proportion) {
585 this.rasterMin = rasterMin.interpolate(rasterCenter, proportion);
586 images.get(0).scale(rasterCenter, proportion);
587 }
588
589 public void rotate(EastNorth rasterCenter, double angle) {
590 this.rasterMin = rasterMin.rotate(rasterCenter, angle);
591 images.get(0).rotate(rasterCenter, angle);
592 }
593
594 private void paintCrosspieces(Graphics g, MapView mv) {
595 String crosspieces = Main.pref.get("cadastrewms.crosspieces", "0");
596 if (!crosspieces.equals("0")) {
597 int modulo = 25;
598 if (crosspieces.equals("2")) modulo = 50;
599 if (crosspieces.equals("3")) modulo = 100;
600 EastNorthBound currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()),
601 mv.getEastNorth(mv.getWidth(), 0));
602 int minX = ((int)currentView.min.east()/modulo+1)*modulo;
603 int minY = ((int)currentView.min.north()/modulo+1)*modulo;
604 int maxX = ((int)currentView.max.east()/modulo)*modulo;
605 int maxY = ((int)currentView.max.north()/modulo)*modulo;
606 int size=(maxX-minX)/modulo;
607 if (size<20) {
608 int px= size > 10 ? 2 : Math.abs(12-size);
609 g.setColor(Color.green);
610 for (int x=minX; x<=maxX; x+=modulo) {
611 for (int y=minY; y<=maxY; y+=modulo) {
612 Point p = mv.getPoint(new EastNorth(x,y));
613 g.drawLine(p.x-px, p.y, p.x+px, p.y);
614 g.drawLine(p.x, p.y-px, p.x, p.y+px);
615 }
616 }
617 }
618 }
619 }
620
621}
Note: See TracBrowser for help on using the repository browser.