Ejemplo n.º 1
0
  public StoredMapConfig readConfig(final FileSystem fs) {
    try {
      final String filename = path + "/" + CONFIG_FILENAME;
      final byte[] data = fs.readFile(filename);
      final String sdata = new String(data);
      final String[] lines = Utils.split(sdata, "\n");
      for (int i = 0; i < lines.length; i++) {
        // split into at most 2 tokens
        final String[] tokens = Tools.split(lines[i].trim(), '=', false, 2);
        if (tokens.length == 2) {
          final String name = tokens[0].trim().toLowerCase();
          final String value = tokens[1].trim();

          // ignore empty values
          if (value.length() == 0) {
            continue;
          }

          // ignore comments
          if (name.startsWith("#")) {
            continue;
          }

          if (name.equals("tiles_per_file")) {
            final int tpf = Integer.parseInt(value);
            if (tpf > 0 && (tpf & (-tpf)) == tpf) {
              setTilesPerFile(tpf);
            } else {
              throw new IOException("Invalid tiles_per_file");
            }
          } else if (name.equals("hash_size")) {
            final int hs = Integer.parseInt(value);
            if (hs >= 1 && hs < 100) {
              setHashSize(hs);
            } else {
              throw new IOException("Invalid hash_size");
            }
          } else if (name.equals("center")) {
            try {
              final String[] xyz = Tools.split(value.trim(), ',', false, 4);
              double lat = Float.parseFloat(xyz[0].trim());
              double lon = Float.parseFloat(xyz[1].trim());
              int zoom = Integer.parseInt(xyz[2].trim());
              Log.debug("center zoom found = " + lat + " " + lon + " " + zoom);
              setCenterLocation(new WgsPoint(lon, lat), zoom);
            } catch (final Exception ex) {

              throw new IOException("invalid center location");
            }
          }
        }
      }
    } catch (final IOException ex) {
      Log.error("Error reading " + CONFIG_FILENAME);
      Log.printStackTrace(ex);
      return null;
    }
    return new StoredMapConfig(tilesPerFile, tpfx, tpfy, hashSize);
  }