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

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

minor fixes

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