Index: POIRecord.java =================================================================== --- POIRecord.java (revision 104) +++ POIRecord.java (working copy) @@ -47,8 +47,8 @@ private Label streetName; private Label streetNumberName; // Used for numbers such as 221b - private char cityIndex; - private char zipIndex; + private char cityIndex = 0; + private char zipIndex = 0; private String phoneNumber; @@ -59,8 +59,19 @@ public void setStreetName(Label label) { this.streetName = label; } + + public void setZipIndex(int zipIndex) + { + this.zipIndex = (char) zipIndex; + } + + public void setCityIndex(int cityIndex) + { + this.cityIndex = (char) cityIndex; + } - void write(ImgFileWriter writer, byte POIGlobalFlags, int realofs) { + void write(ImgFileWriter writer, byte POIGlobalFlags, int realofs, + long numCities, long numZips) { assert offset == realofs; int ptr = poiName.getOffset(); @@ -69,31 +80,104 @@ writer.put3(ptr); if (POIGlobalFlags != getPOIFlags()) - writer.put(getPOIFlags()); + writer.put(getWrittenPOIFlags(POIGlobalFlags)); if (streetName != null) writer.put3(streetName.getOffset()); + + if (cityIndex > 0) + { + if(numCities > 255) + writer.putChar(cityIndex); + else + writer.put((byte)cityIndex); + } + + if (zipIndex > 0) + { + if(numZips > 255) + writer.putChar(zipIndex); + else + writer.put((byte)zipIndex); + } } byte getPOIFlags() { byte b = 0; if (streetName != null) b |= HAS_STREET; + if (cityIndex > 0) + b |= HAS_CITY; + if (zipIndex > 0) + b |= HAS_ZIP; return b; } + + byte getWrittenPOIFlags(byte POIGlobalFlags) + { + int mask; + int flag = 0; + int j = 0; + + int usedFields = getPOIFlags(); + + /* the local POI flag is really tricky + if a bit is not set in the global mask + we have to skip this bit in the local mask. + In other words the meaning of the local bits + change influenced by the global bits */ + + for(byte i = 0; i < 6; i++) + { + mask = 1 << i; + + if((mask & POIGlobalFlags) == mask) + { + if((mask & usedFields) == mask) + flag = flag | (1 << j); + j++; + } + + } + return (byte) flag; + } /** * Sets the start offset of this POIRecord * * \return Number of bytes needed by this entry */ - int calcOffset(int ofs, byte POIGlobalFlags) { + int calcOffset(int ofs, byte POIGlobalFlags, long numCities, long numZips) { offset = ofs; int size = 3; if (POIGlobalFlags != getPOIFlags()) size += 1; if (streetName != null) size += 3; + if (cityIndex > 0) + { + /* + depending on how many cities are in the LBL block we have + to write one or two bytes + */ + + if(numCities > 255) + size += 2; + else + size += 1; + } + if (zipIndex > 0) + { + /* + depending on how many zips are in the LBL block we have + to write one or two bytes + */ + + if(numZips > 255) + size += 2; + else + size += 1; + } return size; } Index: PlacesFile.java =================================================================== --- PlacesFile.java (revision 104) +++ PlacesFile.java (working copy) @@ -70,7 +70,7 @@ byte poiglobalflags = placeHeader.getPOIGlobalFlags(); for (POIRecord p : pois) p.write(writer, poiglobalflags, - writer.position() - poistart); + writer.position() - poistart, cities.size(), postalCodes.size()); placeHeader.endPOI(writer.position()); for (Zip z : postalCodes.values()) @@ -79,7 +79,7 @@ } Country createCountry(String name, String abbr) { - Country c = new Country(countries.size()); + Country c = new Country(countries.size()+1); String s = abbr != null ? name + 0x1d + abbr : name; @@ -91,7 +91,7 @@ } Region createRegion(Country country, String name) { - Region r = new Region(country, regions.size()); + Region r = new Region(country, regions.size()+1); Label l = lblFile.newLabel(name); r.setLabel(l); @@ -101,7 +101,7 @@ } City createCity(Region region, String name) { - City c = new City(region, cities.size()); + City c = new City(region, cities.size()+1); Label l = lblFile.newLabel(name); c.setLabel(l); @@ -111,7 +111,7 @@ } Zip createZip(String code) { - Zip z = new Zip(postalCodes.size()); + Zip z = new Zip(postalCodes.size()+1); Label l = lblFile.newLabel(code); z.setLabel(l); @@ -143,6 +143,6 @@ int ofs = 0; for (POIRecord p : pois) - ofs += p.calcOffset(ofs, poiFlags); + ofs += p.calcOffset(ofs, poiFlags, cities.size(), postalCodes.size()); } } Index: City.java =================================================================== --- City.java (revision 104) +++ City.java (working copy) @@ -26,7 +26,7 @@ * @author Steve Ratcliffe */ public class City { - private static final int POINT_REF = 0x80; + private static final int POINT_REF = 0x8000; private final int index; Index: LBLFile.java =================================================================== --- LBLFile.java (revision 104) +++ LBLFile.java (working copy) @@ -138,7 +138,24 @@ public POIRecord createPOI(String name) { return places.createPOI(name); } + + public Country createCountry(String name, String abbr) { + return places.createCountry(name, abbr); + } + + public Region createRegion(Country country, String region) { + return places.createRegion(country, region); + } + + public City createCity(Region region, String city) { + return places.createCity(region, city); + } + public Zip createZip(String code) { + return places.createZip(code); + } + + public void allPOIsDone() { places.allPOIsDone(); }