Ignore:
Timestamp:
2008-08-28T22:07:04+02:00 (16 years ago)
Author:
stoecker
Message:

added multi-style mappaint support. Closes #1186

File:
1 edited

Legend:

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

    r880 r885  
    4848
    4949        protected boolean isZoomOk(ElemStyle e) {
     50                if (!zoomLevelDisplay) /* show everything if the user wishes so */
     51                        return true;
     52
    5053                double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter
    5154
    52                 /* show everything if the user wishes so */
    53                 if (!zoomLevelDisplay) {
    54                         return true;
    55                 }
    56 
    57                 if (e == null) {
    58                         /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */
    59                         if (circum < 1500)
    60                                 return true;
    61                         return false;
    62                 }
     55                if(e == null) /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */
     56                        return (circum < 1500);
    6357
    6458                // formula to calculate a map scale: natural size / map size = scale
     
    6761                // so the exact "correcting value" below depends only on the screen size and resolution
    6862                // XXX - do we need a Preference setting for this (if things vary widely)?
    69                 /*System.out.println(
    70                 "Circum: " + circum +
    71                 " max: " + e.getMaxScale() + "(" + e.getMaxScale()/22 + ")" +
    72                 " min:" + e.getMinScale() + "(" + e.getMinScale()/22 + ")");*/
    73                 if(circum>=e.getMaxScale() / 22 || circum<e.getMinScale() / 22)
    74                         return false;
    75                 return true;
     63                return !(circum >= e.maxScale / 22 || circum < e.minScale / 22);
    7664        }
    7765
     
    8371         */
    8472        public void visit(Node n) {
    85                 ElemStyle nodeStyle = MapPaintStyles.getStyle(n);
    86                 if (nodeStyle!=null) {
    87                         if (nodeStyle instanceof IconElemStyle) {
    88                                 if (isZoomOk(nodeStyle)) {
    89                                         drawNode(n, ((IconElemStyle)nodeStyle).getIcon(), ((IconElemStyle)nodeStyle).doAnnotate());
    90                                 }
    91                         } else {
    92                                 // throw some sort of exception
    93                         }
    94                 } else {
     73                IconElemStyle nodeStyle = MapPaintStyles.getStyles().get(n);
     74                if (nodeStyle != null && isZoomOk(nodeStyle))
     75                        drawNode(n, nodeStyle.icon, nodeStyle.annotate);
     76                else {
    9577                        if (n.selected)
    9678                                drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
     
    11395                 && (!showRelevantDirectionsOnly || w.hasDirectionKeys)));
    11496
    115                 Color colour = untaggedColor;
    116                 Color areacolour = untaggedColor;
     97                Color color = untaggedColor;
     98                Color areacolor = untaggedColor;
    11799                int width = defaultSegmentWidth;
    118100                int realWidth = 0; //the real width of the element in meters
    119101                boolean dashed = false;
    120102                boolean area = false;
    121                 ElemStyle wayStyle = MapPaintStyles.getStyle(w);
    122 
    123                 if(!isZoomOk(wayStyle)) {
     103                ElemStyle wayStyle = MapPaintStyles.getStyles().get(w);
     104
     105                if(!isZoomOk(wayStyle))
    124106                        return;
    125                 }
    126 
     107
     108                LineElemStyle l = null;
    127109                if(wayStyle!=null)
    128110                {
    129                         LineElemStyle l = null;
    130111                        if(wayStyle instanceof LineElemStyle)
    131                         {
    132112                                l = (LineElemStyle)wayStyle;
    133                         }
    134113                        else if (wayStyle instanceof AreaElemStyle)
    135114                        {
    136                                 areacolour = ((AreaElemStyle)wayStyle).colour;
    137                                 colour = areacolour;
     115                                areacolor = ((AreaElemStyle)wayStyle).color;
     116                                color = areacolor;
    138117                                l = ((AreaElemStyle)wayStyle).line;
    139118                                area = true;
     
    141120                        if(l != null)
    142121                        {
    143                                 colour = l.colour;
     122                                color = l.color;
    144123                                width = l.width;
    145124                                realWidth = l.realWidth;
     
    149128
    150129                if (area && fillAreas)
    151                         drawWayAsArea(w, areacolour);
    152                 int orderNumber = 0;
    153 
    154                 Node lastN = null;
    155                 for (Node n : w.nodes) {
    156                         if (lastN == null) {
     130                        drawWayAsArea(w, areacolor);
     131                if (realWidth > 0 && useRealWidth && !showDirection)
     132                {
     133                        int tmpWidth = (int) (100 /  (float) (circum / realWidth));
     134                        if (tmpWidth > width) width = tmpWidth;
     135                }
     136
     137                Node lastN;
     138                if(l != null && l.overlays != null)
     139                {
     140                        for(LineElemStyle s : l.overlays)
     141                        {
     142                                if(!s.over)
     143                                {
     144                                        lastN = null;
     145                                        for(Node n : w.nodes)
     146                                        {
     147                                                if(lastN != null)
     148                                                        drawSeg(lastN, n, s.color != null ? s.color : color, false, s.getWidth(width), s.dashed);
     149                                                lastN = n;
     150                                        }
     151                                }
     152                        }
     153                }
     154
     155                lastN = null;
     156                for(Node n : w.nodes)
     157                {
     158                        if(lastN != null)
     159                                drawSeg(lastN, n, w.selected ? selectedColor : color, showDirection, width, dashed);
     160                        lastN = n;
     161                }
     162
     163                if(l != null && l.overlays != null)
     164                {
     165                        for(LineElemStyle s : l.overlays)
     166                        {
     167                                if(s.over)
     168                                {
     169                                        lastN = null;
     170                                        for(Node n : w.nodes)
     171                                        {
     172                                                if(lastN != null)
     173                                                        drawSeg(lastN, n, s.color != null ? s.color : color, false, s.getWidth(width), s.dashed);
     174                                                lastN = n;
     175                                        }
     176                                }
     177                        }
     178                }
     179
     180                if(showOrderNumber)
     181                {
     182                        int orderNumber = 0;
     183                        lastN = null;
     184                        for(Node n : w.nodes)
     185                        {
     186                                if(lastN != null)
     187                                {
     188                                        orderNumber++;
     189                                        drawOrderNumber(lastN, n, orderNumber);
     190                                }
    157191                                lastN = n;
    158                                 continue;
    159                         }
    160                         orderNumber++;
    161 
    162                         if (realWidth > 0 && useRealWidth && !showDirection)
    163                         {
    164                                 int tmpWidth = (int) (100 /  (float) (circum / realWidth));
    165                                 if (tmpWidth > width) width = tmpWidth;
    166                         }
    167                         drawSeg(lastN, n, w.selected ? selectedColor : colour, showDirection, width, dashed);
    168 
    169                         if (showOrderNumber)
    170                                 drawOrderNumber(lastN, n, orderNumber);
    171 
    172                         lastN = n;
     192                        }
    173193                }
    174194        }
     
    179199
    180200        // This assumes that all segments are aligned in the same direction!
    181         protected void drawWayAsArea(Way w, Color colour)
     201        protected void drawWayAsArea(Way w, Color color)
    182202        {
    183203                Polygon polygon = new Polygon();
     
    189209                }
    190210
    191                 Color mycolor = w.selected ? selectedColor : colour;
     211                Color mycolor = w.selected ? selectedColor : color;
    192212                // set the opacity (alpha) level of the filled polygon
    193213                g.setColor(new Color( mycolor.getRed(), mycolor.getGreen(), mycolor.getBlue(), fillAlpha));
     
    299319
    300320                for (final OsmPrimitive osm : data.ways)
    301                         if (!osm.incomplete && !osm.deleted && MapPaintStyles.isArea(osm))
     321                        if (!osm.incomplete && !osm.deleted && MapPaintStyles.getStyles().isArea((Way)osm))
    302322                                osm.visit(this);
    303323                        else if (!osm.deleted && !osm.incomplete)
Note: See TracChangeset for help on using the changeset viewer.