Location renderers: allow fixed center position

This commit is contained in:
Emux 2019-10-17 15:00:53 +03:00
parent faed3d05a5
commit 4c10d5848b
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
3 changed files with 87 additions and 35 deletions

View File

@ -1,4 +1,5 @@
/*
* Copyright 2014 Hannes Janetzek
* Copyright 2016-2019 devemux86
* Copyright 2017 Luca Osten
* 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.
* Range is [-1, 1].
*/
public float[] getMapViewCenter() {
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.
* Range is [-1, 1].
*/
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;
}
/**
* 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;
}

View File

@ -66,6 +66,7 @@ public class LocationRenderer extends LayerRenderer {
private boolean mRunAnim;
private boolean mAnimate = true;
private long mAnimStart;
private boolean mCenter;
private Callback mCallback;
private final float[] mColors = new float[4];
@ -97,6 +98,10 @@ public class LocationRenderer extends LayerRenderer {
mCallback = callback;
}
public void setCenter(boolean center) {
mCenter = center;
}
public void setColor(int color) {
float a = Color.aToFloat(color);
mColors[0] = a * Color.rToFloat(color);
@ -168,33 +173,39 @@ public class LocationRenderer extends LayerRenderer {
return;
}
/*if (!v.changed() && isReady())
return;*/
/*if (!v.changed() && isReady())
return;*/
setReady(true);
int width = mMap.getWidth();
int height = mMap.getHeight();
// clamp location to a position that can be
// savely translated to screen coordinates
v.getBBox(mBBox, 0);
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
// safely translated to screen coordinates
v.getBBox(mBBox, 0);
double x = mLocation.x;
double y = mLocation.y;
x = mLocation.x;
y = mLocation.y;
if (!mBBox.contains(mLocation)) {
x = FastMath.clamp(x, mBBox.xmin, mBBox.xmax);
y = FastMath.clamp(y, mBBox.ymin, mBBox.ymax);
if (!mBBox.contains(mLocation)) {
x = FastMath.clamp(x, mBBox.xmin, mBBox.xmax);
y = FastMath.clamp(y, mBBox.ymin, mBBox.ymax);
}
// get position of Location in pixel relative to
// screen center
v.toScreenPoint(x, y, mScreenPoint);
x = mScreenPoint.x + (width >> 1);
y = mScreenPoint.y + (height >> 1);
}
// get position of Location in pixel relative to
// screen center
v.toScreenPoint(x, y, mScreenPoint);
x = mScreenPoint.x + width / 2;
y = mScreenPoint.y + height / 2;
// clip position to screen boundaries
int visible = 0;

View File

@ -1,6 +1,6 @@
/*
* 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
* 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 animate = true;
private long animStart;
private boolean center;
private boolean update;
private float bearing;
@ -124,6 +125,10 @@ public class LocationTextureRenderer extends BucketRenderer {
this.billboard = billboard;
}
public void setCenter(boolean center) {
this.center = center;
}
public void setIndicatorColor(int color) {
this.viewShedColor = color;
}
@ -194,23 +199,30 @@ public class LocationTextureRenderer extends BucketRenderer {
int width = map.getWidth();
int height = map.getHeight();
v.getBBox(boundingBox, 0);
double x = mapPoint.x;
double y = mapPoint.y;
double x, y;
if (center) {
x = (width >> 1) + width * map.viewport().getMapViewCenterX();
y = (height >> 1) + height * map.viewport().getMapViewCenterY();
} else {
v.getBBox(boundingBox, 0);
if (!boundingBox.contains(mapPoint)) {
x = FastMath.clamp(x, boundingBox.xmin, boundingBox.xmax);
y = FastMath.clamp(y, boundingBox.ymin, boundingBox.ymax);
x = mapPoint.x;
y = mapPoint.y;
if (!boundingBox.contains(mapPoint)) {
x = FastMath.clamp(x, boundingBox.xmin, boundingBox.xmax);
y = FastMath.clamp(y, boundingBox.ymin, boundingBox.ymax);
}
// get position of Location in pixel relative to
// screen center
v.toScreenPoint(x, y, screenPoint);
x = screenPoint.x + width / 2;
y = screenPoint.y + height / 2;
}
// get position of Location in pixel relative to
// screen center
v.toScreenPoint(x, y, screenPoint);
x = screenPoint.x + width / 2;
y = screenPoint.y + height / 2;
// clip position to screen boundaries
int visible = 0;