private Point getUpperLeftCornerOfCenterMapTileInScreen( final int[] centerMapTileCoords, final int tileSizePx, final Point reuse) { if (OpenStreetMapViewConstants.DEBUGMODE) Log.d("RMAPS-Me", "YandexTrafficOverlay getUpperLeftCornerOfCenterMapTileInScreen is Called"); final Point out = (reuse != null) ? reuse : new Point(); final int viewWidth = mMapView.getWidth(); final int viewWidth_2 = viewWidth / 2; final int viewHeight = mMapView.getHeight(); final int viewHeight_2 = viewHeight / 2; /* * Calculate the Latitude/Longitude on the left-upper ScreenCoords of the center MapTile. So in the end we can * determine which MapTiles we additionally need next to the centerMapTile. */ final BoundingBoxE6 bb = Util.getBoundingBoxFromMapTile( centerMapTileCoords, mMapView.getZoomLevel(), mRendererInfo.PROJECTION); final float[] relativePositionInCenterMapTile = bb.getRelativePositionOfGeoPointInBoundingBoxWithLinearInterpolation( mMapView.getMapCenterLatitudeE6(), mMapView.getMapCenterLongitudeE6(), null); final int centerMapTileScreenLeft = viewWidth_2 - (int) (0.5f + (relativePositionInCenterMapTile[1] * tileSizePx)); final int centerMapTileScreenTop = viewHeight_2 - (int) (0.5f + (relativePositionInCenterMapTile[0] * tileSizePx)); out.set(centerMapTileScreenLeft, centerMapTileScreenTop); return out; }
@Override protected void onDraw(Canvas c, OpenStreetMapView osmv) { if (this.mLocation != null) { mT.setText(mDescr); mT.measure(0, 0); mT.layout(0, 0, mT.getMeasuredWidth(), mT.getMeasuredHeight()); final OpenStreetMapViewProjection pj = osmv.getProjection(); final Point screenCoords = new Point(); pj.toPixels(this.mLocation, screenCoords); c.save(); c.rotate(osmv.getBearing(), screenCoords.x, screenCoords.y); c.translate(screenCoords.x - 12, screenCoords.y - mT.getMeasuredHeight() + 2); mT.draw(c); c.restore(); } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event, OpenStreetMapView mapView) { if (keyCode == KeyEvent.KEYCODE_BACK) if (mLocation != null) { mLocation = null; mapView.invalidate(); return true; } return super.onKeyDown(keyCode, event, mapView); }
/** * Draw a red line for our tracklog * * @see Overlay#draw(android.graphics.Canvas, boolean) */ public void fixmeBustedOnOSM(Canvas canvas, OpenStreetMapView mapView) { OpenStreetMapViewProjection proj = mapView.getProjection(); Point p = new Point(); int prevZ = 0, prevTime = 0; float prevX = 0, prevY = 0; boolean hasPrev = false; int[] times = tracklog.timeMsec.toUnsafeArray(); int[] alts = tracklog.altitudeMM.toUnsafeArray(); // Provide rational initial condition if (tracklog.numPoints() > 0) { prevZ = alts[0]; prevTime = times[0]; } int hue = hsvMap.length / 2; // Default to something middling for (int i = 0; i < tracklog.numPoints(); i++) { GeoPoint gp = tracklog.getGeoPoint(i); int curTime = times[i]; // for time // FIXME - busted on OSM // proj.toPixels(gp, p); if (hasPrev) { int deltaMsec = curTime - prevTime; // Integrate over the last X seconds of time int integrateMsec = 10 * 1000; if (deltaMsec > integrateMsec) { int curZ = alts[i]; int deltaMM = curZ - prevZ; int mmPerSecUp = (deltaMM * 1000) / deltaMsec; if (mmPerSecUp > maxMMeterSec) maxMMeterSec = mmPerSecUp; if (mmPerSecUp < minMMeterSec) minMMeterSec = mmPerSecUp; // linear interpolate between min and max vert speed, 1.0== // max hue = (hsvMap.length - 1) * (mmPerSecUp - minMMeterSec) / (maxMMeterSec - minMMeterSec); // Scale hue so max up is yellow, and max down is blue if (hue >= hsvMap.length) hue = hsvMap.length - 1; else if (hue < 0) hue = 0; prevTime = curTime; prevZ = curZ; // FIXME, we should do some sort of moving boxcar average // instead } // trackPaint.setARGB(255, 255, 0, 0); int color = hsvMap[hue]; trackPaint.setColor(color); // FIXME - for live flights we should only plot a detailed // tracklog for the last // 20 minutes. Prior to that we // can skip points // FIXME, the array based versions are probably faster canvas.drawLine(prevX, prevY, p.x, p.y, trackPaint); } prevX = p.x; prevY = p.y; hasPrev = true; } }
@Override protected void onDraw(Canvas c, OpenStreetMapView osmv) { if (OpenStreetMapViewConstants.DEBUGMODE) Log.d("RMAPS-Me", "YandexTrafficOverlay onDraw is Called"); // final long startMs = System.currentTimeMillis(); /* * Do some calculations and drag attributes to local variables to save some performance. */ final int zoomLevel = mMapView.getZoomLevel(); final int viewWidth = mMapView.getWidth(); final int viewHeight = mMapView.getHeight(); final int tileSizePx = (int) (this.mRendererInfo.getTileSizePx(zoomLevel) * osmv.mTouchScale); /* * Get the center MapTile which is above this.mLatitudeE6 and this.mLongitudeE6 . */ final int[] centerMapTileCoords = Util.getMapTileFromCoordinates( mMapView.getMapCenterLatitudeE6(), mMapView.getMapCenterLongitudeE6(), zoomLevel, null, mRendererInfo.PROJECTION); /* * Calculate the Latitude/Longitude on the left-upper ScreenCoords of the center MapTile. So in the end we can * determine which MapTiles we additionally need next to the centerMapTile. */ final Point upperLeftCornerOfCenterMapTile = getUpperLeftCornerOfCenterMapTileInScreen(centerMapTileCoords, tileSizePx, null); final int centerMapTileScreenLeft = upperLeftCornerOfCenterMapTile.x; final int centerMapTileScreenTop = upperLeftCornerOfCenterMapTile.y; final int centerMapTileScreenRight = centerMapTileScreenLeft + tileSizePx; final int centerMapTileScreenBottom = centerMapTileScreenTop + tileSizePx; /* * Calculate the amount of tiles needed for each side around the center one. */ final int additionalTilesNeededToLeftOfCenter = (int) Math.ceil((float) centerMapTileScreenLeft / tileSizePx); // i.e. // "30 / 256" // = 1; final int additionalTilesNeededToRightOfCenter = (int) Math.ceil((float) (viewWidth - centerMapTileScreenRight) / tileSizePx); final int additionalTilesNeededToTopOfCenter = (int) Math.ceil((float) centerMapTileScreenTop / tileSizePx); // i.e. // "30 / 256" // = 1; final int additionalTilesNeededToBottomOfCenter = (int) Math.ceil((float) (viewHeight - centerMapTileScreenBottom) / tileSizePx); final int mapTileUpperBound = (int) Math.pow(2, zoomLevel); final int[] mapTileCoords = new int[] {centerMapTileCoords[0], centerMapTileCoords[1]}; /* Draw all the MapTiles (from the upper left to the lower right). */ for (int y = -additionalTilesNeededToTopOfCenter; y <= additionalTilesNeededToBottomOfCenter; y++) { for (int x = -additionalTilesNeededToLeftOfCenter; x <= additionalTilesNeededToRightOfCenter; x++) { /* * Add/substract the difference of the tile-position to the one of the center. */ mapTileCoords[0] = MyMath.mod(centerMapTileCoords[0] + y, mapTileUpperBound); mapTileCoords[1] = MyMath.mod(centerMapTileCoords[1] + x, mapTileUpperBound); /* Construct a URLString, which represents the MapTile. */ final String tileURLString = this.mRendererInfo.getTileURLString(mapTileCoords, zoomLevel); // Log.i(DEBUGTAG, tileURLString); if (OpenStreetMapViewConstants.DEBUGMODE) Log.d("RMAPS-Me", "YandexTrafficOverlay onDraw Loop is Called"); /* Draw the MapTile 'i tileSizePx' above of the centerMapTile */ final Bitmap currentMapTile = this.mTileProvider.getMapTile( tileURLString, this.mRendererInfo.TILE_SOURCE_TYPE, null, 0, 0, 0); if (currentMapTile != null) { final int tileLeft = mMapView.mTouchMapOffsetX + centerMapTileScreenLeft + (x * tileSizePx); final int tileTop = mMapView.mTouchMapOffsetY + centerMapTileScreenTop + (y * tileSizePx); final Rect r = new Rect(tileLeft, tileTop, tileLeft + tileSizePx, tileTop + tileSizePx); c.drawBitmap(currentMapTile, null, r, this.mPaint); if (DEBUGMODE) { c.drawText( "y x = " + mapTileCoords[0] + " " + mapTileCoords[1] + " zoom " + zoomLevel, tileLeft + 5, tileTop + 45, this.mPaint); } } } } }
@Override protected void onDraw(Canvas c, OpenStreetMapView osmv) { if (DEBUGMODE) logger.trace("onDraw"); /* * Do some calculations and drag attributes to local variables to save * some performance. */ final OpenStreetMapViewProjection pj = osmv.getProjection(); final int zoomLevel = osmv.getZoomLevel(false); c.getClipBounds(mViewPort); final int tileSizePx = this.mRendererInfo.maptileSizePx(); final int tileZoom = this.mRendererInfo.maptileZoom(); final int worldSize_2 = 1 << (zoomLevel + tileZoom - 1); /* * Calculate the amount of tiles needed for each side around the center * one. */ mViewPort.offset(worldSize_2, worldSize_2); final int tileNeededToLeftOfCenter = (mViewPort.left >> tileZoom) - 1; final int tileNeededToRightOfCenter = mViewPort.right >> tileZoom; final int tileNeededToTopOfCenter = (mViewPort.top >> tileZoom) - 1; final int tileNeededToBottomOfCenter = mViewPort.bottom >> tileZoom; final int mapTileUpperBound = 1 << zoomLevel; // make sure the cache is big enough for all the tiles final int numNeeded = (tileNeededToBottomOfCenter - tileNeededToTopOfCenter + 1) * (tileNeededToRightOfCenter - tileNeededToLeftOfCenter + 1); mTileProvider.ensureCapacity(numNeeded); /* Draw all the MapTiles (from the upper left to the lower right). */ for (int y = tileNeededToTopOfCenter; y <= tileNeededToBottomOfCenter; y++) { for (int x = tileNeededToLeftOfCenter; x <= tileNeededToRightOfCenter; x++) { /* Construct a URLString, which represents the MapTile. */ final int tileY = MyMath.mod(y, mapTileUpperBound); final int tileX = MyMath.mod(x, mapTileUpperBound); final OpenStreetMapTile tile = new OpenStreetMapTile(this.mRendererInfo, zoomLevel, tileX, tileY); pj.toPixels(x, y, mTilePos); final Drawable currentMapTile = mTileProvider.getMapTile(tile); if (currentMapTile != null) { currentMapTile.setBounds( mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y + tileSizePx); currentMapTile.draw(c); } if (DEBUGMODE) { c.drawText(tile.toString(), mTilePos.x + 1, mTilePos.y + mPaint.getTextSize(), mPaint); c.drawLine(mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y, mPaint); c.drawLine(mTilePos.x, mTilePos.y, mTilePos.x, mTilePos.y + tileSizePx, mPaint); } } } // draw a cross at center in debug mode if (DEBUGMODE) { final GeoPoint center = osmv.getMapCenter(); final Point centerPoint = pj.toMapPixels(center, null); c.drawLine(centerPoint.x, centerPoint.y - 9, centerPoint.x, centerPoint.y + 9, mPaint); c.drawLine(centerPoint.x - 9, centerPoint.y, centerPoint.x + 9, centerPoint.y, mPaint); } }