[OSM-dev] Addition to JOSM - 'map style' display
Nick Whitelegg
Nick.Whitelegg at solent.ac.uk
Fri Sep 15 17:04:29 BST 2006
I have now added some code to JOSM (downloaded revision 141) to optionally
display different types of way in different colours depending on tags.
Additionally, points of interest are shown as annotated icons, using the
same icons as the slippy map and Freemap.
This is the approach I have taken - any feedback would be appreciated. I
also describe what I've done at the code level - Imi, hope I'm taking the
approach which fits in best with the rest of the application.
Firstly, the optional 'map style' display mode is turned on by a line in
the preferences:
draw.mapstyle = true
Secondly, the look and feel of the 'map style' display is governed by a
very simple XML format, similar to the Freemap rules file, which covers
linear ways, areas and POI nodes:
<rules>
<rule>
<tag k="highway" v="footway"/>
<line width="1" colour="#00ff00"/> <!--green line width 1 pixel -->
</rule>
<rule>
<tag k="amenity" v="pub"/>
<icon src="pub.png" annotate="true"/> <!-- annotate=true means show the
name besides the icon-->
</rule>
<rule>
<tag k="natural" v="water"/>
<area colour="#0000ff"/> <!-- blue filled polygon -->
</rule>
</rules>
At the moment it matches *one* key/value pair to *one* style - it cannot
deal with styles defined by more than one key/value pair. This means, for
example, that anything with highway=footway comes out green, whether a
public or permissive footpath. But I guess since we're talking about an
editor, not a full-scale renderer, this isn't a big deal. I guess ideally
it could use the osmarender approach, though this would I imagine be
significantly more complex to parse.
Down to the code level, and this is the approach I have taken, following
some of Imi's suggestions:
- In OsmDataLayer.java I instantiate either a SimplePaintVisitor or a
MapPaintVisitor (see below) depending on whether the draw.mapstyle
preference is set (see above)
- MapPaintVisitor inherits from SimplePaintVisitor (maybe an abstract
PaintVisitor could be designed) and renders the OSM data layer using the
styles from the XML, above.
- There are also some new classes to parse the XML governing the styles.
To try and maximise performance I store the styles in a HashMap with the
keys of the HashMap, the key-value pair e.g. "highway=footway".
Once I've done a few real-world tests on it, I'll make it available as a
jar - Imi, do you want my new code to add to JOSM or should I make some
alterations on the above scheme?
Nick
More information about the dev
mailing list