Skip to content

Commit 49cc72e

Browse files
committed
updated to use checkboxes instead of controlsfx component
1 parent acbd3c9 commit 49cc72e

File tree

4 files changed

+40
-50
lines changed

4 files changed

+40
-50
lines changed
-81.2 KB
Loading

src/main/java/com/esri/samples/imagelayers/map_image_layer_sublayer_visibility/MapImageLayerSublayerVisibilitySample.java

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,26 @@
1616

1717
package com.esri.samples.imagelayers.map_image_layer_sublayer_visibility;
1818

19-
import org.controlsfx.control.CheckComboBox;
20-
2119
import com.esri.arcgisruntime.layers.ArcGISMapImageLayer;
20+
import com.esri.arcgisruntime.layers.ArcGISSublayer;
2221
import com.esri.arcgisruntime.layers.SublayerList;
2322
import com.esri.arcgisruntime.mapping.ArcGISMap;
2423
import com.esri.arcgisruntime.mapping.Basemap;
2524
import com.esri.arcgisruntime.mapping.view.MapView;
2625

2726
import javafx.application.Application;
28-
import javafx.collections.FXCollections;
29-
import javafx.collections.ListChangeListener;
30-
import javafx.collections.ObservableList;
3127
import javafx.geometry.Insets;
3228
import javafx.geometry.Pos;
3329
import javafx.scene.Scene;
30+
import javafx.scene.control.CheckBox;
3431
import javafx.scene.layout.StackPane;
32+
import javafx.scene.layout.VBox;
3533
import javafx.stage.Stage;
3634

3735
public class MapImageLayerSublayerVisibilitySample extends Application {
3836

3937
private MapView mapView;
4038

41-
private SublayerList layers;
42-
43-
private CheckComboBox<String> checkComboBox;
44-
4539
// World Topo Map Service URL
4640
private static final String WORLD_CITIES_SERVICE =
4741
"http://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer";
@@ -53,41 +47,55 @@ public void start(Stage stage) throws Exception {
5347
// create a border pane and application scene
5448
StackPane stackPane = new StackPane();
5549
Scene scene = new Scene(stackPane);
50+
scene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());
51+
5652
// size the stage and add a title
5753
stage.setTitle("Map Image Layer Sublayer Visibility Sample");
5854
stage.setWidth(800);
5955
stage.setHeight(700);
6056
stage.setScene(scene);
6157
stage.show();
62-
// create the layers data to show in the CheckComboBox
63-
ObservableList<String> layersList = FXCollections.observableArrayList();
64-
layersList.add("Cities");
65-
layersList.add("Continents");
66-
layersList.add("World");
67-
// create the CheckComboBox with the data
68-
checkComboBox = new CheckComboBox<>(layersList);
69-
// set all sub layers on by default
70-
checkComboBox.getCheckModel().checkAll();
71-
checkComboBox.setPrefSize(300, 20);
72-
checkComboBox.setPadding(new Insets(20, 0, 0, 10));
73-
// handle sub layer selection
74-
checkComboBox.getCheckModel().getCheckedItems().addListener((ListChangeListener<String>) c -> layersList.forEach(
75-
this::toggleVisibility));
58+
59+
// create a control panel
60+
VBox vBoxControl = new VBox(6);
61+
vBoxControl.setMaxSize(180, 130);
62+
vBoxControl.getStyleClass().add("panel-region");
63+
64+
// create checkboxes for each sublayer
65+
CheckBox citiesBox = new CheckBox("Cities");
66+
CheckBox continentsBox = new CheckBox("Continents");
67+
CheckBox worldBox = new CheckBox("World");
68+
69+
vBoxControl.getChildren().addAll(citiesBox, continentsBox, worldBox);
70+
vBoxControl.getChildren().forEach(c -> ((CheckBox) c).setSelected(true));
71+
7672
// create a ArcGISMap with the a BasemapTyppe Topographic
7773
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 48.354406, -99.998267, 2);
74+
7875
// create a Image Layer with dynamically generated ArcGISMap images
7976
ArcGISMapImageLayer imageLayer = new ArcGISMapImageLayer(WORLD_CITIES_SERVICE);
8077
imageLayer.setOpacity(0.7f);
78+
8179
// add world cities layers as ArcGISMap operational layer
8280
map.getOperationalLayers().add(imageLayer);
81+
8382
// set the ArcGISMap to be displayed in this view
8483
mapView = new MapView();
8584
mapView.setMap(map);
85+
8686
// get the layers from the ArcGISMap image layer
87-
layers = imageLayer.getSublayers();
88-
// add the MapView and sublayers menu
89-
stackPane.getChildren().addAll(mapView, checkComboBox);
90-
StackPane.setAlignment(checkComboBox, Pos.TOP_LEFT);
87+
SublayerList layers = imageLayer.getSublayers();
88+
89+
// handle sub layer selection
90+
citiesBox.selectedProperty().addListener(e -> layers.get(0).setVisible(citiesBox.isSelected()));
91+
continentsBox.selectedProperty().addListener(e -> layers.get(1).setVisible(continentsBox.isSelected()));
92+
worldBox.selectedProperty().addListener(e -> layers.get(2).setVisible(worldBox.isSelected()));
93+
94+
// add the MapView and checkboxes
95+
stackPane.getChildren().addAll(mapView, vBoxControl);
96+
StackPane.setAlignment(vBoxControl, Pos.TOP_LEFT);
97+
StackPane.setMargin(vBoxControl, new Insets(10, 0, 0, 10));
98+
9199
} catch (Exception e) {
92100
// on any error, display the stack trace.
93101
e.printStackTrace();
@@ -112,26 +120,4 @@ public static void main(String[] args) {
112120

113121
Application.launch(args);
114122
}
115-
116-
/**
117-
* Toggle sub layer visibility.
118-
*
119-
* @param sublayer sub layer to be toggled
120-
*/
121-
private void toggleVisibility(String sublayer) {
122-
123-
int indexSublayer = checkComboBox.getCheckModel().getItemIndex(sublayer);
124-
// check if the sub layer is selected in the checkComboBox
125-
if (checkComboBox.getCheckModel().getCheckedItems().contains(sublayer)) {
126-
// sub layer is off, turn it on
127-
if (!layers.get(indexSublayer).isVisible()) {
128-
layers.get(indexSublayer).setVisible(true);
129-
}
130-
} else {
131-
// sub layer is on, turn it off
132-
if (layers.get(indexSublayer).isVisible()) {
133-
layers.get(indexSublayer).setVisible(false);
134-
}
135-
}
136-
}
137123
}

src/main/java/com/esri/samples/imagelayers/map_image_layer_sublayer_visibility/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<h2>How to use the sample</h2>
88

9-
<p>A list of ArcGISSubLayers is display in a drop down box in the top right. Each sublayer in the list has a check-box, which can be used to toggle the visibility of that particular sublayer.</p>
9+
<p>Each sublayer has a check-box which can be used to toggle the visibility of the sublayer.</p>
1010

1111
<h2>How it works</h2>
1212

src/main/resources/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313

1414
.slider .axis {
1515
-fx-tick-label-fill: white;
16+
}
17+
18+
.panel-region .check-box {
19+
-fx-text-fill: white;
1620
}

0 commit comments

Comments
 (0)