| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package seachart;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.Color;
|
|---|
| 5 | import java.awt.Font;
|
|---|
| 6 | import java.awt.Graphics2D;
|
|---|
| 7 | import java.awt.Rectangle;
|
|---|
| 8 | import java.awt.geom.Point2D;
|
|---|
| 9 | import java.awt.geom.Point2D.Double;
|
|---|
| 10 | import java.util.Collections;
|
|---|
| 11 | import java.util.List;
|
|---|
| 12 |
|
|---|
| 13 | import javax.swing.Action;
|
|---|
| 14 |
|
|---|
| 15 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 16 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| 17 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
|---|
| 18 | import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
|
|---|
| 19 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 20 | import org.openstreetmap.josm.gui.MapView;
|
|---|
| 21 | import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
|
|---|
| 22 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
|---|
| 23 |
|
|---|
| 24 | import render.ChartContext;
|
|---|
| 25 | import render.Renderer;
|
|---|
| 26 | import s57.S57map;
|
|---|
| 27 | import s57.S57map.Feature;
|
|---|
| 28 | import s57.S57map.GeomIterator;
|
|---|
| 29 | import s57.S57map.Pflag;
|
|---|
| 30 | import s57.S57map.Snode;
|
|---|
| 31 | import s57.S57obj.Obj;
|
|---|
| 32 | import symbols.Symbols;
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * @author Malcolm Herring
|
|---|
| 36 | */
|
|---|
| 37 | public class ChartImage extends ImageryLayer implements ZoomChangeListener, ChartContext {
|
|---|
| 38 |
|
|---|
| 39 | double top;
|
|---|
| 40 | double bottom;
|
|---|
| 41 | double left;
|
|---|
| 42 | double right;
|
|---|
| 43 | double width;
|
|---|
| 44 | double height;
|
|---|
| 45 | int zoom;
|
|---|
| 46 |
|
|---|
| 47 | public ChartImage(ImageryInfo info) {
|
|---|
| 48 | super(info);
|
|---|
| 49 | MapView.addZoomChangeListener(this);
|
|---|
| 50 | zoomChanged();
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | @Override
|
|---|
| 54 | public Action[] getMenuEntries() {
|
|---|
| 55 | return null;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | @Override
|
|---|
| 59 | protected List<OffsetMenuEntry> getOffsetMenuEntries() {
|
|---|
| 60 | return Collections.emptyList();
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | @Override
|
|---|
| 64 | public String getToolTipText() {
|
|---|
| 65 | return null;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | @Override
|
|---|
| 69 | protected Action getAdjustAction() {
|
|---|
| 70 | return null;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | @Override
|
|---|
| 74 | public void visitBoundingBox(BoundingXYVisitor arg0) {
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | @Override
|
|---|
| 78 | public void paint(Graphics2D g2, MapView mv, Bounds bb) {
|
|---|
| 79 | Rectangle rect = MainApplication.getMap().mapView.getBounds();
|
|---|
| 80 | Renderer.reRender(g2, rect, zoom, Math.pow(2, (zoom-12)), SeachartAction.map, this);
|
|---|
| 81 | g2.setPaint(Color.black);
|
|---|
| 82 | g2.setFont(new Font("Arial", Font.BOLD, 20));
|
|---|
| 83 | Rectangle crect = g2.getClipBounds();
|
|---|
| 84 | if ((crect.y + crect.height) < (rect.y + rect.height - 10)) {
|
|---|
| 85 | g2.drawString(("Z" + zoom), (crect.x + crect.width - 40), (crect.y + crect.height - 10));
|
|---|
| 86 | } else {
|
|---|
| 87 | g2.drawString(("Z" + zoom), (rect.x + rect.width - 40), (rect.y + rect.height - 10));
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | @Override
|
|---|
| 92 | public void zoomChanged() {
|
|---|
| 93 | if ((MainApplication.getMap() != null) && (MainApplication.getMap().mapView != null)) {
|
|---|
| 94 | Bounds bounds = MainApplication.getMap().mapView.getRealBounds();
|
|---|
| 95 | top = bounds.getMax().lat();
|
|---|
| 96 | bottom = bounds.getMin().lat();
|
|---|
| 97 | left = bounds.getMin().lon();
|
|---|
| 98 | right = bounds.getMax().lon();
|
|---|
| 99 | width = MainApplication.getMap().mapView.getBounds().getWidth();
|
|---|
| 100 | height = MainApplication.getMap().mapView.getBounds().getHeight();
|
|---|
| 101 | zoom = ((int) Math.min(18, Math.max(9, Math.round(Math.floor(Math.log(1024 / bounds.asRect().height) / Math.log(2))))));
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | @Override
|
|---|
| 106 | public Point2D.Double getPoint(Snode coord) {
|
|---|
| 107 | return (Double) MainApplication.getMap().mapView.getPoint2D(new LatLon(Math.toDegrees(coord.lat), Math.toDegrees(coord.lon)));
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | @Override
|
|---|
| 111 | public double mile(Feature feature) {
|
|---|
| 112 | return 185000 / MainApplication.getMap().mapView.getDist100Pixel();
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | @Override
|
|---|
| 116 | public boolean clip() {
|
|---|
| 117 | return true;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | @Override
|
|---|
| 121 | public int grid() {
|
|---|
| 122 | return 0;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | @Override
|
|---|
| 126 | public Color background(S57map map) {
|
|---|
| 127 | if (map.features.containsKey(Obj.COALNE)) {
|
|---|
| 128 | for (Feature feature : map.features.get(Obj.COALNE)) {
|
|---|
| 129 | if (feature.geom.prim == Pflag.POINT) {
|
|---|
| 130 | break;
|
|---|
| 131 | }
|
|---|
| 132 | GeomIterator git = map.new GeomIterator(feature.geom);
|
|---|
| 133 | git.nextComp();
|
|---|
| 134 | while (git.hasEdge()) {
|
|---|
| 135 | git.nextEdge();
|
|---|
| 136 | while (git.hasNode()) {
|
|---|
| 137 | Snode node = git.next();
|
|---|
| 138 | if (node == null)
|
|---|
| 139 | continue;
|
|---|
| 140 | if ((node.lat >= map.bounds.minlat) && (node.lat <= map.bounds.maxlat)
|
|---|
| 141 | && (node.lon >= map.bounds.minlon) && (node.lon <= map.bounds.maxlon)) {
|
|---|
| 142 | return Symbols.Bwater;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 | return Symbols.Yland;
|
|---|
| 148 | } else {
|
|---|
| 149 | if (map.features.containsKey(Obj.ROADWY) || map.features.containsKey(Obj.RAILWY)
|
|---|
| 150 | || map.features.containsKey(Obj.LAKARE) || map.features.containsKey(Obj.RIVERS) || map.features.containsKey(Obj.CANALS)) {
|
|---|
| 151 | return Symbols.Yland;
|
|---|
| 152 | } else {
|
|---|
| 153 | return Symbols.Bwater;
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | @Override
|
|---|
| 159 | public RuleSet ruleset() {
|
|---|
| 160 | return RuleSet.ALL;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | @Override
|
|---|
| 164 | public Chart chart() {
|
|---|
| 165 | // TODO Auto-generated method stub
|
|---|
| 166 | return null;
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|