Support TextureRegion to be used for MarkerSymbol (#245)
This commit is contained in:
parent
0c39ff8be0
commit
41867344e2
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016 Izumi Kawashima
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -161,7 +162,11 @@ public class MarkerRenderer extends BucketRenderer {
|
|||||||
marker = mDefaultMarker;
|
marker = mDefaultMarker;
|
||||||
|
|
||||||
SymbolItem s = SymbolItem.pool.get();
|
SymbolItem s = SymbolItem.pool.get();
|
||||||
s.set(it.x, it.y, marker.getBitmap(), true);
|
if (marker.isBitmap()) {
|
||||||
|
s.set(it.x, it.y, marker.getBitmap(), true);
|
||||||
|
} else {
|
||||||
|
s.set(it.x, it.y, marker.getTextureRegion(), true);
|
||||||
|
}
|
||||||
s.offset = marker.getHotspot();
|
s.offset = marker.getHotspot();
|
||||||
s.billboard = marker.isBillboard();
|
s.billboard = marker.isBillboard();
|
||||||
mSymbolLayer.pushSymbol(s);
|
mSymbolLayer.pushSymbol(s);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
* Copyright 2016 devemux86
|
* Copyright 2016 devemux86
|
||||||
|
* Copyright 2016 Izumi Kawashima
|
||||||
*
|
*
|
||||||
* 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,6 +20,7 @@ package org.oscim.layers.marker;
|
|||||||
|
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.core.PointF;
|
import org.oscim.core.PointF;
|
||||||
|
import org.oscim.renderer.atlas.TextureRegion;
|
||||||
|
|
||||||
public class MarkerSymbol {
|
public class MarkerSymbol {
|
||||||
/**
|
/**
|
||||||
@ -34,12 +36,64 @@ public class MarkerSymbol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Bitmap mBitmap;
|
final Bitmap mBitmap;
|
||||||
|
final TextureRegion mTextureRegion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hotspot offset
|
* Hotspot offset
|
||||||
*/
|
*/
|
||||||
final PointF mOffset;
|
final PointF mOffset;
|
||||||
final boolean mBillboard;
|
final boolean mBillboard;
|
||||||
|
|
||||||
|
public MarkerSymbol(TextureRegion textureRegion, float relX, float relY) {
|
||||||
|
this(textureRegion, relX, relY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkerSymbol(TextureRegion textureRegion, float relX, float relY, boolean billboard) {
|
||||||
|
mBitmap = null;
|
||||||
|
mTextureRegion = textureRegion;
|
||||||
|
mOffset = new PointF(relX, relY);
|
||||||
|
mBillboard = billboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkerSymbol(TextureRegion textureRegion, HotspotPlace hotspot) {
|
||||||
|
this(textureRegion, hotspot, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkerSymbol(TextureRegion textureRegion, HotspotPlace hotspot, boolean billboard) {
|
||||||
|
mBitmap = null;
|
||||||
|
mTextureRegion = textureRegion;
|
||||||
|
switch (hotspot) {
|
||||||
|
case BOTTOM_CENTER:
|
||||||
|
mOffset = new PointF(0.5f, 1);
|
||||||
|
break;
|
||||||
|
case TOP_CENTER:
|
||||||
|
mOffset = new PointF(0.5f, 0);
|
||||||
|
break;
|
||||||
|
case RIGHT_CENTER:
|
||||||
|
mOffset = new PointF(1, 0.5f);
|
||||||
|
break;
|
||||||
|
case LEFT_CENTER:
|
||||||
|
mOffset = new PointF(0, 0.5f);
|
||||||
|
break;
|
||||||
|
case UPPER_RIGHT_CORNER:
|
||||||
|
mOffset = new PointF(1, 0);
|
||||||
|
break;
|
||||||
|
case LOWER_RIGHT_CORNER:
|
||||||
|
mOffset = new PointF(1, 1);
|
||||||
|
break;
|
||||||
|
case UPPER_LEFT_CORNER:
|
||||||
|
mOffset = new PointF(0, 0);
|
||||||
|
break;
|
||||||
|
case LOWER_LEFT_CORNER:
|
||||||
|
mOffset = new PointF(0, 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mOffset = new PointF(0.5f, 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
mBillboard = billboard;
|
||||||
|
}
|
||||||
|
|
||||||
public MarkerSymbol(Bitmap bitmap, float relX, float relY) {
|
public MarkerSymbol(Bitmap bitmap, float relX, float relY) {
|
||||||
this(bitmap, relX, relY, true);
|
this(bitmap, relX, relY, true);
|
||||||
}
|
}
|
||||||
@ -48,6 +102,7 @@ public class MarkerSymbol {
|
|||||||
mBitmap = bitmap;
|
mBitmap = bitmap;
|
||||||
mOffset = new PointF(relX, relY);
|
mOffset = new PointF(relX, relY);
|
||||||
mBillboard = billboard;
|
mBillboard = billboard;
|
||||||
|
mTextureRegion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MarkerSymbol(Bitmap bitmap, HotspotPlace hotspot) {
|
public MarkerSymbol(Bitmap bitmap, HotspotPlace hotspot) {
|
||||||
@ -87,6 +142,7 @@ public class MarkerSymbol {
|
|||||||
|
|
||||||
mBitmap = bitmap;
|
mBitmap = bitmap;
|
||||||
mBillboard = billboard;
|
mBillboard = billboard;
|
||||||
|
mTextureRegion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBillboard() {
|
public boolean isBillboard() {
|
||||||
@ -97,14 +153,28 @@ public class MarkerSymbol {
|
|||||||
return mOffset;
|
return mOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBitmap() {
|
||||||
|
return mBitmap != null;
|
||||||
|
}
|
||||||
|
|
||||||
public Bitmap getBitmap() {
|
public Bitmap getBitmap() {
|
||||||
return mBitmap;
|
return mBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextureRegion getTextureRegion() {
|
||||||
|
return mTextureRegion;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInside(float dx, float dy) {
|
public boolean isInside(float dx, float dy) {
|
||||||
/* TODO handle no-billboard */
|
/* TODO handle no-billboard */
|
||||||
int w = mBitmap.getWidth();
|
int w, h;
|
||||||
int h = mBitmap.getHeight();
|
if (isBitmap()) {
|
||||||
|
w = mBitmap.getWidth();
|
||||||
|
h = mBitmap.getHeight();
|
||||||
|
} else {
|
||||||
|
w = mTextureRegion.rect.w;
|
||||||
|
h = mTextureRegion.rect.h;
|
||||||
|
}
|
||||||
float ox = -w * mOffset.x;
|
float ox = -w * mOffset.x;
|
||||||
float oy = -h * (1 - mOffset.y);
|
float oy = -h * (1 - mOffset.y);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user