Java Code Examples for org.oscim.core.MercatorProjection#project()

The following examples show how to use org.oscim.core.MercatorProjection#project() . 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: MarkerRenderer.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
protected void populate(int size) {

        InternalItem[] tmp = new InternalItem[size];

        for (int i = 0; i < size; i++) {
            InternalItem it = new InternalItem();
            tmp[i] = it;
            it.item = mMarkerLayer.createItem(i);

            /* pre-project points */
            MercatorProjection.project(it.item.getPoint(), mMapPoint);
            it.px = mMapPoint.x;
            it.py = mMapPoint.y;
        }
        synchronized (this) {
            mUpdate = true;
            mItems = tmp;
        }
    }
 
Example 2
Source File: MarkerRenderer.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
void populate(int size) {

        InternalItem[] tmp = new InternalItem[size];

        for (int i = 0; i < size; i++) {
            InternalItem it = new InternalItem();
            tmp[i] = it;
            it.item = mMarkerLayer.createItem(i);

			/* pre-project polygonPoints */
            MercatorProjection.project(it.item.getPoint(), mMapPoint);
            it.px = mMapPoint.x;
            it.py = mMapPoint.y;
        }
        synchronized (this) {
            mUpdate = true;
            mItems = tmp;
        }
    }
 
Example 3
Source File: ClusterMarkerRenderer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Repopulates item list clustering close markers. This is triggered from update() when
   * a significant change in scale has happened.
   *
   * @param size  Item list size
   * @param scale current map scale
   */
  private void repopulateCluster(int size, double scale) {
      /* the grid slot size in px. increase to group more aggressively. currently set to marker size */
      final int GRIDSIZE = ScreenUtils.getPixels(MAP_GRID_SIZE_DP);

/* the factor to map into Grid Coordinates (discrete squares of GRIDSIZE x GRIDSIZE) */
      final double factor = (scale / GRIDSIZE);

      InternalItem.Clustered[] tmp = new InternalItem.Clustered[size];

      // clear grid map to count items that share the same "grid slot"
      mGridMap.clear();

      for (int i = 0; i < size; i++) {
          InternalItem.Clustered it = tmp[i] = new InternalItem.Clustered();

          it.item = mMarkerLayer.createItem(i);

	/* pre-project points */
          MercatorProjection.project(it.item.getPoint(), mMapPoint);
          it.px = mMapPoint.x;
          it.py = mMapPoint.y;

          // items can be declared non-clusterable
          if (!(it.item instanceof MarkerItem.NonClusterable)) {

              final int
                      absposx = (int) (it.px * factor),             // absolute item X position in the grid
                      absposy = (int) (it.py * factor),             // absolute item Y position
                      maxcols = (int) factor,                       // Grid number of columns
                      itemGridIndex = absposx + absposy * maxcols;  // Index in the sparsearray map

              // we store in the linear sparsearray the index of the marker,
              // ie, index = y * maxcols + x; array[index} = markerIndex

              // Lets check if there's already an item in the grid slot
              final int storedIndexInGridSlot = mGridMap.get(itemGridIndex, -1);

              if (storedIndexInGridSlot == -1) {
                  // no item at that grid position. The grid slot is free so let's
                  // store this item "i" (we identify every item by its InternalItem index)

                  mGridMap.put(itemGridIndex, i);
                  //Log.v(TAG, "UNclustered item at " + itemGridIndex);
              } else {
                  // at that grid position there's already a marker index
                  // mark this item as clustered out, so it will be skipped in the update() call

                  it.clusteredOut = true;

                  // and increment the count on its "parent" that will from now on act as a cluster
                  tmp[storedIndexInGridSlot].clusterSize++;

                  //Log.v(TAG, "Clustered item at " + itemGridIndex + ", \'parent\' size " + (tmp[storedIndexInGridSlot].clusterSize));
              }
          }
      }

      /* All ready for update. */
      synchronized (this) {
          mUpdate = true;
          mItems = tmp;
      }
  }
 
Example 4
Source File: MapObjectLayer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
InternalItem(MapObject item) {
    this.item = item;
    MercatorProjection.project(item.coordinates, mMapPoint);
    px = mMapPoint.x;
    py = mMapPoint.y;
}
 
Example 5
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the screen pixel for a GeoPoint
 *
 * @param geoPoint the GeoPoint
 * @param out      Point projected to screen pixel
 */
public void toScreenPoint(GeoPoint geoPoint, boolean relativeToCenter, Point out) {
    MercatorProjection.project(geoPoint, out);
    toScreenPoint(out.x, out.y, relativeToCenter, out);
}