Ignore:
Timestamp:
2013-01-08T21:26:40+01:00 (13 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/seamap/Renderer.java

    r29175 r29184  
    1414import java.awt.geom.Point2D;
    1515import java.util.ArrayList;
    16 import java.util.EnumMap;
    1716import java.util.HashMap;
    1817
     
    4342                        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    4443                        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    45                         Rules.MainRules(map, zoom);
     44                        Rules.rules(map, zoom);
    4645                }
    4746        }
    4847       
    49         public static EnumMap<Att, AttItem> getAtts(Feature feature, Obj obj, int idx) {
    50                 HashMap<Integer, EnumMap<Att, AttItem>> objs = feature.objs.get(obj);
     48        public static AttMap getAtts(Feature feature, Obj obj, int idx) {
     49                HashMap<Integer, AttMap> objs = feature.objs.get(obj);
    5150                if (objs == null) return null;
    5251                else return objs.get(idx);
     
    5453       
    5554        public static Object getAttVal(Feature feature, Obj obj, int idx, Att att) {
    56                 EnumMap<Att, AttItem> atts = getAtts(feature, obj, idx);
     55                AttMap atts = getAtts(feature, obj, idx);
    5756                if (atts == null) return  S57val.nullVal(att);
    5857                else {
     
    6261                }
    6362        }
     63
     64        public static Coord findCentroid(Feature feature) {
     65    double slon = 0.0;
     66    double slat = 0.0;
     67    double sarc = 0.0;
     68    double llon = 0.0;
     69    double llat = 0.0;
     70                if (feature.flag == Fflag.NODE) {
     71                        return map.nodes.get(feature.refs);
     72                }
     73                ArrayList<Long> way = map.ways.get(feature.refs);
     74                if (feature.flag == Fflag.WAY) {
     75                        llon = map.nodes.get(way.get(1)).lon;
     76                        llat = map.nodes.get(way.get(1)).lat;
     77                } else {
     78                        llon = map.nodes.get(way.get(0)).lon;
     79                        llat = map.nodes.get(way.get(0)).lat;
     80                }
     81                for (long node : way) {
     82      double lon = map.nodes.get(node).lon;
     83      double lat = map.nodes.get(node).lat;
     84      double arc = Math.sqrt(Math.pow((lon-llon), 2) + Math.pow((lat-llat), 2));
     85      slon += (lon * arc);
     86      slat += (lat * arc);
     87      sarc += arc;
     88      llon = lon;
     89      llat = lat;
     90                }
     91                return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
     92        }
    6493       
    6594        public static void symbol(Feature feature, ArrayList<Instr> symbol, Obj obj) {
    66                 Point2D point = helper.getPoint(map.nodes.get(feature.refs));
     95                Point2D point = helper.getPoint(findCentroid(feature));
    6796                ArrayList<ColCOL> colours = (ArrayList<ColCOL>) getAttVal(feature, obj, 0, Att.COLOUR);
    6897                ArrayList<ColPAT> pattern = (ArrayList<ColPAT>) getAttVal(feature, obj, 0, Att.COLPAT);
Note: See TracChangeset for help on using the changeset viewer.