コード例 #1
0
  public void parse(int eLevel, boolean show_closed, BoundingBoxE6 boundingBox) {
    // get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {

      // get a new instance of parser
      SAXParser sp = spf.newSAXParser();

      // parse the file and also register this class for call backs

      HttpClient httpClient = new DefaultHttpClient();
      HttpContext localContext = new BasicHttpContext();
      List<NameValuePair> qparams = new ArrayList<NameValuePair>();
      qparams.add(
          new BasicNameValuePair("l", "" + String.valueOf(boundingBox.getLonWestE6() / 1E6)));
      qparams.add(
          new BasicNameValuePair("b", "" + String.valueOf(boundingBox.getLatSouthE6() / 1E6)));
      qparams.add(
          new BasicNameValuePair("r", "" + String.valueOf(boundingBox.getLonEastE6() / 1E6)));
      qparams.add(
          new BasicNameValuePair("t", "" + String.valueOf(boundingBox.getLatNorthE6() / 1E6)));
      if (!show_closed) {
        qparams.add(new BasicNameValuePair("open", "1"));
      }
      URI uri;
      uri =
          URIUtils.createURI(
              "http",
              "openstreetbugs.schokokeks.org",
              -1,
              "/api/0.1/getGPX",
              URLEncodedUtils.format(qparams, "UTF-8"),
              null);
      HttpGet httpget = new HttpGet(uri);

      HttpResponse response = httpClient.execute(httpget, localContext);

      org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OpenFixMapActivity.class);
      logger.info("Fetch " + httpget.getURI());

      sp.parse(response.getEntity().getContent(), this);

    } catch (SAXException se) {
      se.printStackTrace();
    } catch (ParserConfigurationException pce) {
      pce.printStackTrace();
    } catch (IOException ie) {
      ie.printStackTrace();
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #2
0
 private String getUrlInside(BoundingBoxE6 bb, String type, int maxResults) {
   StringBuffer urlString = getCommonUrl(type, maxResults);
   urlString.append(
       "&viewbox="
           + bb.getLonWestE6() * 1E-6
           + ","
           + bb.getLatNorthE6() * 1E-6
           + ","
           + bb.getLonEastE6() * 1E-6
           + ","
           + bb.getLatSouthE6() * 1E-6);
   return urlString.toString();
 }
コード例 #3
0
ファイル: DirectorySynchronizer.java プロジェクト: bailuk/AAT
    private ContentValues createContentValues(
        String pathname, String filename, GpxBigDeltaInterface summary) {

      BoundingBoxE6 box = summary.getBoundingBox().toBoundingBoxE6();

      ContentValues content = new ContentValues();
      content.put(GpxDbConstants.KEY_PATHNAME_OLD, pathname);
      content.put(GpxDbConstants.KEY_FILENAME, filename);
      content.put(GpxDbConstants.KEY_AVG_SPEED, summary.getSpeed());
      content.put(GpxDbConstants.KEY_MAX_SPEED, summary.getMaximumSpeed());
      content.put(GpxDbConstants.KEY_DISTANCE, summary.getDistance());
      content.put(GpxDbConstants.KEY_START_TIME, summary.getStartTime());
      content.put(GpxDbConstants.KEY_TOTAL_TIME, summary.getTimeDelta());
      content.put(GpxDbConstants.KEY_END_TIME, summary.getEndTime());
      content.put(GpxDbConstants.KEY_PAUSE, summary.getPause());
      content.put(GpxDbConstants.KEY_TYPE_ID, summary.getType());
      content.put(GpxDbConstants.KEY_EAST_BOUNDING, box.getLonEastE6());
      content.put(GpxDbConstants.KEY_WEST_BOUNDING, box.getLonWestE6());
      content.put(GpxDbConstants.KEY_NORTH_BOUNDING, box.getLatNorthE6());
      content.put(GpxDbConstants.KEY_SOUTH_BOUNDING, box.getLatSouthE6());
      return content;
    }
コード例 #4
0
ファイル: MapController.java プロジェクト: xiorcal/COR3F
  // TODO rework zoomToSpan
  @Override
  public void zoomToSpan(final int reqLatSpan, final int reqLonSpan) {
    if (reqLatSpan <= 0 || reqLonSpan <= 0) {
      return;
    }

    final BoundingBoxE6 bb = this.mOsmv.getBoundingBox();
    final int curZoomLevel = this.mOsmv.getZoomLevel();

    final int curLatSpan = bb.getLatitudeSpanE6();
    final int curLonSpan = bb.getLongitudeSpanE6();

    final float diffNeededLat = (float) reqLatSpan / curLatSpan; // i.e. 600/500 = 1,2
    final float diffNeededLon = (float) reqLonSpan / curLonSpan; // i.e. 300/400 = 0,75

    final float diffNeeded = Math.max(diffNeededLat, diffNeededLon); // i.e. 1,2

    if (diffNeeded > 1) { // Zoom Out
      this.mOsmv.setZoomLevel(curZoomLevel - MyMath.getNextSquareNumberAbove(diffNeeded));
    } else if (diffNeeded < 0.5) { // Can Zoom in
      this.mOsmv.setZoomLevel(curZoomLevel + MyMath.getNextSquareNumberAbove(1 / diffNeeded) - 1);
    }
  }
コード例 #5
0
ファイル: EfficientPolyline.java プロジェクト: Crazyphil/EGO
  protected void drawOld(final Canvas canvas, final MapView mapView, final boolean shadow) {

    if (shadow) {
      return;
    }

    final int size = this.mPoints.size();
    if (size < 2) {
      // nothing to paint
      return;
    }

    final Projection pj = mapView.getProjection();

    // precompute new points to the intermediate projection.
    precomputePoints(pj);

    Point screenPoint0 = null; // points on screen
    Point screenPoint1;
    Point projectedPoint0; // points from the points list
    Point projectedPoint1;

    // clipping rectangle in the intermediate projection, to avoid performing projection.
    BoundingBoxE6 boundingBox = pj.getBoundingBox();
    Point topLeft =
        pj.toProjectedPixels(boundingBox.getLatNorthE6(), boundingBox.getLonWestE6(), null);
    Point bottomRight =
        pj.toProjectedPixels(boundingBox.getLatSouthE6(), boundingBox.getLonEastE6(), null);
    final Rect clipBounds = new Rect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
    // take into account map orientation:
    if (mapView.getMapOrientation() != 0.0f)
      GeometryMath.getBoundingBoxForRotatatedRectangle(
          clipBounds, mapView.getMapOrientation(), clipBounds);

    mPath.rewind();
    projectedPoint0 = this.mPoints.get(size - 1);
    mLineBounds.set(projectedPoint0.x, projectedPoint0.y, projectedPoint0.x, projectedPoint0.y);

    for (int i = size - 2; i >= 0; i--) {
      // compute next points
      projectedPoint1 = this.mPoints.get(i);
      mLineBounds.union(projectedPoint1.x, projectedPoint1.y);

      if (!Rect.intersects(clipBounds, mLineBounds)) {
        // skip this line, move to next point
        projectedPoint0 = projectedPoint1;
        screenPoint0 = null;
        continue;
      }

      // the starting point may be not calculated, because previous segment was out of clip
      // bounds
      if (screenPoint0 == null) {
        screenPoint0 = pj.toPixelsFromProjected(projectedPoint0, this.mTempPoint1);
        mPath.moveTo(screenPoint0.x, screenPoint0.y);
      }

      screenPoint1 = pj.toPixelsFromProjected(projectedPoint1, this.mTempPoint2);

      // skip this point, too close to previous point
      if (Math.abs(screenPoint1.x - screenPoint0.x) + Math.abs(screenPoint1.y - screenPoint0.y)
          <= 1) {
        continue;
      }

      mPath.lineTo(screenPoint1.x, screenPoint1.y);

      // update starting point to next position
      projectedPoint0 = projectedPoint1;
      screenPoint0.x = screenPoint1.x;
      screenPoint0.y = screenPoint1.y;
      mLineBounds.set(projectedPoint0.x, projectedPoint0.y, projectedPoint0.x, projectedPoint0.y);
    }

    canvas.drawPath(mPath, mPaint);
  }
コード例 #6
0
ファイル: MapController.java プロジェクト: xiorcal/COR3F
 public void zoomToSpan(final BoundingBoxE6 bb) {
   zoomToSpan(bb.getLatitudeSpanE6(), bb.getLongitudeSpanE6());
 }
コード例 #7
0
  @Override
  public Road getRoad(ArrayList<GeoPoint> waypoints) {
    String url = getUrl(waypoints);
    Log.d(BonusPackHelper.LOG_TAG, "OSRMRoadManager.getRoad:" + url);

    // String jString = BonusPackHelper.requestStringFromUrl(url);
    HttpConnection connection = new HttpConnection();
    connection.setUserAgent(mUserAgent);
    connection.doGet(url);
    String jString = connection.getContentAsString();
    connection.close();

    if (jString == null) {
      Log.e(BonusPackHelper.LOG_TAG, "OSRMRoadManager::getRoad: request failed.");
      return new Road(waypoints);
    }
    Locale l = Locale.getDefault();
    HashMap<String, String> directions = (HashMap<String, String>) DIRECTIONS.get(l.getLanguage());
    if (directions == null) directions = (HashMap<String, String>) DIRECTIONS.get("en");
    Road road = new Road();
    try {
      JSONObject jObject = new JSONObject(jString);
      road.mStatus = jObject.getInt("status");
      String route_geometry = jObject.getString("route_geometry");
      road.mRouteHigh = PolylineEncoder.decode(route_geometry, 1, false);
      JSONArray jInstructions = jObject.getJSONArray("route_instructions");
      int n = jInstructions.length();
      RoadNode lastNode = null;
      for (int i = 0; i < n; i++) {
        JSONArray jInstruction = jInstructions.getJSONArray(i);
        RoadNode node = new RoadNode();
        int positionIndex = jInstruction.getInt(3);
        node.mLocation = road.mRouteHigh.get(positionIndex);
        node.mLength = jInstruction.getInt(2) / 1000.0;
        node.mDuration = jInstruction.getInt(4); // Segment duration in seconds.
        String direction = jInstruction.getString(0);
        String roadName = jInstruction.getString(1);
        if (lastNode != null && "1".equals(direction) && "".equals(roadName)) {
          // node "Continue" with no road name is useless, don't add it
          lastNode.mLength += node.mLength;
          lastNode.mDuration += node.mDuration;
        } else {
          node.mManeuverType = getManeuverCode(direction);
          node.mInstructions = buildInstructions(direction, roadName, directions);
          // Log.d(BonusPackHelper.LOG_TAG, direction+"=>"+node.mManeuverType+";
          // "+node.mInstructions);
          road.mNodes.add(node);
          lastNode = node;
        }
      }
      JSONObject jSummary = jObject.getJSONObject("route_summary");
      road.mLength = jSummary.getInt("total_distance") / 1000.0;
      road.mDuration = jSummary.getInt("total_time");
    } catch (JSONException e) {
      road.mStatus = Road.STATUS_TECHNICAL_ISSUE;
      e.printStackTrace();
    }
    if (road.mStatus != Road.STATUS_OK) {
      // Create default road:
      int status = road.mStatus;
      road = new Road(waypoints);
      road.mStatus = status;
    } else {
      road.buildLegs(waypoints);
      road.mBoundingBox = BoundingBoxE6.fromGeoPoints(road.mRouteHigh);
      road.mStatus = Road.STATUS_OK;
    }
    Log.d(BonusPackHelper.LOG_TAG, "OSRMRoadManager.getRoad - finished");
    return road;
  }