Location renderers: allow fixed center position
This commit is contained in:
parent
faed3d05a5
commit
4c10d5848b
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2014 Hannes Janetzek
|
||||||
* Copyright 2016-2019 devemux86
|
* Copyright 2016-2019 devemux86
|
||||||
* Copyright 2017 Luca Osten
|
* Copyright 2017 Luca Osten
|
||||||
* Copyright 2018 Izumi Kawashima
|
* Copyright 2018 Izumi Kawashima
|
||||||
@ -74,21 +75,49 @@ public class ViewController extends Viewport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get pivot horizontal / vertical relative to view center.
|
* Get pivot horizontal / vertical relative to view center in [-1, 1].
|
||||||
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
||||||
* Range is [-1, 1].
|
|
||||||
*/
|
*/
|
||||||
public float[] getMapViewCenter() {
|
public float[] getMapViewCenter() {
|
||||||
return new float[]{mPivotX, mPivotY};
|
return new float[]{mPivotX, mPivotY};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set pivot horizontal / vertical relative to view center.
|
* Get pivot horizontal relative to view center in [-1, 1].
|
||||||
|
*/
|
||||||
|
public float getMapViewCenterX() {
|
||||||
|
return mPivotX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get pivot vertical relative to view center in [-1, 1].
|
||||||
|
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
||||||
|
*/
|
||||||
|
public float getMapViewCenterY() {
|
||||||
|
return mPivotY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set pivot horizontal / vertical relative to view center in [-1, 1].
|
||||||
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
||||||
* Range is [-1, 1].
|
|
||||||
*/
|
*/
|
||||||
public void setMapViewCenter(float pivotX, float pivotY) {
|
public void setMapViewCenter(float pivotX, float pivotY) {
|
||||||
|
setMapViewCenterX(pivotX);
|
||||||
|
setMapViewCenterY(pivotY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set pivot horizontal relative to view center in [-1, 1].
|
||||||
|
*/
|
||||||
|
public void setMapViewCenterX(float pivotX) {
|
||||||
mPivotX = FastMath.clamp(pivotX, -1, 1) * 0.5f;
|
mPivotX = FastMath.clamp(pivotX, -1, 1) * 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set pivot horizontal / vertical relative to view center in [-1, 1].
|
||||||
|
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
|
||||||
|
*/
|
||||||
|
public void setMapViewCenterY(float pivotY) {
|
||||||
mPivotY = FastMath.clamp(pivotY, -1, 1) * 0.5f;
|
mPivotY = FastMath.clamp(pivotY, -1, 1) * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,7 @@ public class LocationRenderer extends LayerRenderer {
|
|||||||
private boolean mRunAnim;
|
private boolean mRunAnim;
|
||||||
private boolean mAnimate = true;
|
private boolean mAnimate = true;
|
||||||
private long mAnimStart;
|
private long mAnimStart;
|
||||||
|
private boolean mCenter;
|
||||||
|
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private final float[] mColors = new float[4];
|
private final float[] mColors = new float[4];
|
||||||
@ -97,6 +98,10 @@ public class LocationRenderer extends LayerRenderer {
|
|||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCenter(boolean center) {
|
||||||
|
mCenter = center;
|
||||||
|
}
|
||||||
|
|
||||||
public void setColor(int color) {
|
public void setColor(int color) {
|
||||||
float a = Color.aToFloat(color);
|
float a = Color.aToFloat(color);
|
||||||
mColors[0] = a * Color.rToFloat(color);
|
mColors[0] = a * Color.rToFloat(color);
|
||||||
@ -176,12 +181,17 @@ public class LocationRenderer extends LayerRenderer {
|
|||||||
int width = mMap.getWidth();
|
int width = mMap.getWidth();
|
||||||
int height = mMap.getHeight();
|
int height = mMap.getHeight();
|
||||||
|
|
||||||
|
double x, y;
|
||||||
|
if (mCenter) {
|
||||||
|
x = (width >> 1) + width * mMap.viewport().getMapViewCenterX();
|
||||||
|
y = (height >> 1) + height * mMap.viewport().getMapViewCenterY();
|
||||||
|
} else {
|
||||||
// clamp location to a position that can be
|
// clamp location to a position that can be
|
||||||
// savely translated to screen coordinates
|
// safely translated to screen coordinates
|
||||||
v.getBBox(mBBox, 0);
|
v.getBBox(mBBox, 0);
|
||||||
|
|
||||||
double x = mLocation.x;
|
x = mLocation.x;
|
||||||
double y = mLocation.y;
|
y = mLocation.y;
|
||||||
|
|
||||||
if (!mBBox.contains(mLocation)) {
|
if (!mBBox.contains(mLocation)) {
|
||||||
x = FastMath.clamp(x, mBBox.xmin, mBBox.xmax);
|
x = FastMath.clamp(x, mBBox.xmin, mBBox.xmax);
|
||||||
@ -192,8 +202,9 @@ public class LocationRenderer extends LayerRenderer {
|
|||||||
// screen center
|
// screen center
|
||||||
v.toScreenPoint(x, y, mScreenPoint);
|
v.toScreenPoint(x, y, mScreenPoint);
|
||||||
|
|
||||||
x = mScreenPoint.x + width / 2;
|
x = mScreenPoint.x + (width >> 1);
|
||||||
y = mScreenPoint.y + height / 2;
|
y = mScreenPoint.y + (height >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
// clip position to screen boundaries
|
// clip position to screen boundaries
|
||||||
int visible = 0;
|
int visible = 0;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2018 Longri
|
* Copyright 2017-2018 Longri
|
||||||
* Copyright 2018 devemux86
|
* Copyright 2018-2019 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
|
||||||
@ -98,6 +98,7 @@ public class LocationTextureRenderer extends BucketRenderer {
|
|||||||
private boolean runAnim;
|
private boolean runAnim;
|
||||||
private boolean animate = true;
|
private boolean animate = true;
|
||||||
private long animStart;
|
private long animStart;
|
||||||
|
private boolean center;
|
||||||
private boolean update;
|
private boolean update;
|
||||||
private float bearing;
|
private float bearing;
|
||||||
|
|
||||||
@ -124,6 +125,10 @@ public class LocationTextureRenderer extends BucketRenderer {
|
|||||||
this.billboard = billboard;
|
this.billboard = billboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCenter(boolean center) {
|
||||||
|
this.center = center;
|
||||||
|
}
|
||||||
|
|
||||||
public void setIndicatorColor(int color) {
|
public void setIndicatorColor(int color) {
|
||||||
this.viewShedColor = color;
|
this.viewShedColor = color;
|
||||||
}
|
}
|
||||||
@ -194,10 +199,16 @@ public class LocationTextureRenderer extends BucketRenderer {
|
|||||||
|
|
||||||
int width = map.getWidth();
|
int width = map.getWidth();
|
||||||
int height = map.getHeight();
|
int height = map.getHeight();
|
||||||
|
|
||||||
|
double x, y;
|
||||||
|
if (center) {
|
||||||
|
x = (width >> 1) + width * map.viewport().getMapViewCenterX();
|
||||||
|
y = (height >> 1) + height * map.viewport().getMapViewCenterY();
|
||||||
|
} else {
|
||||||
v.getBBox(boundingBox, 0);
|
v.getBBox(boundingBox, 0);
|
||||||
|
|
||||||
double x = mapPoint.x;
|
x = mapPoint.x;
|
||||||
double y = mapPoint.y;
|
y = mapPoint.y;
|
||||||
|
|
||||||
if (!boundingBox.contains(mapPoint)) {
|
if (!boundingBox.contains(mapPoint)) {
|
||||||
x = FastMath.clamp(x, boundingBox.xmin, boundingBox.xmax);
|
x = FastMath.clamp(x, boundingBox.xmin, boundingBox.xmax);
|
||||||
@ -210,6 +221,7 @@ public class LocationTextureRenderer extends BucketRenderer {
|
|||||||
|
|
||||||
x = screenPoint.x + width / 2;
|
x = screenPoint.x + width / 2;
|
||||||
y = screenPoint.y + height / 2;
|
y = screenPoint.y + height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
// clip position to screen boundaries
|
// clip position to screen boundaries
|
||||||
int visible = 0;
|
int visible = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user