org.oscim.core.Box Java Examples

The following examples show how to use org.oscim.core.Box. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuadTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean search(Box bbox, SearchCb<T> cb, Object context) {
    BoxItem<T> box = getBox(bbox);
    boolean finished = search(box, cb, context);
    boxPool.release(box);
    return finished;
}
 
Example #2
Source File: GmsMapsTypeHelper.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public static LatLngBounds toLatLngBounds(Box box) {
    double minLon = MercatorProjection.toLongitude(box.xmin);
    double maxLon = MercatorProjection.toLongitude(box.xmax);
    double minLat = MercatorProjection.toLatitude(box.ymax);
    double maxLat = MercatorProjection.toLatitude(box.ymin);
    if (Double.isNaN(minLon) || Double.isNaN(maxLon) || Double.isNaN(minLat) || Double.isNaN(maxLat))
        minLon = maxLon = minLat = maxLat = 0;
    return new LatLngBounds(new LatLng(minLat, minLon), new LatLng(maxLat, maxLon));
}
 
Example #3
Source File: QuadTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<T> search(Box bbox, List<T> results) {
    BoxItem<T> box = getBox(bbox);
    search(box, collectCb, results);
    boxPool.release(box);
    return results;
}
 
Example #4
Source File: QuadTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean remove(Box box, T item) {
    BoxItem<T> bbox = getBox(box);
    boolean ok = remove(bbox, item);
    boxPool.release(bbox);
    return ok;
}
 
Example #5
Source File: QuadTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private BoxItem<T> getBox(Box box) {
    BoxItem<T> it = boxPool.get();
    it.x1 = (int) box.xmin;
    it.y1 = (int) box.ymin;
    it.x2 = (int) box.xmax;
    it.y2 = (int) box.ymax;
    return it;
}
 
Example #6
Source File: RTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public List<T> search(Box bbox, List<T> results) {
    if (results == null)
        results = new ArrayList<T>(16);

    Rect r = getRect();
    r.set(bbox);

    //search(mRoot, r, results);
    searchStack(r, results);

    releaseRect(r);
    return results;
}
 
Example #7
Source File: RTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public boolean search(Box bbox, SearchCb<T> cb, Object context) {
    Rect r = getRect();
    r.set(bbox);

    searchStack(r, cb, context);

    releaseRect(r);
    return true;
}
 
Example #8
Source File: RTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public boolean remove(Box box, T item) {
    Rect r = getRect();
    r.set(box);
    boolean removed = removeRect(r, item);
    releaseRect(r);
    return removed;
}
 
Example #9
Source File: RTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void set(Box box) {
    if (DEBUG) {
        assert (box.xmin <= box.xmax);
        assert (box.ymin <= box.ymax);
    }
    xmin = box.xmin;
    ymin = box.ymin;
    xmax = box.xmax;
    ymax = box.ymax;
}
 
Example #10
Source File: RTree.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public Rect(Box box) {
    if (DEBUG) {
        assert (xmin <= xmax);
        assert (ymin <= ymax);
    }

    xmin = box.xmin;
    ymin = box.ymin;
    xmax = box.xmax;
    ymax = box.ymax;
}
 
Example #11
Source File: QuadTree.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void insert(Box box, T item) {
    insert(new BoxItem<T>(box, item));
}
 
Example #12
Source File: RTree.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public void insert(Box box, T item) {
    Rect r = getRect();
    r.set(box);
    insertRect(r, item, 0);
    releaseRect(r);
}
 
Example #13
Source File: Map.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public BoundingBox getBoundingBox(int expand) {
    Box box = new Box();
    mViewport.getBBox(box, expand);
    box.map2mercator();
    return new BoundingBox(box.ymin, box.xmin, box.ymax, box.xmax);
}
 
Example #14
Source File: AbstractVectorLayer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
 * running on worker thread
 */
@Override
public boolean doWork(Task t) {

    Box bbox;
    float[] box = new float[8];

    Viewport v = mMap.viewport().getSyncViewport();
    synchronized (v) {
        bbox = v.getBBox(null, 0);
        v.getMapExtents(box, 0);
        v.getMapPosition(t.position);
    }

    /* Hmm what is this for? */
    //    double scale = t.position.scale * Tile.SIZE;
    //    t.position.x = (long) (t.position.x * scale) / scale;
    //    t.position.y = (long) (t.position.y * scale) / scale;

    bbox.map2mercator();

    //    double xmin = bbox.xmin;
    //    double xmax = bbox.xmax;
    //    Box lbox = null;
    //    Box rbox = null;
    //    if (bbox.xmin < -180) {
    //        bbox.xmin = -180;
    //        lbox = new Box(bbox);
    //    }
    //    if (bbox.xmax > 180) {
    //        bbox.xmax = 180;
    //        rbox = new Box(bbox);
    //    }

    processFeatures(t, bbox);

    //if (lbox != null) {
    //    t.position.x += 1;
    //    lbox.xmax = 180;
    //    lbox.xmin = xmin + 180;
    //    processFeatures(t, lbox);
    //    t.position.x -= 1;
    //}
    //
    //if (rbox != null) {
    //    t.position.x -= 1;
    //    rbox.xmin = -180;
    //    rbox.xmax = xmax - 180;
    //    processFeatures(t, rbox);
    //    t.position.x += 1;
    //}

    t.buckets.prepare();

    mMap.render();
    return true;
}
 
Example #15
Source File: ItemizedLayer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
 * When a content sensitive action is performed the content item needs to be
 * identified. This method does that and then performs the assigned task on
 * that item.
 *
 * @return true if event is handled false otherwise
 */
protected boolean activateSelectedItems(MotionEvent event, ActiveItem task) {
    int size = mItemList.size();
    if (size == 0)
        return false;

    int eventX = (int) event.getX() - mMap.getWidth() / 2;
    int eventY = (int) event.getY() - mMap.getHeight() / 2;
    Viewport mapPosition = mMap.viewport();

    Box box = mapPosition.getBBox(null, 128);
    box.map2mercator();
    box.scale(1E6);

    int nearest = -1;
    int inside = -1;
    double insideY = -Double.MAX_VALUE;

    // squared dist: 50x50 px ~ 2mm on 400dpi
    // 20x20 px on baseline mdpi (160dpi)
    double dist = 20 * 20 * CanvasAdapter.getScale();

    for (int i = 0; i < size; i++) {
        Item item = mItemList.get(i);

        if (!box.contains(item.getPoint().longitudeE6,
                item.getPoint().latitudeE6))
            continue;

        mapPosition.toScreenPoint(item.getPoint(), mTmpPoint);

        float dx = (float) (mTmpPoint.x - eventX);
        float dy = (float) (mTmpPoint.y - eventY);

        MarkerSymbol it = item.getMarker();
        if (it == null)
            it = mMarkerRenderer.mDefaultMarker;

        if (it.isInside(dx, dy)) {
            if (mTmpPoint.y > insideY) {
                insideY = mTmpPoint.y;
                inside = i;
            }
        }
        if (inside >= 0)
            continue;

        double d = dx * dx + dy * dy;
        if (d > dist)
            continue;

        dist = d;
        nearest = i;
    }

    if (inside >= 0)
        nearest = inside;

    if (nearest >= 0 && task.run(nearest)) {
        mMarkerRenderer.update();
        mMap.render();
        return true;
    }
    return false;
}
 
Example #16
Source File: MapTrekTileLayer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onGesture(Gesture g, MotionEvent e) {
    if (!(g instanceof Gesture.Tap))
        return false;

    Point point = new Point();
    mMap.viewport().fromScreenPoint(e.getX(), e.getY(), point);

    Box box = mMap.viewport().getBBox(null, 128);

    double cs = mScale * Tile.SIZE;
    double distance = mFingerTipSize * mFingerTipSize / cs / cs;

    long nearest = 0L;

    for (int i = 0; i < mTileSet.cnt; i++) {
        MapTile t = mTileSet.tiles[i];
        AmenityTileData td = (AmenityTileData) t.getData(POI_DATA);
        if (td == null || td.amenities.isEmpty())
            continue;

        double dist = distance;

        int size = td.amenities.size();
        for (int j = 0; j < size; j++) {
            Pair<Point, Long> amenity = td.amenities.get(j);

            if (!box.contains(amenity.first))
                continue;

            double dx = amenity.first.x - point.x;
            double dy = amenity.first.y - point.y;

            double d = dx * dx + dy * dy;
            if (d > dist)
                continue;

            dist = d;
            nearest = amenity.second;
        }

    }

    if (nearest > 0L) {
        return mOnAmenityGestureListener != null &&
                mOnAmenityGestureListener.onAmenitySingleTapUp(nearest);
    }
    return false;
}
 
Example #17
Source File: ItemizedLayer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
   * When a content sensitive action is performed the content item needs to be
   * identified. This method does that and then performs the assigned task on
   * that item.
   *
   * @return true if event is handled false otherwise
   */
  protected boolean activateSelectedItems(MotionEvent event, ActiveItem task) {
      int size = mItemList.size();
      if (size == 0)
          return false;

      int eventX = (int) event.getX() - mMap.getWidth() / 2;
      int eventY = (int) event.getY() - mMap.getHeight() / 2;
      Viewport mapPosition = mMap.viewport();

      Box box = mapPosition.getBBox(null, 128);
      box.map2mercator();
      box.scale(1E6);

      int nearest = -1;
      int inside = -1;
      double insideY = -Double.MAX_VALUE;

/* squared dist: 50*50 pixel ~ 2mm on 400dpi */
      // TODO Use android tap size
      double dist = 2500;

      for (int i = 0; i < size; i++) {
          Item item = mItemList.get(i);

          if (!box.contains(item.getPoint().longitudeE6,
                  item.getPoint().latitudeE6))
              continue;

          mapPosition.toScreenPoint(item.getPoint(), mTmpPoint);

          float dx = (float) (mTmpPoint.x - eventX);
          float dy = (float) (mTmpPoint.y - eventY);

          MarkerSymbol it = item.getMarker();
          if (it == null)
              it = mMarkerRenderer.mDefaultMarker;

          if (it.isInside(dx, dy)) {
              if (mTmpPoint.y > insideY) {
                  insideY = mTmpPoint.y;
                  inside = i;
              }
          }
          if (inside >= 0)
              continue;

          double d = dx * dx + dy * dy;
          if (d > dist)
              continue;

          dist = d;
          nearest = i;
      }

      if (inside >= 0)
          nearest = inside;

      if (nearest >= 0 && task.run(nearest)) {
          mMarkerRenderer.update();
          mMap.render();
          return true;
      }
      return false;
  }
 
Example #18
Source File: SpatialIndex.java    From trekarta with GNU General Public License v3.0 votes vote down vote up
public void insert(Box box, T item); 
Example #19
Source File: SpatialIndex.java    From trekarta with GNU General Public License v3.0 votes vote down vote up
public boolean remove(Box box, T item); 
Example #20
Source File: SpatialIndex.java    From trekarta with GNU General Public License v3.0 votes vote down vote up
public List<T> search(Box bbox, List<T> results); 
Example #21
Source File: SpatialIndex.java    From trekarta with GNU General Public License v3.0 votes vote down vote up
public boolean search(Box bbox, SearchCb<T> cb, Object context); 
Example #22
Source File: AbstractVectorLayer.java    From trekarta with GNU General Public License v3.0 votes vote down vote up
abstract protected void processFeatures(Task t, Box b);