Skip to content

Commit 3076f18

Browse files
Update Blend Renderer sample (#668)
* Update BlendRendererController.java * Update BlendRendererController.java * Update raster/blend-renderer/src/main/java/com/esri/samples/blend_renderer/BlendRendererController.java Co-authored-by: Jen Merritt <[email protected]> Co-authored-by: Jen Merritt <[email protected]>
1 parent 3129beb commit 3076f18

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

raster/blend-renderer/src/main/java/com/esri/samples/blend_renderer/BlendRendererController.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javafx.scene.control.Slider;
2525

2626
import com.esri.arcgisruntime.layers.RasterLayer;
27+
import com.esri.arcgisruntime.loadable.LoadStatus;
2728
import com.esri.arcgisruntime.mapping.ArcGISMap;
2829
import com.esri.arcgisruntime.mapping.Basemap;
2930
import com.esri.arcgisruntime.mapping.view.MapView;
@@ -49,15 +50,19 @@ public void initialize() {
4950
imageryRasterPath = new File(System.getProperty("data.dir"), "./samples-data/raster/Shasta.tif").getAbsolutePath();
5051
elevationRasterPath = new File(System.getProperty("data.dir"), "./samples-data/raster/Shasta_Elevation.tif").getAbsolutePath();
5152

52-
// create a raster layer
53+
// create and load a raster layer
5354
RasterLayer rasterLayer = new RasterLayer(new Raster(imageryRasterPath));
54-
55-
// create a basemap from the raster layer
56-
Basemap basemap = new Basemap(rasterLayer);
57-
ArcGISMap map = new ArcGISMap(basemap);
58-
59-
// set the map to the map view
60-
mapView.setMap(map);
55+
// when the raster has loaded create a basemap from it and create a new ArcGISMap with the basemap
56+
rasterLayer.addDoneLoadingListener(() -> {
57+
if (rasterLayer.getLoadStatus() == LoadStatus.LOADED) {
58+
Basemap basemap = new Basemap(rasterLayer);
59+
ArcGISMap map = new ArcGISMap(basemap);
60+
// set the map to the map view
61+
mapView.setMap(map);
62+
updateRenderer();
63+
}
64+
});
65+
rasterLayer.loadAsync();
6166

6267
// set defaults
6368
colorRampComboBox.getItems().setAll(ColorRamp.PresetType.values());
@@ -77,27 +82,35 @@ public void initialize() {
7782
}
7883
});
7984

80-
updateRenderer();
8185
}
8286

8387
/**
8488
* Updates the raster layer renderer according to the chosen property values.
8589
*/
8690
public void updateRenderer() {
8791

88-
ColorRamp colorRamp = colorRampComboBox.getSelectionModel().getSelectedItem() != ColorRamp.PresetType.NONE
89-
? new ColorRamp(colorRampComboBox.getSelectionModel().getSelectedItem(), 800) : null;
90-
91-
// if color ramp is not NONE, color the hillshade elevation raster instead of using satellite imagery raster color
92-
RasterLayer rasterLayer = colorRamp != null ? new RasterLayer(new Raster(elevationRasterPath))
93-
: new RasterLayer(new Raster(imageryRasterPath));
92+
ColorRamp colorRamp;
93+
// if the color ramp selection is none, don't apply a color ramp otherwise apply the selected color ramp
94+
if (colorRampComboBox.getSelectionModel().getSelectedItem() == ColorRamp.PresetType.NONE) {
95+
colorRamp = null;
96+
} else {
97+
colorRamp = new ColorRamp(colorRampComboBox.getSelectionModel().getSelectedItem(), 800);
98+
}
9499

100+
// if color ramp is NONE, use the satellite imagery raster color instead of coloring the hillshade elevation raster
101+
RasterLayer rasterLayer;
102+
if (colorRamp == null) {
103+
rasterLayer = new RasterLayer(new Raster(imageryRasterPath));
104+
} else {
105+
rasterLayer = new RasterLayer(new Raster(elevationRasterPath));
106+
}
107+
// set the basemap to the raster layer
95108
mapView.getMap().setBasemap(new Basemap(rasterLayer));
96109

97-
// create blend renderer
110+
// create blend renderer and set it to the raster layer
98111
BlendRenderer blendRenderer = new BlendRenderer(new Raster(elevationRasterPath), Collections.singletonList(9.0),
99-
Collections.singletonList(255.0), null, null, null, null, colorRamp, altitudeSlider.getValue(),
100-
azimuthSlider.getValue(), 1, slopeTypeComboBox.getSelectionModel().getSelectedItem(), 1, 1, 8);
112+
Collections.singletonList(255.0), null, null, null, null, colorRamp, altitudeSlider.getValue(),
113+
azimuthSlider.getValue(), 1, slopeTypeComboBox.getSelectionModel().getSelectedItem(), 1, 1, 8);
101114

102115
rasterLayer.setRasterRenderer(blendRenderer);
103116
}

0 commit comments

Comments
 (0)