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

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

fixed a bug in cachedir size control; add departement selection as option in municipality dialog

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