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

Last change on this file since 20390 was 20390, checked in by pieren, 14 years ago

Many small fixes and improvements

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