As I said in the previous post I needed to find a more manageable way of parameterising the features.

I initially toyed with the idea of a simple properties flat file. This would be okay for about a dozen features but after that is becomes harder to maintain the file.

I have decided to implement a json configuration file. I chose this route for a number of reasons:

  1. This allows me to make the features hierarchical.
  2. Using a decent json editor more easy to maintain.
  3. Making the features hierarchical means that it maintains the hierarchy specified by open street maps.
  4. Allows me to make the features 100% configurable and not at all hard-coded.

Here is an extract of the json file produced:

{
	"features":{
		"amenity":{
			"features":{
				"sustenance":{
					"features":{
						"bar":{
							"render":{
								"zoom":10,
								"type":"image",
								"image":"data/symbols/bar.p.20.png"
							}							
						},
						"restaurant":{
							"render":{
								"zoom":10,
								"type":"image",
								"image":"data/symbols/restaurant.p.16.png"
							}							
						},
						"pub":{
							"render":{
								"zoom":10,
								"type":"image",
								"image":"data/symbols/pub.png"
							}							
						}	
					}						
				}
			}
		},

Here is a screenshot of the eclipse json jsoneditor plugin in action:

 

 

 

Here is an extract of the renderer. It is much now much simpler.

for (Way way : map.getWays()) {
    progress++;
    msd.progress = progress;
    doNotify(msd);

    Feature featureToDraw = Features.getMainType(way);
    if (featureToDraw.equals(Features.unknownFeature)) {
        continue;
    }
    PLayer layer = getLayer(featureToDraw);

    if (featureToDraw.isArea()) {
        drawArea(layer, map, way, featureToDraw, true);
    }
    if (featureToDraw.isLine()) {
        drawLine(layer, map, way, featureToDraw, false);
    }
    if (featureToDraw.isImage()) {
        drawImage(layer, map, way, featureToDraw);
    }
}
Parameterisation of features