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

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

continuation of addr helper

  • 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 synchronized(this){
277 for (GeorefImage img : images)
278 img.paint(g, mv, CadastrePlugin.backgroundTransparent,
279 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries);
280 }
281 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation);
282 }
283 if (this.isRaster) {
284 paintCrosspieces(g, mv);
285 }
286 if (this.adjustModeEnabled) {
287 WMSAdjustAction.paintAdjustFrames(g, mv);
288 }
289 }
290
291 @Override
292 public void visitBoundingBox(BoundingXYVisitor v) {
293 for (GeorefImage img : images) {
294 v.visit(img.min);
295 v.visit(img.max);
296 }
297 }
298
299 @Override
300 public Object getInfoComponent() {
301 return getToolTipText();
302 }
303
304 @Override
305 public Component[] getMenuEntries() {
306 saveAsPng = new JMenuItem(new MenuActionSaveRasterAs(this));
307 saveAsPng.setEnabled(isRaster);
308 component = new Component[] { new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
309 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
310 new JMenuItem(new MenuActionLoadFromCache()),
311 saveAsPng,
312 new JMenuItem(new LayerListPopup.InfoAction(this)),
313
314 };
315 return component;
316 }
317
318 public GeorefImage findImage(EastNorth eastNorth) {
319 // Iterate in reverse, so we return the image which is painted last.
320 // (i.e. the topmost one)
321 for (int i = images.size() - 1; i >= 0; i--) {
322 if (images.get(i).contains(eastNorth)) {
323 return images.get(i);
324 }
325 }
326 return null;
327 }
328
329 public boolean isOverlapping(Bounds bounds) {
330 GeorefImage georefImage =
331 new GeorefImage(null,
332 Main.proj.latlon2eastNorth(bounds.getMin()),
333 Main.proj.latlon2eastNorth(bounds.getMax()));
334 for (GeorefImage img : images) {
335 if (img.overlap(georefImage))
336 return true;
337 }
338 return false;
339 }
340
341 public void saveToCache(GeorefImage image) {
342 if (CacheControl.cacheEnabled && !isRaster()) {
343 getCacheControl().saveCache(image);
344 }
345 }
346
347 public void saveNewCache() {
348 if (CacheControl.cacheEnabled) {
349 getCacheControl().deleteCacheFile();
350 for (GeorefImage image : images)
351 getCacheControl().saveCache(image);
352 }
353 }
354
355 public CacheControl getCacheControl() {
356 if (cacheControl == null)
357 cacheControl = new CacheControl(this);
358 return cacheControl;
359 }
360
361 /**
362 * Convert the eastNorth input coordinates to raster coordinates.
363 * The original raster size is [0,0,12286,8730] where 0,0 is the upper left corner and
364 * 12286,8730 is the approx. raster max size.
365 * @return the raster coordinates for the wms server request URL (minX,minY,maxX,maxY)
366 */
367 public String eastNorth2raster(EastNorth min, EastNorth max) {
368 double minX = (min.east() - rasterMin.east()) / rasterRatio;
369 double minY = (min.north() - rasterMin.north()) / rasterRatio;
370 double maxX = (max.east() - rasterMin.east()) / rasterRatio;
371 double maxY = (max.north() - rasterMin.north()) / rasterRatio;
372 return minX+","+minY+","+maxX+","+maxY;
373 }
374
375
376 public String getLocation() {
377 return location;
378 }
379
380 public void setLocation(String location) {
381 this.location = location;
382 setName(rebuildName());
383 }
384
385 public String getDepartement() {
386 return departement;
387 }
388
389 public void setDepartement(String departement) {
390 this.departement = departement;
391 }
392
393 public String getCodeCommune() {
394 return codeCommune;
395 }
396
397 public void setCodeCommune(String codeCommune) {
398 this.codeCommune = codeCommune;
399 setName(rebuildName());
400 }
401
402 public boolean isBuildingsOnly() {
403 return buildingsOnly;
404 }
405
406 public void setBuildingsOnly(boolean buildingsOnly) {
407 this.buildingsOnly = buildingsOnly;
408 setName(rebuildName());
409 }
410
411 public boolean isRaster() {
412 return isRaster;
413 }
414
415 public void setRaster(boolean isRaster) {
416 this.isRaster = isRaster;
417 if (saveAsPng != null)
418 saveAsPng.setEnabled(isRaster);
419 }
420
421 public boolean isAlreadyGeoreferenced() {
422 return isAlreadyGeoreferenced;
423 }
424
425 public void setAlreadyGeoreferenced(boolean isAlreadyGeoreferenced) {
426 this.isAlreadyGeoreferenced = isAlreadyGeoreferenced;
427 }
428
429 /**
430 * Set raster positions used for grabbing and georeferencing.
431 * rasterMin is the Eaast North of bottom left corner raster image on the screen when image is grabbed.
432 * The bounds width and height are the raster width and height. The image width matches the current view
433 * and the image height is adapted.
434 * Required: the communeBBox must be set (normally it is catched by CadastreInterface and saved by DownloadWMSPlanImage)
435 * @param bounds the current main map view boundaries
436 */
437 public void setRasterBounds(Bounds bounds) {
438 EastNorth rasterCenter = Main.proj.latlon2eastNorth(bounds.getCenter());
439 EastNorth eaMin = Main.proj.latlon2eastNorth(bounds.getMin());
440 EastNorth eaMax = Main.proj.latlon2eastNorth(bounds.getMax());
441 double rasterSizeX = communeBBox.max.getX() - communeBBox.min.getX();
442 double rasterSizeY = communeBBox.max.getY() - communeBBox.min.getY();
443 double ratio = rasterSizeY/rasterSizeX;
444 // keep same ratio on screen as WMS bbox (stored in communeBBox)
445 rasterMin = new EastNorth(eaMin.getX(), rasterCenter.getY()-(eaMax.getX()-eaMin.getX())*ratio/2);
446 rasterMax = new EastNorth(eaMax.getX(), rasterCenter.getY()+(eaMax.getX()-eaMin.getX())*ratio/2);
447 rasterRatio = (rasterMax.getX()-rasterMin.getX())/rasterSizeX;
448 }
449
450 /**
451 * Called by CacheControl when a new cache file is created on disk.
452 * Save only primitives to keep cache independent of software changes.
453 * @param oos
454 * @throws IOException
455 */
456 public void write(ObjectOutputStream oos) throws IOException {
457 oos.writeInt(this.serializeFormatVersion);
458 oos.writeObject(this.location); // String
459 oos.writeObject(this.codeCommune); // String
460 oos.writeInt(this.lambertZone);
461 oos.writeBoolean(this.isRaster);
462 oos.writeBoolean(this.buildingsOnly);
463 if (this.isRaster) {
464 oos.writeDouble(this.rasterMin.getX());
465 oos.writeDouble(this.rasterMin.getY());
466 oos.writeDouble(this.rasterMax.getX());
467 oos.writeDouble(this.rasterMax.getY());
468 oos.writeDouble(this.rasterRatio);
469 }
470 oos.writeDouble(this.communeBBox.min.getX());
471 oos.writeDouble(this.communeBBox.min.getY());
472 oos.writeDouble(this.communeBBox.max.getX());
473 oos.writeDouble(this.communeBBox.max.getY());
474 }
475
476 /**
477 * Called by CacheControl when a cache file is read from disk.
478 * Cache uses only primitives to stay independent of software changes.
479 * @param ois
480 * @throws IOException
481 * @throws ClassNotFoundException
482 */
483 public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException {
484 currentFormat = ois.readInt();;
485 if (currentFormat < 2) {
486 JOptionPane.showMessageDialog(Main.parent, tr("Unsupported cache file version; found {0}, expected {1}\nCreate a new one.",
487 currentFormat, this.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE);
488 return false;
489 }
490 this.setLocation((String) ois.readObject());
491 this.setCodeCommune((String) ois.readObject());
492 this.lambertZone = ois.readInt();
493 this.setRaster(ois.readBoolean());
494 if (currentFormat >= 4)
495 this.setBuildingsOnly(ois.readBoolean());
496 if (this.isRaster) {
497 double X = ois.readDouble();
498 double Y = ois.readDouble();
499 this.rasterMin = new EastNorth(X, Y);
500 X = ois.readDouble();
501 Y = ois.readDouble();
502 this.rasterMax = new EastNorth(X, Y);
503 this.rasterRatio = ois.readDouble();
504 }
505 double minX = ois.readDouble();
506 double minY = ois.readDouble();
507 double maxX = ois.readDouble();
508 double maxY = ois.readDouble();
509 this.communeBBox = new EastNorthBound(new EastNorth(minX, minY), new EastNorth(maxX, maxY));
510 if (this.lambertZone != currentLambertZone && currentLambertZone != -1) {
511 JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+
512 "incompatible with current Lambert zone {1}",
513 this.lambertZone+1, currentLambertZone), tr("Cache Lambert Zone Error"), JOptionPane.ERROR_MESSAGE);
514 return false;
515 }
516 synchronized(this){
517 boolean EOF = false;
518 try {
519 while (!EOF) {
520 GeorefImage newImage = (GeorefImage) ois.readObject();
521 for (GeorefImage img : this.images) {
522 if (CadastrePlugin.backgroundTransparent) {
523 if (img.overlap(newImage))
524 // mask overlapping zone in already grabbed image
525 img.withdraw(newImage);
526 else
527 // mask overlapping zone in new image only when
528 // new image covers completely the existing image
529 newImage.withdraw(img);
530 }
531 }
532 this.images.add(newImage);
533 }
534 } catch (EOFException ex) {
535 // expected exception when all images are read
536 }
537 }
538 System.out.println("Cache loaded for location "+location+" with "+images.size()+" images");
539 return true;
540 }
541
542 /**
543 * Join the grabbed images into one single.
544 */
545 public void joinBufferedImages() {
546 if (images.size() > 1) {
547 EastNorth min = images.get(0).min;
548 EastNorth max = images.get(images.size()-1).max;
549 int oldImgWidth = images.get(0).image.getWidth();
550 int oldImgHeight = images.get(0).image.getHeight();
551 HashSet<Double> lx = new HashSet<Double>();
552 HashSet<Double> ly = new HashSet<Double>();
553 for (GeorefImage img : images) {
554 lx.add(img.min.east());
555 ly.add(img.min.north());
556 }
557 int newWidth = oldImgWidth*lx.size();
558 int newHeight = oldImgHeight*ly.size();
559 BufferedImage new_img = new BufferedImage(newWidth, newHeight, images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/);
560 Graphics g = new_img.getGraphics();
561 // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left
562 int rasterDivider = (int)Math.sqrt(images.size());
563 for (int h = 0; h < lx.size(); h++) {
564 for (int v = 0; v < ly.size(); v++) {
565 int newx = h*oldImgWidth;
566 int newy = newHeight - oldImgHeight - (v*oldImgHeight);
567 int j = h*rasterDivider + v;
568 g.drawImage(images.get(j).image, newx, newy, this);
569 }
570 }
571 synchronized(this) {
572 images.clear();
573 images.add(new GeorefImage(new_img, min, max));
574 }
575 }
576 }
577
578 /**
579 * Image cropping based on two EN coordinates pointing to two corners in diagonal
580 * Because it's coming from user mouse clics, we have to sort de positions first.
581 * Works only for raster image layer (only one image in collection).
582 * Updates layer georeferences.
583 * @param en1
584 * @param en2
585 */
586 public void cropImage(EastNorth en1, EastNorth en2){
587 // adj1 is corner bottom, left
588 EastNorth adj1 = new EastNorth(en1.east() <= en2.east() ? en1.east() : en2.east(),
589 en1.north() <= en2.north() ? en1.north() : en2.north());
590 // adj2 is corner top, right
591 EastNorth adj2 = new EastNorth(en1.east() > en2.east() ? en1.east() : en2.east(),
592 en1.north() > en2.north() ? en1.north() : en2.north());
593 images.get(0).crop(adj1, adj2);
594 // update the layer georefs
595 rasterMin = adj1;
596 rasterMax = adj2;
597 setCommuneBBox(new EastNorthBound(new EastNorth(0,0), new EastNorth(images.get(0).image.getWidth()-1,images.get(0).image.getHeight()-1)));
598 rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX());
599 }
600
601 public EastNorthBound getCommuneBBox() {
602 return communeBBox;
603 }
604
605 public void setCommuneBBox(EastNorthBound entireCommune) {
606 this.communeBBox = entireCommune;
607 }
608
609 /**
610 * Method required by ImageObserver when drawing an image
611 */
612 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
613 return false;
614 }
615
616 public int getLambertZone() {
617 return lambertZone;
618 }
619
620 public EastNorth getRasterCenter() {
621 return new EastNorth((images.get(0).max.east()+images.get(0).min.east())/2,
622 (images.get(0).max.north()+images.get(0).min.north())/2);
623 }
624
625 public void displace(double dx, double dy) {
626 this.rasterMin = new EastNorth(rasterMin.east() + dx, rasterMin.north() + dy);
627 this.rasterMax = new EastNorth(rasterMax.east() + dx, rasterMax.north() + dy);
628 images.get(0).shear(dx, dy);
629 }
630
631 public void resize(EastNorth rasterCenter, double proportion) {
632 this.rasterMin = rasterMin.interpolate(rasterCenter, proportion);
633 this.rasterMax = rasterMax.interpolate(rasterCenter, proportion);
634 images.get(0).scale(rasterCenter, proportion);
635 }
636
637 public void rotate(EastNorth rasterCenter, double angle) {
638 this.rasterMin = rasterMin.rotate(rasterCenter, angle);
639 this.rasterMax = rasterMax.rotate(rasterCenter, angle);
640// double proportion = dst1.distance(dst2)/org1.distance(org2);
641 images.get(0).rotate(rasterCenter, angle);
642 this.angle += angle;
643 }
644
645 private void paintCrosspieces(Graphics g, MapView mv) {
646 String crosspieces = Main.pref.get("cadastrewms.crosspieces", "0");
647 if (!crosspieces.equals("0")) {
648 int modulo = 25;
649 if (crosspieces.equals("2")) modulo = 50;
650 if (crosspieces.equals("3")) modulo = 100;
651 EastNorthBound currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()),
652 mv.getEastNorth(mv.getWidth(), 0));
653 int minX = ((int)currentView.min.east()/modulo+1)*modulo;
654 int minY = ((int)currentView.min.north()/modulo+1)*modulo;
655 int maxX = ((int)currentView.max.east()/modulo)*modulo;
656 int maxY = ((int)currentView.max.north()/modulo)*modulo;
657 int size=(maxX-minX)/modulo;
658 if (size<20) {
659 int px= size > 10 ? 2 : Math.abs(12-size);
660 g.setColor(Color.green);
661 for (int x=minX; x<=maxX; x+=modulo) {
662 for (int y=minY; y<=maxY; y+=modulo) {
663 Point p = mv.getPoint(new EastNorth(x,y));
664 g.drawLine(p.x-px, p.y, p.x+px, p.y);
665 g.drawLine(p.x, p.y-px, p.x, p.y+px);
666 }
667 }
668 }
669 }
670 }
671
672}
Note: See TracBrowser for help on using the repository browser.