Ignore:
Timestamp:
2011-03-13T20:44:57+01:00 (13 years ago)
Author:
bastiK
Message:

mapcss: improvements in text label selection, performance and typo (patch by anonymous, see #6107)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r3979 r3987  
    3939import org.openstreetmap.josm.gui.mappaint.NodeElemStyle;
    4040import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.HorizontalTextAlignment;
     41import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.NodeTextElement;
    4142import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol;
    42 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.NodeTextElement;
    4343import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.VerticalTextAlignment;
    4444import org.openstreetmap.josm.gui.mappaint.TextElement;
    4545import org.openstreetmap.josm.tools.ImageProvider;
    46 import org.openstreetmap.josm.tools.LanguageInfo;
    4746import org.openstreetmap.josm.tools.Pair;
    4847
     
    7372
    7473    private final boolean leftHandTraffic;
    75 
    76     private final Collection<String> regionalNameOrder;
    7774
    7875    private static final double PHI = Math.toRadians(20);
     
    104101        this.segmentNumberSpace = Main.pref.getInteger("mappaint.segmentnumber.space", 40);
    105102
    106         String[] names = {"name:" + LanguageInfo.getJOSMLocaleCode(), "name", "int_name", "ref", "operator", "brand", "addr:housenumber"};
    107         this.regionalNameOrder = Main.pref.getCollection("mappaint.nameOrder", Arrays.asList(names));
    108103        this.circum = circum;
    109104        this.leftHandTraffic = leftHandTraffic;
     
    118113     * @param onewayReversed for oneway=-1 and similar
    119114     */
    120     public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, 
     115    public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor,
    121116            TextElement text, boolean showOrientation, boolean showHeadArrowOnly,
    122117            boolean showOneway, boolean onewayReversed) {
     
    253248        if (text == null)
    254249            return;
    255         String name = text.getString(way, this);
     250        String name = text.getString(way);
    256251        if (name == null || name.equals(""))
    257252            return;
     
    292287
    293288        if (p1[0] < p2[0] &&
    294             p1[2] < Math.PI/2 &&
    295             p1[2] > -Math.PI/2) {
     289                p1[2] < Math.PI/2 &&
     290                p1[2] > -Math.PI/2) {
    296291            angleOffset = 0;
    297292            offsetSign = 1;
     
    347342            }
    348343            return new double[] {poly.xpoints[i-1]+(totalLen - curLen)/segLen*dx,
    349                                  poly.ypoints[i-1]+(totalLen - curLen)/segLen*dy,
    350                                  Math.atan2(dy, dx)};
     344                    poly.ypoints[i-1]+(totalLen - curLen)/segLen*dy,
     345                    Math.atan2(dy, dx)};
    351346        }
    352347        return null;
     
    495490            return;
    496491
    497         String s = text.textKey == null ? getNodeName(n) : n.get(text.textKey);
    498         if (s == null)
    499             return;
     492        /*
     493         * abort if we can't compose the label to be rendered
     494         */
     495        if (text.labelCompositionStrategy == null) return;
     496        String s = text.labelCompositionStrategy.compose(n);
     497        if (s == null) return;
    500498
    501499        Font defaultFont = g.getFont();
     
    598596
    599597        if (text != null && isShowNames()) {
    600             String name = text.textKey == null ? getAreaName(osm) : osm.get(text.textKey);
    601             if (name == null)
    602                 return;
     598            /*
     599             * abort if we can't compose the label to be rendered
     600             */
     601            if (text.labelCompositionStrategy == null) return;
     602            String name = text.labelCompositionStrategy.compose(osm);
     603            if (name == null) return;
    603604
    604605            Rectangle pb = polygon.getBounds();
     
    931932    }
    932933
    933     //TODO Not a good place for this method
    934     public String getNodeName(Node n) {
    935         String name = null;
    936         if (n.hasKeys()) {
    937             for (String rn : regionalNameOrder) {
    938                 name = n.get(rn);
    939                 if (name != null) {
    940                     break;
    941                 }
    942             }
    943         }
    944         return name;
    945     }
    946 
    947     //TODO Not a good place for this method
    948     public String getAreaName(OsmPrimitive w) {
    949         String name = null;
    950         if (w.hasKeys()) {
    951             for (String rn : regionalNameOrder) {
    952                 name = w.get(rn);
    953                 if (name != null) {
    954                     break;
    955                 }
    956             }
    957         }
    958         return name;
    959     }
    960 
    961934    public boolean isInactive() {
    962935        return inactive;
Note: See TracChangeset for help on using the changeset viewer.