예제 #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);
  }
예제 #2
0
 /**
  * @param directionsWaiter object waiting for directions result
  * @param baseurl baseurl for the service
  * @param language used language
  * @param routeStart star point for route (in WGS84)
  * @param routeEnd end point for route (in WGS84)
  */
 public OpenLSDirections(
     final DirectionsWaiter directionsWaiter,
     final String baseurl,
     final String language,
     final WgsPoint routeStart,
     final WgsPoint routeEnd) {
   this.directionsWaiter = directionsWaiter;
   final StringBuffer url = new StringBuffer(Utils.prepareForParameters(baseurl));
   url.append("out=openls&t=d&saddr=").append(Tools.urlEncode(routeStart.getLat() + "N, "));
   url.append(Tools.urlEncode(routeStart.getLon() + "E"));
   url.append("&daddr=").append(Tools.urlEncode(routeEnd.getLat() + "N, "));
   url.append(Tools.urlEncode(routeEnd.getLon() + "E")).append("&lang=");
   url.append(language).append("&gzip=yes");
   routeUrl = url.toString();
 }
예제 #3
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    onRetainCalled = false;

    mapComponent =
        new BasicMapComponent(
            "c7e1249ffc03eb9ded908c236bd1996d4c62dbae56a439.28554625",
            "CycleStreets",
            "CycleStreets",
            1,
            1,
            CAMBRIDGE,
            10);

    mapComponent.setMap(new CloudMade("13ed67dfecf44b5a8d9dc3ec49268ba0", "DEVICE_UID", 64, 1));
    mapComponent.setPanningStrategy(new ThreadDrivenPanning());
    mapComponent.setControlKeysHandler(new AndroidKeysHandler());
    mapComponent.setOnMapElementListener(this);
    mapComponent.startMapping();
    mapView = new MapView(this, mapComponent);

    PlaceIcon icon = new PlaceIcon(Utils.createImage("/res/drawable-mdpi/icon.png"));
    mapComponent.addPlace(new Place(0, "foo", icon, CAMBRIDGE));

    // add map listener
    //    WrapperMapListener wml = new WrapperMapListener(mapView);
    //    mapComponent.setMapListener(wml);
    //    wml.addListener(new MapAdapter() {
    //    	public void mapMoved() {
    //            WgsBoundingBox bounds = mapComponent.getBoundingBox();
    //            WgsPoint center = bounds.getBoundingBoxCenter();
    //            int zoom = mapComponent.getZoom();
    //            WgsPoint sw = bounds.getWgsMin();
    //            WgsPoint ne = bounds.getWgsMax();
    //            double n = ne.getLat();
    //            double s = sw.getLat();
    //            double e = ne.getLon();
    //            double w = sw.getLon();
    //            Log.d(getClass().getSimpleName(), "north: " + n);
    //            Log.d(getClass().getSimpleName(), "south: " + s);
    //            Log.d(getClass().getSimpleName(), "east: " + e);
    //            Log.d(getClass().getSimpleName(), "west: " + w);
    //
    //            try {
    //            	List<Photo> photos = apiClient.getPhotos(center, zoom, n, s, e, w);
    //            	Log.d(getClass().getSimpleName(), "got photos: " + photos.size());
    //            	Log.d(getClass().getSimpleName(), photos.get(0).caption);
    //            }
    //            catch (Exception ex) {
    //            	throw new RuntimeException(ex);
    //            }
    //    	}
    //    });

    // Add ZoomControls
    zoomControls = new ZoomControls(this);
    zoomControls.setOnZoomInClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapComponent.zoomIn();
          }
        });
    zoomControls.setOnZoomOutClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            mapComponent.zoomOut();
          }
        });

    // GPS Location
    final LocationSource locationSource =
        new AndroidGPSProvider((LocationManager) getSystemService(Context.LOCATION_SERVICE), 1000L);
    final LocationMarker marker =
        new NutiteqLocationMarker(
            new PlaceIcon(Utils.createImage("/res/drawable-mdpi/icon.png"), 5, 17), 3000, true);
    locationSource.setLocationMarker(marker);
    mapComponent.setLocationSource(locationSource);

    final RelativeLayout relativeLayout = new RelativeLayout(this);
    setContentView(relativeLayout);
    final RelativeLayout.LayoutParams mapViewLayoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    relativeLayout.addView(mapView, mapViewLayoutParams);

    // Add Zoom controls View to the RelativeLayout
    final RelativeLayout.LayoutParams zoomControlsLayoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    relativeLayout.addView(zoomControls, zoomControlsLayoutParams);
  }
예제 #4
0
 /**
  * Set tiles per file.
  *
  * @param tilesPerFile new value for tiles per file
  */
 public void setTilesPerFile(final int tilesPerFile) {
   this.tilesPerFile = tilesPerFile;
   final int tpflog = Utils.log2(tilesPerFile);
   tpfx = 1 << (tpflog / 2 + tpflog % 2);
   tpfy = 1 << (tpflog / 2);
 }