public boolean updateInfo(RotatedTileBox tb, DrawSettings nightMode) { boolean visible = true; OsmandMapTileView view = ma.getMapView(); // update cache if (view.isZooming()) { visible = false; } else if (!orientationPortrait && ma.getRoutingHelper().isRoutePlanningMode()) { visible = false; } else if ((tb.getZoom() != cacheRulerZoom || Math.abs(tb.getCenterTileX() - cacheRulerTileX) > 1 || Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1) && tb.getPixWidth() > 0 && maxWidth > 0) { cacheRulerZoom = tb.getZoom(); cacheRulerTileX = tb.getCenterTileX(); cacheRulerTileY = tb.getCenterTileY(); final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); double pixDensity = tb.getPixWidth() / dist; double roundedDist = OsmAndFormatter.calculateRoundedDist(maxWidth / pixDensity, view.getApplication()); int cacheRulerDistPix = (int) (pixDensity * roundedDist); cacheRulerText = OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication()); textShadow.setText(cacheRulerText); text.setText(cacheRulerText); ViewGroup.LayoutParams lp = layout.getLayoutParams(); lp.width = cacheRulerDistPix; layout.setLayoutParams(lp); layout.requestLayout(); } updateVisibility(layout, visible); return true; }
@Override public void onZoomEnded(double relativeToStart, float angleRelative) { // 1.5 works better even on dm.density=1 devices float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f; setIntZoom(Math.round(dz) + initialViewport.getZoom()); if (Math.abs(angleRelative) < ANGLE_THRESHOLD) { angleRelative = 0; } rotateToAnimate(initialViewport.getRotate() + angleRelative); final int newZoom = getZoom(); if (application.getInternalAPI().accessibilityEnabled()) { if (newZoom != initialViewport.getZoom()) { showMessage(getContext().getString(R.string.zoomIs) + " " + newZoom); // $NON-NLS-1$ } else { final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1); final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2); showMessage( OsmAndFormatter.getFormattedDistance( (float) MapUtils.getDistance( p1.getLatitude(), p1.getLongitude(), p2.getLatitude(), p2.getLongitude()), application)); } } }
public int getRadiusPoi(RotatedTileBox tb) { int r = 0; if (tb.getZoom() < startZoom) { r = 0; } else { r = 15; } return (int) (r * tb.getDensity()); }
public void setMainLayer(BaseMapLayer mainLayer) { this.mainLayer = mainLayer; int zoom = currentViewport.getZoom(); if (mainLayer.getMaximumShownMapZoom() < zoom) { zoom = mainLayer.getMaximumShownMapZoom(); } if (mainLayer.getMinimumShownMapZoom() > zoom) { zoom = mainLayer.getMinimumShownMapZoom(); } currentViewport.setZoomAndAnimation(zoom, 0); refreshMap(); }
private String getZoomLevel(RotatedTileBox tb) { String zoomText = tb.getZoom() + ""; double frac = tb.getMapDensity(); if (frac != 0) { int ifrac = (int) (frac * 10); zoomText += " "; zoomText += Math.abs(ifrac) / 10; if (ifrac % 10 != 0) { zoomText += "." + Math.abs(ifrac) % 10; } } return zoomText; }
private void changeZoomPosition(float dz, float angle) { final QuadPoint cp = initialViewport.getCenterPixelPoint(); float dx = cp.x - initialMultiTouchCenterPoint.x; float dy = cp.y - initialMultiTouchCenterPoint.y; final RotatedTileBox calc = initialViewport.copy(); calc.setLatLonCenter(initialCenterLatLon.getLatitude(), initialCenterLatLon.getLongitude()); float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale(); float calcRotate = calc.getRotate() + angle; calc.setRotate(calcRotate); calc.setZoomAnimation(dz); final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy); setLatLon(r.getLatitude(), r.getLongitude()); zoomToAnimate(calcZoom, true); rotateToAnimate(calcRotate); }
public int getRadiusBug(RotatedTileBox tb) { int z; final double zoom = tb.getZoom(); if (zoom < startZoom) { z = 0; } else if (zoom <= 12) { z = 8; } else if (zoom <= 15) { z = 10; } else if (zoom == 16) { z = 13; } else if (zoom == 17) { z = 15; } else { z = 16; } return (int) (z * tb.getDensity()); }
@Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (tileBox.getZoom() >= startZoom) { // request to load data.queryNewData(tileBox); List<OpenStreetNote> objects = data.getResults(); if (objects != null) { for (OpenStreetNote o : objects) { int x = tileBox.getPixXFromLonNoRot(o.getLongitude()); int y = tileBox.getPixYFromLatNoRot(o.getLatitude()); canvas.drawCircle( x, y, getRadiusBug(tileBox), o.isLocal() ? pointNotSubmitedUI : (o.isOpened() ? pointOpenedUI : pointClosedUI)); } } } }
@Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (tileBox.getZoom() >= startZoom) { DataTileManager<Recording> recs = plugin.getRecordings(); final QuadRect latlon = tileBox.getLatLonBounds(); List<Recording> objects = recs.getObjects(latlon.top, latlon.left, latlon.bottom, latlon.right); for (Recording o : objects) { int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); Bitmap b; if (o.isPhoto()) { b = photo; } else if (o.isAudio()) { b = audio; } else { b = video; } canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); } } }
@Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (tileBox.getZoom() >= startZoom) { // request to load final QuadRect latLonBounds = tileBox.getLatLonBounds(); for (FavouritePoint o : favorites.getFavouritePoints()) { if (o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left && o.getLongitude() <= latLonBounds.right) { int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor()); fid.drawBitmapInCenter(canvas, x, y); // canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2, // y - favoriteIcon.getHeight(), paint); } } } }
public void openDialog() { BaseMapLayer mainLayer = mapView.getMainLayer(); if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) { AccessibleToast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT) .show(); } final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap(); if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) { AccessibleToast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT) .show(); return; } final RotatedTileBox rb = mapView.getCurrentRotatedTileBox(); final int max = mapSource.getMaximumZoomSupported(); // get narrow zoom final int zoom = rb.getZoom(); // calculate pixel rectangle AlertDialog.Builder builder = new AlertDialog.Builder(ctx); LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.download_tiles, null); ((TextView) view.findViewById(R.id.MinZoom)).setText(zoom + ""); // $NON-NLS-1$ ((TextView) view.findViewById(R.id.MaxZoom)).setText(max + ""); // $NON-NLS-1$ final SeekBar seekBar = (SeekBar) view.findViewById(R.id.ZoomToDownload); seekBar.setMax(max - zoom); seekBar.setProgress((max - zoom) / 2); final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription)); final String template = ctx.getString(R.string.tiles_to_download_estimated_size); updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, seekBar.getProgress()); seekBar.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); builder.setPositiveButton( R.string.shared_string_download, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); run(zoom, seekBar.getProgress(), rb.getLatLonBounds(), mapSource); } }); builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setView(view); builder.show(); }
public int getZoom() { return currentViewport.getZoom(); }