Skip to content

Commit e70807b

Browse files
committed
Add possibility to control Placemark visibility from LevelOfDetailsSelector via return parameter instead of nulling PlacamerkAttributes.
1 parent 1129ef0 commit e70807b

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

worldwind-examples/src/main/java/gov/nasa/worldwindx/PlacemarksDemoActivity.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ public PlaceLevelOfDetailSelector(Resources resources, Place place) {
142142
* @param rc
143143
* @param placemark The placemark needing a level of detail selection
144144
* @param cameraDistance The distance from the placemark to the camera (meters)
145+
*
146+
* @return if placemark should display or skip its rendering
145147
*/
146148
@Override
147-
public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
149+
public boolean selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
148150

149151
boolean highlighted = placemark.isHighlighted();
150152
boolean highlightChanged = this.lastHighlightState != highlighted;
@@ -213,7 +215,13 @@ public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double ca
213215
this.lastHighlightState = highlighted;
214216

215217
// Update the placemark's attributes bundle
216-
placemark.setAttributes(this.attributes);
218+
if (this.attributes != null) {
219+
this.attributes.setDrawLabel(highlighted || cameraDistance <= LEVEL_1_DISTANCE);
220+
placemark.setAttributes(this.attributes);
221+
return true; // Placemark visible
222+
} else {
223+
return false; // Placemark invisible
224+
}
217225
}
218226

219227
protected static PlacemarkAttributes getPlacemarkAttributes(Resources resources, Place place) {

worldwind-examples/src/main/java/gov/nasa/worldwindx/milstd2525/MilStd2525LevelOfDetailSelector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ public static void setNearThreshold(double nearThreshold) {
5959
* @param rc The current render contents
6060
* @param placemark The placemark needing a level of detail selection
6161
* @param cameraDistance The distance from the placemark to the camera (meters)
62+
*
63+
* @return if placemark should display or skip its rendering
6264
*/
6365
@Override
64-
public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
66+
public boolean selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance) {
6567
if (!(placemark instanceof MilStd2525Placemark)) {
6668
throw new IllegalArgumentException(
6769
Logger.logMessage(Logger.ERROR, "MilStd2525LevelOfDetailSelector", "selectLevelOfDetail",
@@ -108,5 +110,7 @@ public void selectLevelOfDetail(RenderContext rc, Placemark placemark, double ca
108110
if (this.placemarkAttributes != null) {
109111
milStdPlacemark.setAttributes(this.placemarkAttributes);
110112
}
113+
114+
return true; // Placemark is always visible
111115
}
112116
}

worldwind/src/main/java/gov/nasa/worldwind/shape/Placemark.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public interface LevelOfDetailSelector {
4949
* @param rc The current render context
5050
* @param placemark The placemark needing a level of detail selection
5151
* @param cameraDistance The distance from the placemark to the camera (meters)
52+
*
53+
* @return if placemark should display or skip its rendering
5254
*/
53-
void selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance);
55+
boolean selectLevelOfDetail(RenderContext rc, Placemark placemark, double cameraDistance);
5456
}
5557

5658
/**
@@ -702,8 +704,9 @@ protected void doRender(RenderContext rc) {
702704
}
703705

704706
// Allow the placemark to adjust the level of detail based on distance to the camera
705-
if (this.levelOfDetailSelector != null) {
706-
this.levelOfDetailSelector.selectLevelOfDetail(rc, this, this.cameraDistance);
707+
if (this.levelOfDetailSelector != null
708+
&& !this.levelOfDetailSelector.selectLevelOfDetail(rc, this, this.cameraDistance)) {
709+
return; // skip rendering
707710
}
708711

709712
// Determine the attributes to use for the current render pass.

0 commit comments

Comments
 (0)