Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/placemark rotation and tilt #251

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import gov.nasa.worldwind.BasicWorldWindowController;
import gov.nasa.worldwind.PickedObject;
import gov.nasa.worldwind.PickedObjectList;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.geom.Offset;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layer.RenderableLayer;
import gov.nasa.worldwind.render.ImageSource;
Expand Down Expand Up @@ -140,9 +142,11 @@ public PlaceLevelOfDetailSelector(Resources resources, Place place) {
* @param rc
* @param placemark The placemark needing a level of detail selection
* @param cameraDistance The distance from the placemark to the camera (meters)
*
* @return if placemark should display or skip its rendering
*/
@Override
public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
public boolean selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {

boolean highlighted = placemark.isHighlighted();
boolean highlightChanged = this.lastHighlightState != highlighted;
Expand Down Expand Up @@ -211,7 +215,13 @@ public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double ca
this.lastHighlightState = highlighted;

// Update the placemark's attributes bundle
placemark.setAttributes(this.attributes);
if (this.attributes != null) {
this.attributes.setDrawLabel(highlighted || cameraDistance <= LEVEL_1_DISTANCE);
placemark.setAttributes(this.attributes);
return true; // Placemark visible
} else {
return false; // Placemark invisible
}
}

protected static PlacemarkAttributes getPlacemarkAttributes(Resources resources, Place place) {
Expand Down Expand Up @@ -273,6 +283,7 @@ protected static PlacemarkAttributes createPlacemarkAttributes(Resources resourc
//IconBitmapFactory factory = new IconBitmapFactory(resources, resourceId);
//placemarkAttributes.setImageSource(ImageSource.fromBitmapFactory(factory)).setImageScale(scale);
placemarkAttributes.setImageSource(ImageSource.fromResource(resourceId)).setImageScale(scale).setMinimumImageScale(0.5);
placemarkAttributes.getLabelAttributes().setTextOffset(new Offset(WorldWind.OFFSET_PIXELS, -24, WorldWind.OFFSET_FRACTION, 0.0));
return placemarkAttributes;
}
}
Expand Down Expand Up @@ -560,6 +571,8 @@ private void createPlaceIcons() {
placemark.setLevelOfDetailSelector(new PlaceLevelOfDetailSelector(getResources(), place));
placemark.setEyeDistanceScaling(true);
placemark.setEyeDistanceScalingThreshold(PlaceLevelOfDetailSelector.LEVEL_1_DISTANCE);
placemark.setLabel(place.name);
placemark.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);

// On a background thread, we can add Placemarks to a RenderableLayer that is
// NOT attached to the WorldWindow. If the layer was attached to the WorldWindow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ protected void onPostExecute(Void notUsed) {
Placemark drone = new Placemark(
Position.fromDegrees(32.4520, 63.44553, 3000),
MilStd2525.getPlacemarkAttributes("SFAPMFQM--GIUSA", modifiers, null));
drone.getAttributes().setDrawLeader(true);

symbolLayer.addRenderable(drone);

Expand All @@ -96,6 +97,7 @@ protected void onPostExecute(Void notUsed) {
Placemark launcher = new Placemark(
Position.fromDegrees(32.4014, 63.3894, 0),
MilStd2525.getPlacemarkAttributes("SHGXUCFRMS----G", modifiers, null));
launcher.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);

symbolLayer.addRenderable(launcher);

Expand All @@ -109,6 +111,7 @@ protected void onPostExecute(Void notUsed) {
Placemark machineGun = new Placemark(
Position.fromDegrees(32.3902, 63.4161, 0),
MilStd2525.getPlacemarkAttributes("SFGPEWRH--MTUSG", modifiers, null));
machineGun.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);

symbolLayer.addRenderable(machineGun);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -266,10 +265,11 @@ public Bitmap createBitmap() {
// placement as the offset may change depending on the level of detail, for instance, the absence or
// presence of text modifiers.
Point centerPoint = imageInfo.getCenterPoint(); // The center of the core symbol
Rect bounds = imageInfo.getImageBounds(); // The extents of the image, including text modifiers
//Rect bounds = imageInfo.getImageBounds(); // The extents of the image, including text modifiers
this.placemarkOffset = new Offset(
WorldWind.OFFSET_PIXELS, centerPoint.x, // x offset
WorldWind.OFFSET_PIXELS, bounds.height() - centerPoint.y); // y offset converted to lower-left origin
// Use billboarding or lollipopping to prevent icon clipping by terrain as described in MIL-STD-2525C APPENDIX F.5.1.1.2
WorldWind.OFFSET_PIXELS, 0/*bounds.height() - centerPoint.y*/); // y offset converted to lower-left origin

// Apply the placemark offset to the attributes on the main thread. This is necessary to synchronize write
// access to placemarkAttributes from the thread that invokes this BitmapFactory and read access from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ public static void setNearThreshold(double nearThreshold) {
* @param rc The current render contents
* @param placemark The placemark needing a level of detail selection
* @param cameraDistance The distance from the placemark to the camera (meters)
*
* @return if placemark should display or skip its rendering
*/
@Override
public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
public boolean selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
if (!(placemark instanceof MilStd2525Placemark)) {
throw new IllegalArgumentException(
Logger.logMessage(Logger.ERROR, "MilStd2525LevelOfDetailSelector", "selectLevelOfDetail",
Expand Down Expand Up @@ -108,5 +110,7 @@ public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double ca
if (this.placemarkAttributes != null) {
milStdPlacemark.setAttributes(this.placemarkAttributes);
}

return true; // Placemark is always visible
}
}
7 changes: 4 additions & 3 deletions worldwind/src/main/java/gov/nasa/worldwind/shape/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ protected void makeDrawable(RenderContext rc) {
// origin at the text's bottom-left corner and axes that extend up and to the right from the origin point.
int w = texture.getWidth();
int h = texture.getHeight();
double s = this.activeAttributes.scale;
this.activeAttributes.textOffset.offsetForSize(w, h, renderData.offset);
renderData.unitSquareTransform.setTranslation(
renderData.screenPlacePoint.x - renderData.offset.x,
renderData.screenPlacePoint.y - renderData.offset.y,
renderData.screenPlacePoint.x - renderData.offset.x * s,
renderData.screenPlacePoint.y - renderData.offset.y * s,
renderData.screenPlacePoint.z);

// Apply the label's rotation according to its rotation value and orientation mode. The rotation is applied
Expand All @@ -462,7 +463,7 @@ protected void makeDrawable(RenderContext rc) {
}

// Apply the label's translation and scale according to its text size.
renderData.unitSquareTransform.multiplyByScale(w, h, 1);
renderData.unitSquareTransform.multiplyByScale(w * s, h * s, 1);

WWMath.boundingRectForUnitSquare(renderData.unitSquareTransform, renderData.screenBounds);
if (!rc.frustum.intersectsViewport(renderData.screenBounds)) {
Expand Down
Loading