Are you a heavy duty styler? If so, read on: I notice that quite a lot of postings on the list are from people who are having problems with complex style files. This little patch won't (directly) solve those problems but it does provide a useful capability that could be part of a solution for those people who have complex styling requirements and are willing to do some coding.
What the patch does is allow elements (nodes, ways) to specify their garmin type (and a few other things) explicitly using these tags: mkgmap:gtype the element's type (integer constant) mkgmap:kind one of "node", "polyline", "polygon" (only polygon is used at this time to differentiate polygons from lines). mkgmap:minres the element's minimum resolution (needed to make element visible) mkgmap:maxres the element's maximum resolution (not required) mkgmap:roadclass the element's road class (needed for roads) mkgmap:roadspeed the element's road speed (needed for roads) If the mkgmap:gtype tag is present, the element will not be passed through the normal style file process at all. So how do these tags get added to the OSM data? Well, you could just add them with an editor but that would get boring pretty quickly so what I would expect to see is some kind of external filter program that reads the OSM file and outputs a new OSM file with the appropriate tags added. That filter program could be written in any language that has some XML processing support. Current issues to be sorted out are handling of the highway shields (not currently implemented) and also this feature is not compatible with the cycleway faking code. All feedback welcome. Cheers, Mark
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java index 2a549f8..03fdbda 100644 --- a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java +++ b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java @@ -144,6 +144,50 @@ public class StyledConverter implements OsmConverter { lineAdder = overlayAdder; } + public GType makeGTypeFromTags(Element element, int kind) { + String s = element.getTag("mkgmap:gtype"); + GType gt = new GType(kind, s); + element.setName(element.getTag("name")); + s = element.getTag("mkgmap:minres"); + if(s != null) { + try { + gt.setMinResolution(Integer.decode(s)); + } + catch (NumberFormatException nfe) { + log.error("Bad value for mkgmap:minres tag: " + s); + } + } + s = element.getTag("mkgmap:maxres"); + if(s != null) { + try { + gt.setMaxResolution(Integer.decode(s)); + } + catch (NumberFormatException nfe) { + log.error("Bad value for mkgmap:maxres tag: " + s); + } + } + s = element.getTag("mkgmap:roadclass"); + if(s != null) { + try { + gt.setRoadClass(Integer.decode(s)); + } + catch (NumberFormatException nfe) { + log.error("Bad value for mkgmap:roadclass tag: " + s); + } + } + s = element.getTag("mkgmap:roadspeed"); + if(s != null) { + try { + gt.setRoadClass(Integer.decode(s)); + } + catch (NumberFormatException nfe) { + log.error("Bad value for mkgmap:roadspeed tag: " + s); + } + } + + return gt; + } + /** * This takes the way and works out what kind of map feature it is and makes * the relevant call to the mapper callback. @@ -157,13 +201,22 @@ public class StyledConverter implements OsmConverter { if (way.getPoints().size() < 2) return; - preConvertRules(way); + GType foundType = null; + if(way.getTag("mkgmap:gtype") != null) { + if("polygon".equals(way.getTag("mkgmap:kind"))) + foundType = makeGTypeFromTags(way, GType.POLYGON); + else + foundType = makeGTypeFromTags(way, GType.POLYLINE); + } + else { + preConvertRules(way); - GType foundType = wayRules.resolveType(way); - if (foundType == null) - return; + foundType = wayRules.resolveType(way); + if (foundType == null) + return; - postConvertRules(way, foundType); + postConvertRules(way, foundType); + } if (foundType.getFeatureKind() == GType.POLYLINE) { if(foundType.isRoad()) @@ -182,13 +235,20 @@ public class StyledConverter implements OsmConverter { * @param node The node to convert. */ public void convertNode(Node node) { - preConvertRules(node); - GType foundType = nodeRules.resolveType(node); - if (foundType == null) - return; + GType foundType = null; + if(node.getTag("mkgmap:gtype") != null) { + foundType = makeGTypeFromTags(node, GType.POINT); + } + else { + preConvertRules(node); + + foundType = nodeRules.resolveType(node); + if (foundType == null) + return; - postConvertRules(node, foundType); + postConvertRules(node, foundType); + } addPoint(node, foundType); }
_______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev