Map scale bar: multi-platform implementation, closes #84
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
- vtm-ios update module [#29](https://github.com/mapsforge/vtm/issues/29)
|
||||
- Native libraries for all platforms [#14](https://github.com/mapsforge/vtm/issues/14)
|
||||
- Group layer implementation [#99](https://github.com/mapsforge/vtm/issues/99)
|
||||
- Map scale bar new Android implementation [#88](https://github.com/mapsforge/vtm/issues/88)
|
||||
- Map scale bar multi-platform implementation [#84](https://github.com/mapsforge/vtm/issues/84)
|
||||
- Render themes area tessellation option [#37](https://github.com/mapsforge/vtm/issues/37)
|
||||
- Graphics API platform enhancements [#92](https://github.com/mapsforge/vtm/issues/92)
|
||||
- vtm-jts create module [#53](https://github.com/mapsforge/vtm/issues/53)
|
||||
|
||||
@@ -19,11 +19,6 @@ package org.oscim.android.test;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.oscim.android.scalebar.DefaultMapScaleBar;
|
||||
import org.oscim.android.scalebar.ImperialUnitAdapter;
|
||||
import org.oscim.android.scalebar.MapScaleBar;
|
||||
import org.oscim.android.scalebar.MapScaleBarLayer;
|
||||
import org.oscim.android.scalebar.MetricUnitAdapter;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
@@ -32,6 +27,11 @@ import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.renderer.BitmapRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.scalebar.DefaultMapScaleBar;
|
||||
import org.oscim.scalebar.ImperialUnitAdapter;
|
||||
import org.oscim.scalebar.MapScaleBar;
|
||||
import org.oscim.scalebar.MapScaleBarLayer;
|
||||
import org.oscim.scalebar.MetricUnitAdapter;
|
||||
import org.oscim.theme.IRenderTheme;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
@@ -48,14 +48,14 @@ public class SimpleMapActivity extends BaseMapActivity {
|
||||
groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer));
|
||||
mMap.layers().add(groupLayer);
|
||||
|
||||
mapScaleBar = new DefaultMapScaleBar(mMap);
|
||||
mapScaleBar = new DefaultMapScaleBar(mMap, CanvasAdapter.dpi / 160);
|
||||
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
|
||||
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
|
||||
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
|
||||
mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
|
||||
|
||||
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
|
||||
BitmapRenderer renderer = (BitmapRenderer) mapScaleBarLayer.getRenderer();
|
||||
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
|
||||
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
|
||||
renderer.setOffset(5 * CanvasAdapter.dpi / 160, 0);
|
||||
mMap.layers().add(mapScaleBarLayer);
|
||||
|
||||
@@ -22,6 +22,13 @@ import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.BitmapRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.scalebar.DefaultMapScaleBar;
|
||||
import org.oscim.scalebar.ImperialUnitAdapter;
|
||||
import org.oscim.scalebar.MapScaleBar;
|
||||
import org.oscim.scalebar.MapScaleBarLayer;
|
||||
import org.oscim.scalebar.MetricUnitAdapter;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
@@ -38,6 +45,18 @@ public class MapTest extends GdxMapApp {
|
||||
groupLayer.layers.add(new LabelLayer(map, l));
|
||||
map.layers().add(groupLayer);
|
||||
|
||||
DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
|
||||
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
|
||||
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
|
||||
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
|
||||
mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
|
||||
|
||||
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
|
||||
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
|
||||
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
|
||||
renderer.setOffset(5, 0);
|
||||
map.layers().add(mapScaleBarLayer);
|
||||
|
||||
map.setTheme(VtmThemes.DEFAULT);
|
||||
map.setMapPosition(53.075, 8.808, 1 << 17);
|
||||
}
|
||||
|
||||
@@ -16,30 +16,28 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
import org.oscim.map.Map;
|
||||
|
||||
/**
|
||||
* Displays the default MapScaleBar
|
||||
* Displays the default MapScaleBar.
|
||||
*/
|
||||
public class DefaultMapScaleBar extends MapScaleBar {
|
||||
private static final int BITMAP_HEIGHT = 40;
|
||||
private static final int BITMAP_WIDTH = 120;
|
||||
private static final int DEFAULT_HORIZONTAL_MARGIN = 5;
|
||||
private static final int DEFAULT_VERTICAL_MARGIN = 0;
|
||||
private static final int SCALE_BAR_MARGIN = 10;
|
||||
private static final float STROKE_EXTERNAL = 4;
|
||||
private static final float STROKE_INTERNAL = 2;
|
||||
private static final int TEXT_MARGIN = 1;
|
||||
|
||||
public static enum ScaleBarMode {BOTH, SINGLE}
|
||||
public enum ScaleBarMode {BOTH, SINGLE}
|
||||
|
||||
private final float scale;
|
||||
private ScaleBarMode scaleBarMode;
|
||||
@@ -50,15 +48,16 @@ public class DefaultMapScaleBar extends MapScaleBar {
|
||||
private final Paint paintScaleText;
|
||||
private final Paint paintScaleTextStroke;
|
||||
|
||||
private final Rect rect = new Rect();
|
||||
|
||||
public DefaultMapScaleBar(Map map) {
|
||||
this(map, CanvasAdapter.dpi / 160);
|
||||
this(map, CanvasAdapter.dpi / 240);
|
||||
}
|
||||
|
||||
public DefaultMapScaleBar(Map map, float scale) {
|
||||
super(map, (int) (BITMAP_WIDTH * scale), (int) (BITMAP_HEIGHT * scale));
|
||||
|
||||
setMarginHorizontal((int) (DEFAULT_HORIZONTAL_MARGIN * scale));
|
||||
setMarginVertical((int) (DEFAULT_VERTICAL_MARGIN * scale));
|
||||
|
||||
this.scale = scale;
|
||||
this.scaleBarMode = ScaleBarMode.BOTH;
|
||||
this.secondaryDistanceUnitAdapter = ImperialUnitAdapter.INSTANCE;
|
||||
@@ -99,12 +98,7 @@ public class DefaultMapScaleBar extends MapScaleBar {
|
||||
}
|
||||
|
||||
private Paint createScaleBarPaint(int color, float strokeWidth, Paint.Style style) {
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
paint.setStrokeJoin(Paint.Join.ROUND);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
|
||||
Paint paint = CanvasAdapter.newPaint();
|
||||
paint.setColor(color);
|
||||
paint.setStrokeWidth(strokeWidth * this.scale);
|
||||
paint.setStyle(style);
|
||||
@@ -113,24 +107,18 @@ public class DefaultMapScaleBar extends MapScaleBar {
|
||||
}
|
||||
|
||||
private Paint createTextPaint(int color, float strokeWidth, Paint.Style style) {
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
paint.setStrokeJoin(Paint.Join.ROUND);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
|
||||
Paint paint = CanvasAdapter.newPaint();
|
||||
paint.setColor(color);
|
||||
paint.setStrokeWidth(strokeWidth * this.scale);
|
||||
paint.setStyle(style);
|
||||
paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
|
||||
paint.setTypeface(Paint.FontFamily.DEFAULT, Paint.FontStyle.BOLD);
|
||||
paint.setTextSize(12 * this.scale);
|
||||
|
||||
return paint;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void redraw(Canvas canvas) {
|
||||
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
||||
canvas.fillColor(Color.TRANSPARENT);
|
||||
|
||||
ScaleBarLengthAndValue lengthAndValue = this.calculateScaleBarLengthAndValue();
|
||||
ScaleBarLengthAndValue lengthAndValue2;
|
||||
@@ -276,13 +264,13 @@ public class DefaultMapScaleBar extends MapScaleBar {
|
||||
switch (scaleBarPosition) {
|
||||
case BOTTOM_CENTER:
|
||||
if (scaleText2.length() == 0) {
|
||||
canvas.drawText(scaleText1, Math.round((canvas.getWidth() - getTextWidth(this.paintScaleTextStroke, scaleText1)) * 0.5f),
|
||||
canvas.drawText(scaleText1, Math.round((canvas.getWidth() - this.paintScaleTextStroke.getTextWidth(scaleText1)) * 0.5f),
|
||||
Math.round(canvas.getHeight() - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
} else {
|
||||
canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText2)), paint);
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
|
||||
}
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
@@ -293,62 +281,53 @@ public class DefaultMapScaleBar extends MapScaleBar {
|
||||
canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText2)), paint);
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
|
||||
}
|
||||
break;
|
||||
case BOTTOM_RIGHT:
|
||||
if (scaleText2.length() == 0) {
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - getTextWidth(this.paintScaleTextStroke, scaleText1)),
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText1)),
|
||||
Math.round(canvas.getHeight() - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
} else {
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - getTextWidth(this.paintScaleTextStroke, scaleText1)),
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText1)),
|
||||
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
canvas.drawText(scaleText2, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - getTextWidth(this.paintScaleTextStroke, scaleText2)),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText2)), paint);
|
||||
canvas.drawText(scaleText2, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText2)),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
|
||||
}
|
||||
break;
|
||||
case TOP_CENTER:
|
||||
if (scaleText2.length() == 0) {
|
||||
canvas.drawText(scaleText1, Math.round((canvas.getWidth() - getTextWidth(this.paintScaleTextStroke, scaleText1)) * 0.5f),
|
||||
Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText1)), paint);
|
||||
canvas.drawText(scaleText1, Math.round((canvas.getWidth() - this.paintScaleTextStroke.getTextWidth(scaleText1)) * 0.5f),
|
||||
Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint);
|
||||
} else {
|
||||
canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText2)), paint);
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
|
||||
}
|
||||
break;
|
||||
case TOP_LEFT:
|
||||
if (scaleText2.length() == 0) {
|
||||
canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText1)), paint);
|
||||
Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint);
|
||||
} else {
|
||||
canvas.drawText(scaleText1, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
canvas.drawText(scaleText2, Math.round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText2)), paint);
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
|
||||
}
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
if (scaleText2.length() == 0) {
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - getTextWidth(this.paintScaleTextStroke, scaleText1)),
|
||||
Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText1)), paint);
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText1)),
|
||||
Math.round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText1)), paint);
|
||||
} else {
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - getTextWidth(this.paintScaleTextStroke, scaleText1)),
|
||||
canvas.drawText(scaleText1, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText1)),
|
||||
Math.round(canvas.getHeight() * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
|
||||
canvas.drawText(scaleText2, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - getTextWidth(this.paintScaleTextStroke, scaleText2)),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + getTextHeight(this.paintScaleTextStroke, scaleText2)), paint);
|
||||
canvas.drawText(scaleText2, Math.round(canvas.getWidth() - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.getTextWidth(scaleText2)),
|
||||
Math.round(canvas.getHeight() * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.getTextHeight(scaleText2)), paint);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int getTextHeight(Paint paint, String text) {
|
||||
paint.getTextBounds(text, 0, text.length(), rect);
|
||||
return rect.height();
|
||||
}
|
||||
|
||||
private int getTextWidth(Paint paint, String text) {
|
||||
return (int) paint.measureText(text);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
public interface DistanceUnitAdapter {
|
||||
double getMeterRatio();
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
public final class ImperialUnitAdapter implements DistanceUnitAdapter {
|
||||
public static final ImperialUnitAdapter INSTANCE = new ImperialUnitAdapter();
|
||||
@@ -15,12 +15,11 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.map.Map;
|
||||
@@ -29,18 +28,15 @@ import org.oscim.map.Map;
|
||||
* A MapScaleBar displays the ratio of a distance on the map to the corresponding distance on the ground.
|
||||
*/
|
||||
public abstract class MapScaleBar {
|
||||
public static enum ScaleBarPosition {BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, TOP_CENTER, TOP_LEFT, TOP_RIGHT}
|
||||
public enum ScaleBarPosition {BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, TOP_CENTER, TOP_LEFT, TOP_RIGHT}
|
||||
|
||||
/**
|
||||
* Default position of the scale bar.
|
||||
*/
|
||||
private static final ScaleBarPosition DEFAULT_SCALE_BAR_POSITION = ScaleBarPosition.BOTTOM_LEFT;
|
||||
|
||||
private static final int DEFAULT_HORIZONTAL_MARGIN = 5;
|
||||
private static final int DEFAULT_VERTICAL_MARGIN = 0;
|
||||
private static final double LATITUDE_REDRAW_THRESHOLD = 0.2;
|
||||
|
||||
protected final Paint bitmapPaint = new Paint();
|
||||
private final MapPosition currentMapPosition = new MapPosition();
|
||||
protected DistanceUnitAdapter distanceUnitAdapter;
|
||||
protected final Map map;
|
||||
@@ -68,16 +64,11 @@ public abstract class MapScaleBar {
|
||||
|
||||
public MapScaleBar(Map map, int width, int height) {
|
||||
this.map = map;
|
||||
this.mapScaleBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
this.mapScaleBitmap = CanvasAdapter.newBitmap(width, height, 0);
|
||||
|
||||
this.bitmapPaint.setAntiAlias(true);
|
||||
this.bitmapPaint.setFilterBitmap(true);
|
||||
|
||||
this.marginHorizontal = DEFAULT_HORIZONTAL_MARGIN;
|
||||
this.marginVertical = DEFAULT_VERTICAL_MARGIN;
|
||||
this.scaleBarPosition = DEFAULT_SCALE_BAR_POSITION;
|
||||
|
||||
this.mapScaleCanvas = new Canvas();
|
||||
this.mapScaleCanvas = CanvasAdapter.newCanvas();
|
||||
this.mapScaleCanvas.setBitmap(this.mapScaleBitmap);
|
||||
this.distanceUnitAdapter = MetricUnitAdapter.INSTANCE;
|
||||
this.visible = true;
|
||||
@@ -212,8 +203,8 @@ public abstract class MapScaleBar {
|
||||
int scaleBarLength = 0;
|
||||
int mapScaleValue = 0;
|
||||
|
||||
for (int i = 0; i < scaleBarValues.length; ++i) {
|
||||
mapScaleValue = scaleBarValues[i];
|
||||
for (int scaleBarValue : scaleBarValues) {
|
||||
mapScaleValue = scaleBarValue;
|
||||
scaleBarLength = (int) (mapScaleValue / groundResolution);
|
||||
if (scaleBarLength < (this.mapScaleBitmap.getWidth() - 10)) {
|
||||
break;
|
||||
@@ -252,7 +243,14 @@ public abstract class MapScaleBar {
|
||||
int positionLeft = calculatePositionLeft(0, this.map.getWidth(), this.mapScaleBitmap.getWidth());
|
||||
int positionTop = calculatePositionTop(0, this.map.getHeight(), this.mapScaleBitmap.getHeight());
|
||||
|
||||
canvas.drawBitmap(this.mapScaleBitmap, positionLeft, positionTop, this.bitmapPaint);
|
||||
canvas.drawBitmap(this.mapScaleBitmap, positionLeft, positionTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* The scalebar is redrawn now.
|
||||
*/
|
||||
public void drawScaleBar() {
|
||||
draw(mapScaleCanvas);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -12,9 +12,8 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
import org.oscim.android.canvas.AndroidBitmap;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.event.Event;
|
||||
import org.oscim.layers.Layer;
|
||||
@@ -24,16 +23,18 @@ import org.oscim.renderer.BitmapRenderer;
|
||||
public class MapScaleBarLayer extends Layer implements Map.UpdateListener {
|
||||
private final MapScaleBar mapScaleBar;
|
||||
private final BitmapRenderer bitmapRenderer;
|
||||
// Passed to BitmapRenderer - need to sync on this object
|
||||
private final AndroidBitmap layerBitmap;
|
||||
|
||||
public MapScaleBarLayer(Map map, MapScaleBar mapScaleBar) {
|
||||
super(map);
|
||||
this.mapScaleBar = mapScaleBar;
|
||||
|
||||
mRenderer = bitmapRenderer = new BitmapRenderer();
|
||||
layerBitmap = new AndroidBitmap(mapScaleBar.mapScaleBitmap);
|
||||
bitmapRenderer.setBitmap(layerBitmap, mapScaleBar.mapScaleBitmap.getWidth(), mapScaleBar.mapScaleBitmap.getHeight());
|
||||
bitmapRenderer.setBitmap(mapScaleBar.mapScaleBitmap, mapScaleBar.mapScaleBitmap.getWidth(), mapScaleBar.mapScaleBitmap.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitmapRenderer getRenderer() {
|
||||
return bitmapRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,8 +51,8 @@ public class MapScaleBarLayer extends Layer implements Map.UpdateListener {
|
||||
if (!mapScaleBar.isRedrawNecessary())
|
||||
return;
|
||||
|
||||
synchronized (layerBitmap) {
|
||||
mapScaleBar.redraw(mapScaleBar.mapScaleCanvas);
|
||||
synchronized (mapScaleBar.mapScaleBitmap) {
|
||||
mapScaleBar.drawScaleBar();
|
||||
}
|
||||
|
||||
bitmapRenderer.updateBitmap();
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
public final class MetricUnitAdapter implements DistanceUnitAdapter {
|
||||
public static final MetricUnitAdapter INSTANCE = new MetricUnitAdapter();
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.scalebar;
|
||||
package org.oscim.scalebar;
|
||||
|
||||
public final class NauticalUnitAdapter implements DistanceUnitAdapter {
|
||||
public static final NauticalUnitAdapter INSTANCE = new NauticalUnitAdapter();
|
||||
Reference in New Issue
Block a user