Changeset 32457 in osm


Ignore:
Timestamp:
2016-06-30T00:22:24+02:00 (8 years ago)
Author:
darya
Message:

styling: oneway, stop numbers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java

    r32438 r32457  
    55import java.awt.Graphics;
    66import java.awt.Point;
     7import java.util.HashMap;
    78import java.util.List;
    89
     
    1112import org.openstreetmap.josm.data.osm.Relation;
    1213import org.openstreetmap.josm.data.osm.RelationMember;
     14import org.openstreetmap.josm.data.osm.Way;
    1315import org.openstreetmap.josm.data.validation.PaintVisitor;
    1416import org.openstreetmap.josm.gui.MapView;
     
    3133        public void visit(Relation r) {
    3234
     35                HashMap<Long, String> stopOrderMap = new HashMap<>();
     36
    3337                int stopCount = 1;
     38
    3439                for (RelationMember rm : r.getMembers()) {
     40
    3541                        if (RouteUtils.isPTStop(rm)) {
     42
    3643                                String label = "";
    37                                 if (r.hasKey("ref")) {
    38                                         label = label + r.get("ref");
    39                                 } else if (r.hasKey("name")) {
    40                                         label = label + r.get("name");
    41                                 }
    42                                 label = label + "." + stopCount;
     44
     45                                if (stopOrderMap.containsKey(rm.getMember().getId())) {
     46                                        label = stopOrderMap.get(rm.getMember().getId());
     47                                        label = label + ";" + stopCount;
     48                                } else {
     49                                        if (r.hasKey("ref")) {
     50                                                label = label + r.get("ref");
     51                                        } else if (r.hasKey("name")) {
     52                                                label = label + r.get("name");
     53                                        }
     54                                        label = label + ":" + stopCount;
     55                                }
     56
     57                                stopOrderMap.put(rm.getMember().getId(), label);
    4358                                drawStop(rm.getMember(), label);
    4459                                stopCount++;
     60
    4561                        } else if (RouteUtils.isPTWay(rm)) {
    4662                                if (rm.isWay()) {
     
    6177
    6278        @Override
    63         public void visit(List<Node> nodes) {
     79        public void visit(Way w) {
     80
     81                if (w == null) {
     82                        return;
     83                }
     84
     85                /*-
     86                 * oneway values:
     87                 * 0 two-way street
     88                 * 1 oneway street in the way's direction
     89                 * 2 oneway street in ways's direction but public transport allowed
     90                 * -1 oneway street in reverse direction
     91                 * -2 oneway street in reverse direction but public transport allowed
     92                 */
     93                int oneway = 0;
     94
     95                if (w.hasTag("junction", "roundabout") || w.hasTag("highway", "motorway")) {
     96                        oneway = 1;
     97                } else if (w.hasTag("oneway", "1") || w.hasTag("oneway", "yes") || w.hasTag("oneway", "true")) {
     98                        if (w.hasTag("busway", "lane") || w.hasTag("busway:left", "lane") || w.hasTag("busway:right", "lane")
     99                                        || w.hasTag("oneway:bus", "no") || w.hasTag("busway", "opposite_lane")
     100                                        || w.hasTag("oneway:psv", "no") || w.hasTag("trolley_wire", "backward")) {
     101                                oneway = 2;
     102                        } else {
     103                                oneway = 1;
     104                        }
     105                } else if (w.hasTag("oneway", "-1") || w.hasTag("oneway", "reverse")) {
     106                        if (w.hasTag("busway", "lane") || w.hasTag("busway:left", "lane") || w.hasTag("busway:right", "lane")
     107                                        || w.hasTag("oneway:bus", "no") || w.hasTag("busway", "opposite_lane")
     108                                        || w.hasTag("oneway:psv", "no") || w.hasTag("trolley_wire", "backward")) {
     109                                oneway = -2;
     110                        } else {
     111                                oneway = -1;
     112                        }
     113                }
     114
     115                visit(w.getNodes(), oneway);
     116
     117        }
     118
     119        public void visit(List<Node> nodes, int oneway) {
    64120                Node lastN = null;
    65121                for (Node n : nodes) {
     
    68124                                continue;
    69125                        }
    70                         drawSegment(lastN, n, new Color(208, 80, 208, 179));
     126                        this.drawSegment(lastN, n, new Color(208, 80, 208, 179), oneway);
    71127                        lastN = n;
    72128                }
     
    83139                if (n.isDrawable() && isNodeVisible(n)) {
    84140                        drawNode(n, Color.BLUE);
     141                }
     142        }
     143
     144        /**
     145         * Draws a line around the segment
     146         *
     147         * @param n1
     148         *            The first node of segment
     149         * @param n2
     150         *            The second node of segment
     151         * @param color
     152         *            The color
     153         */
     154        protected void drawSegment(Node n1, Node n2, Color color, int oneway) {
     155                if (n1.isDrawable() && n2.isDrawable() && isSegmentVisible(n1, n2)) {
     156                        drawSegment(mv.getPoint(n1), mv.getPoint(n2), color, oneway);
    85157                }
    86158        }
     
    96168         *            The color
    97169         */
    98         protected void drawSegment(Point p1, Point p2, Color color) {
     170        protected void drawSegment(Point p1, Point p2, Color color, int oneway) {
    99171
    100172                double t = Math.atan2((double) p2.x - p1.x, (double) p2.y - p1.y);
     
    109181                g.fillOval((int) (p2.x - 8), (int) (p2.y - 8), 16, 16);
    110182
     183                if (oneway != 0) {
     184                        double middleX = (double) (p1.x + p2.x) / 2.0;
     185                        double middleY = (double) (p1.y + p2.y) / 2.0;
     186                        double cosTriangle = 6 * Math.cos(t);
     187                        double sinTriangle = 6 * Math.sin(t);
     188                        g.setColor(new Color(50, 50, 50));
     189
     190                        if (oneway > 0) {
     191                                int[] xFillTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle),
     192                                                (int) (middleX + 2 * sinTriangle) };
     193                                int[] yFillTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle),
     194                                                (int) (middleY + 2 * cosTriangle) };
     195                                g.fillPolygon(xFillTriangle, yFillTriangle, 3);
     196
     197                                if (oneway == 2) {
     198                                        int[] xDrawTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle),
     199                                                        (int) (middleX - 2 * sinTriangle) };
     200                                        int[] yDrawTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle),
     201                                                        (int) (middleY - 2 * cosTriangle) };
     202                                        g.fillPolygon(xDrawTriangle, yDrawTriangle, 3);
     203                                }
     204                        }
     205
     206                        if (oneway < 0) {
     207                                int[] xFillTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle),
     208                                                (int) (middleX - 2 * sinTriangle) };
     209                                int[] yFillTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle),
     210                                                (int) (middleY - 2 * cosTriangle) };
     211                                g.fillPolygon(xFillTriangle, yFillTriangle, 3);
     212
     213                                if (oneway == -2) {
     214                                        int[] xDrawTriangle = { (int) (middleX + cosTriangle), (int) (middleX - cosTriangle),
     215                                                        (int) (middleX + 2 * sinTriangle) };
     216                                        int[] yDrawTriangle = { (int) (middleY - sinTriangle), (int) (middleY + sinTriangle),
     217                                                        (int) (middleY + 2 * cosTriangle) };
     218                                        g.fillPolygon(xDrawTriangle, yDrawTriangle, 3);
     219                                }
     220                        }
     221
     222                }
     223
    111224                // g.drawLine((int) (p1.x - cosT), (int) (p1.y - sinT), (int) (p2.x +
    112225                // cosT), (int) (p2.y - sinT));
     
    139252
    140253                Point p = mv.getPoint(n);
    141                
     254
    142255                g.setColor(Color.WHITE);
    143256                Font stringFont = new Font("SansSerif", Font.PLAIN, 24);
     
    160273                }
    161274
    162 
    163275        }
    164276
Note: See TracChangeset for help on using the changeset viewer.