MarkS wrote:
Mark Burton wrote:
Hi Mark,


I'll change it. The original intention was to avoid creating another option (as I'd seen some comment about "yet another option"). But I'm happy to go down that route.

Here's a revised version of the patch picking up the suggestions Mark made.

This adds a new option "maxspeed". This can be set to:

"ignore" - The maxspeed tag is ignored and road class from the style file is used. "heed" - The maxspeed tag is used. If it doesn't exist then road class from the style file is used
"lower" - The lower of the maxspeed tag and the road class is used.
"higher" - The higher of the maxspeed tag and the road class is used.

If "maxspeed" isn't defined then the patch will look for ignore-maxspeed ; if ignore-maxspeed is present then it will just use the road class from the style file. This will ensure current usage isn't broken.

If "maxspeed" and "ignore-maxspeed" are not defined then it will default to "heed" which reproduces current behaviour.

Mark
Index: src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java     (revision 1147)
+++ src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java     (working copy)
@@ -101,6 +101,7 @@
        private final Rule relationRules;
 
        private boolean ignoreMaxspeeds;
+       private String MaxspeedsPar;
 
        class AccessMapping {
                private final String type;
@@ -143,6 +144,18 @@
                relationRules = style.getRelationRules();
                ignoreMaxspeeds = props.getProperty("ignore-maxspeeds") != null;
 
+               MaxspeedsPar=props.getProperty("maxspeed",null);
+               if(MaxspeedsPar==null){
+                       // If the maxspeeds parameter has not been defined then 
fall back to looking at the ignore-maxspeeds parameter
+                       if(ignoreMaxspeeds){
+                               MaxspeedsPar="ignore";
+                       }
+                       else{
+                               MaxspeedsPar="heed";
+                       }
+               }
+               MaxspeedsPar=MaxspeedsPar.toLowerCase();
+
                LineAdder overlayAdder = style.getOverlays(lineAdder);
                if (overlayAdder != null)
                        lineAdder = overlayAdder;
@@ -903,17 +916,30 @@
                }
 
                int speedIdx = -1;
-               if(!ignoreMaxspeeds) {
-                       // maxspeed attribute overrides default for road type
-                       String maxSpeed = way.getTag("maxspeed");
-                       if(maxSpeed != null) {
-                               speedIdx = getSpeedIdx(maxSpeed);
-                               log.info(debugWayName + " maxspeed=" + maxSpeed 
+ ", speedIndex=" + speedIdx);
-                       }
+               String maxSpeed;
+               if(MaxspeedsPar.equals("ignore")){
+                       // Use the style file and ignore the maxspeed tag
+                       road.setSpeed(gt.getRoadSpeed());
                }
+               else if(MaxspeedsPar.equals("heed")){
+                       // Use maxspeed tag, only use the style file if 
maxspeed is missing
+                       maxSpeed = way.getTag("maxspeed");
+                       if(maxSpeed!=null) speedIdx = getSpeedIdx(maxSpeed);
+                       road.setSpeed(speedIdx >= 0? speedIdx : 
gt.getRoadSpeed());
+               }
+               else if(MaxspeedsPar.equals("lower")){
+                       // Use the lower of the maxspeed tag and road class 
from the style file
+                       maxSpeed = way.getTag("maxspeed");
+                       if(maxSpeed!=null) speedIdx = getSpeedIdx(maxSpeed);
+                       road.setSpeed(speedIdx >= 0? 
Math.min(gt.getRoadSpeed(),speedIdx ) : gt.getRoadSpeed());
+               }
+               else if(MaxspeedsPar.equals("higher")){
+                       // Use the higher of the maxspeed tag and the style 
file value
+                       maxSpeed = way.getTag("maxspeed");
+                       if(maxSpeed!=null) speedIdx = getSpeedIdx(maxSpeed);
+                       road.setSpeed(speedIdx >= 0? 
Math.max(gt.getRoadSpeed(),speedIdx ) : gt.getRoadSpeed());
+               }
 
-               road.setSpeed(speedIdx >= 0? speedIdx : gt.getRoadSpeed());
-
                boolean[] noAccess = new boolean[RoadNetwork.NO_MAX];
                String highwayType = way.getTag("highway");
                if(highwayType == null) {
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to