Screen position for bitmap renderering, closes #87
This commit is contained in:
parent
52da03ce59
commit
faada6625f
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -19,11 +20,14 @@ package org.oscim.android.test;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.oscim.android.MapScaleBar;
|
import org.oscim.android.MapScaleBar;
|
||||||
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||||
import org.oscim.map.Layers;
|
import org.oscim.map.Layers;
|
||||||
|
import org.oscim.renderer.BitmapRenderer;
|
||||||
|
import org.oscim.renderer.GLViewport;
|
||||||
import org.oscim.theme.IRenderTheme;
|
import org.oscim.theme.IRenderTheme;
|
||||||
import org.oscim.theme.ThemeLoader;
|
import org.oscim.theme.ThemeLoader;
|
||||||
import org.oscim.theme.VtmThemes;
|
import org.oscim.theme.VtmThemes;
|
||||||
@ -37,7 +41,11 @@ public class SimpleMapActivity extends BaseMapActivity {
|
|||||||
Layers layers = mMap.layers();
|
Layers layers = mMap.layers();
|
||||||
layers.add(new BuildingLayer(mMap, mBaseLayer));
|
layers.add(new BuildingLayer(mMap, mBaseLayer));
|
||||||
layers.add(new LabelLayer(mMap, mBaseLayer));
|
layers.add(new LabelLayer(mMap, mBaseLayer));
|
||||||
layers.add(new MapScaleBar(mMapView));
|
|
||||||
|
MapScaleBar mapScaleBar = new MapScaleBar(mMapView);
|
||||||
|
((BitmapRenderer) mapScaleBar.getRenderer()).setPosition(GLViewport.Position.BOTTOM_LEFT);
|
||||||
|
((BitmapRenderer) mapScaleBar.getRenderer()).setOffset(5 * CanvasAdapter.dpi / 160, 0);
|
||||||
|
layers.add(mapScaleBar);
|
||||||
|
|
||||||
mMap.setTheme(VtmThemes.DEFAULT);
|
mMap.setTheme(VtmThemes.DEFAULT);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package org.oscim.android;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -15,6 +14,7 @@ package org.oscim.android;
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* 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/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
package org.oscim.android;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@ -95,11 +95,7 @@ public class MapScaleBar extends Layer implements UpdateListener {
|
|||||||
mRedrawNeeded = true;
|
mRedrawNeeded = true;
|
||||||
mRenderer = mBitmapLayer = new BitmapRenderer();
|
mRenderer = mBitmapLayer = new BitmapRenderer();
|
||||||
mLayerBitmap = new AndroidBitmap(mBitmap);
|
mLayerBitmap = new AndroidBitmap(mBitmap);
|
||||||
mBitmapLayer.setBitmap(mLayerBitmap,
|
mBitmapLayer.setBitmap(mLayerBitmap, BITMAP_WIDTH, BITMAP_HEIGHT);
|
||||||
BITMAP_WIDTH,
|
|
||||||
BITMAP_HEIGHT,
|
|
||||||
(int) (BITMAP_WIDTH * 1.2f),
|
|
||||||
(int) (BITMAP_HEIGHT * 1.2f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
* Copyright 2016 Andrey Novikov
|
* Copyright 2016 Andrey Novikov
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -32,26 +33,26 @@ public class BitmapRenderer extends BucketRenderer {
|
|||||||
private int mHeight;
|
private int mHeight;
|
||||||
private boolean initialized;
|
private boolean initialized;
|
||||||
private boolean mUpdateBitmap;
|
private boolean mUpdateBitmap;
|
||||||
private boolean center;
|
private GLViewport.Position position = GLViewport.Position.TOP_LEFT;
|
||||||
private int xOffset;
|
private float xOffset, yOffset;
|
||||||
private int yOffset;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bitmap with dimension being power of two
|
* @param bitmap with dimension being power of two
|
||||||
* @param srcWidth TODO width used
|
* @param width width used
|
||||||
* @param srcHeight TODO height used
|
* @param height height used
|
||||||
*/
|
*/
|
||||||
public synchronized void setBitmap(Bitmap bitmap,
|
public synchronized void setBitmap(Bitmap bitmap, int width, int height) {
|
||||||
int srcWidth, int srcHeight,
|
|
||||||
int targetWidth, int targetHeight) {
|
|
||||||
mWidth = targetWidth;
|
|
||||||
mHeight = targetHeight;
|
|
||||||
mBitmap = bitmap;
|
mBitmap = bitmap;
|
||||||
|
mWidth = width;
|
||||||
|
mHeight = height;
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setDrawOffset(boolean center, int xOffset, int yOffset) {
|
public synchronized void setPosition(GLViewport.Position position) {
|
||||||
this.center = center;
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setOffset(float xOffset, float yOffset) {
|
||||||
this.xOffset = xOffset;
|
this.xOffset = xOffset;
|
||||||
this.yOffset = yOffset;
|
this.yOffset = yOffset;
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ public class BitmapRenderer extends BucketRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void render(GLViewport v) {
|
public synchronized void render(GLViewport v) {
|
||||||
v.setScreenOffset(center, xOffset, yOffset, 8);
|
v.useScreenCoordinates(mWidth, mHeight, position, xOffset, yOffset, 8);
|
||||||
BitmapBucket.Renderer.draw(buckets.get(), v, 1, 1);
|
BitmapBucket.Renderer.draw(buckets.get(), v, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
* Copyright 2016 Andrey Novikov
|
* Copyright 2016 Andrey Novikov
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -23,6 +24,10 @@ import org.oscim.map.Viewport;
|
|||||||
|
|
||||||
public class GLViewport extends Viewport {
|
public class GLViewport extends Viewport {
|
||||||
|
|
||||||
|
public enum Position {
|
||||||
|
TOP_LEFT, TOP_CENTER, TOP_RIGHT, CENTER_LEFT, CENTER, CENTER_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do not modify!
|
* Do not modify!
|
||||||
*/
|
*/
|
||||||
@ -65,10 +70,48 @@ public class GLViewport extends Viewport {
|
|||||||
/**
|
/**
|
||||||
* Set MVP offset in screen pixel coordinates
|
* Set MVP offset in screen pixel coordinates
|
||||||
*/
|
*/
|
||||||
public void setScreenOffset(boolean center, int xOffset, int yOffset, float scale) {
|
public void useScreenCoordinates(int width, int height, Position position, float xOffset, float yOffset, float scale) {
|
||||||
float invScale = 1f / scale;
|
float invScale = 1f / scale;
|
||||||
float x = center ? xOffset : -mWidth / 2 + xOffset;
|
float x = 0;
|
||||||
float y = center ? yOffset : -mHeight / 2 + yOffset;
|
float y = 0;
|
||||||
|
switch (position) {
|
||||||
|
case TOP_LEFT:
|
||||||
|
x = -mWidth * 0.5f + xOffset;
|
||||||
|
y = -mHeight * 0.5f + yOffset;
|
||||||
|
break;
|
||||||
|
case TOP_CENTER:
|
||||||
|
x = -width * 0.5f + xOffset;
|
||||||
|
y = -mHeight * 0.5f + yOffset;
|
||||||
|
break;
|
||||||
|
case TOP_RIGHT:
|
||||||
|
x = mWidth * 0.5f - width - xOffset;
|
||||||
|
y = -mHeight * 0.5f + yOffset;
|
||||||
|
break;
|
||||||
|
case CENTER_LEFT:
|
||||||
|
x = -mWidth * 0.5f + xOffset;
|
||||||
|
y = -height * 0.5f + yOffset;
|
||||||
|
break;
|
||||||
|
case CENTER:
|
||||||
|
x = -width * 0.5f + xOffset;
|
||||||
|
y = -height * 0.5f + yOffset;
|
||||||
|
break;
|
||||||
|
case CENTER_RIGHT:
|
||||||
|
x = mWidth * 0.5f - width - xOffset;
|
||||||
|
y = -height * 0.5f + yOffset;
|
||||||
|
break;
|
||||||
|
case BOTTOM_LEFT:
|
||||||
|
x = -mWidth * 0.5f + xOffset;
|
||||||
|
y = mHeight * 0.5f - height - yOffset;
|
||||||
|
break;
|
||||||
|
case BOTTOM_CENTER:
|
||||||
|
x = -width * 0.5f + xOffset;
|
||||||
|
y = mHeight * 0.5f - height - yOffset;
|
||||||
|
break;
|
||||||
|
case BOTTOM_RIGHT:
|
||||||
|
x = mWidth * 0.5f - width - xOffset;
|
||||||
|
y = mHeight * 0.5f - height - yOffset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
mvp.setTransScale(x, y, invScale);
|
mvp.setTransScale(x, y, invScale);
|
||||||
mvp.multiplyLhs(proj);
|
mvp.multiplyLhs(proj);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user