diff --git a/src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java b/src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java index b669793..7375784 100644 --- a/src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java +++ b/src/uk/me/parabola/imgfmt/app/lbl/PlacesFile.java @@ -33,7 +33,7 @@ import uk.me.parabola.imgfmt.app.Label; public class PlacesFile { private final Map countries = new LinkedHashMap(); private final Map regions = new LinkedHashMap(); - private final Map cities = new LinkedHashMap(); + private final List cities = new ArrayList(); private final Map postalCodes = new LinkedHashMap(); private final List pois = new ArrayList(); @@ -62,7 +62,7 @@ public class PlacesFile { r.write(writer); placeHeader.endRegions(writer.position()); - for (City c : cities.values()) + for (City c : cities) c.write(writer); placeHeader.endCity(writer.position()); @@ -108,7 +108,7 @@ public class PlacesFile { Label l = lblFile.newLabel(name); c.setLabel(l); // label may be ignored if pointref is set - cities.put(name, c); + cities.add(c); return c; } @@ -118,7 +118,7 @@ public class PlacesFile { Label l = lblFile.newLabel(name); c.setLabel(l); // label may be ignored if pointref is set - cities.put(name, c); + cities.add(c); return c; } diff --git a/src/uk/me/parabola/mkgmap/build/MapBuilder.java b/src/uk/me/parabola/mkgmap/build/MapBuilder.java index cd6b8c2..0dd8a52 100644 --- a/src/uk/me/parabola/mkgmap/build/MapBuilder.java +++ b/src/uk/me/parabola/mkgmap/build/MapBuilder.java @@ -83,7 +83,7 @@ public class MapBuilder implements Configurable { private static final int CLEAR_TOP_BITS = (32 - 15); private final java.util.Map poimap = new HashMap(); - private final SortedMap sortedCities = new TreeMap(); + private final SortedMap sortedCities = new TreeMap(); private boolean doRoads; private Country country; @@ -168,19 +168,27 @@ public class MapBuilder implements Configurable { private void processPOIs(Map map, MapDataSource src) { LBLFile lbl = map.getLblFile(); - // collect the names of the cities + // gpsmapedit doesn't sort the city names so to be + // friendly we generate the city objects in alphabetic + // order - to do that we first build a map from city + // name to the associated MapPoint - we don't want to + // be fooled by duplicate names so suffix the name + // with the object to make it unique for (MapPoint p : src.getPoints()) { if(p.isCity() && p.getName() != null) - sortedCities.put(p.getName(), null); + sortedCities.put(p.getName() + "@" + p, p); } - // create the city records in alphabetic order + // now loop through the sorted keys and retrieve + // the MapPoint associated with the key - now we + // can create the City object and remember it for later for (String s : sortedCities.keySet()) { + MapPoint p = (MapPoint)sortedCities.get(s); City c; if(region != null) - c = lbl.createCity(region, s); + c = lbl.createCity(region, p.getName()); else - c = lbl.createCity(country, s); + c = lbl.createCity(country, p.getName()); sortedCities.put(s, c); } // TODO: this is temporarily removed, but should be put back @@ -449,8 +457,10 @@ public class MapBuilder implements Configurable { p.setLongitude(coord.getLongitude()); if(div.getZoom().getLevel() == 0 && name != null) { - City c = sortedCities.get(name); - + // retrieve the City created earlier for + // this point and store the point info + // in it + City c = (City)sortedCities.get(name + "@" + point); if(pointIndex > 255) { System.err.println("Can't set city point index for " + name + " (too many indexed points in division)\n"); } else {