Skip to content

Configure basemap style parameters

View on GitHubSample viewer app

Apply basemap style parameters customization for a basemap, such as displaying all labels in a specific language or displaying every label in their corresponding local language.

Configure basemap style parameters

Use case

When creating an application that’s used in multiple countries, basemaps can reflect the languages and cultures of the users' location. For example, if an application user is in Greece, displaying the labels on a basemap in Greek reflects the local language. Customizing the language setting on the basemap can be controlled by an application user (such as by setting preferences), or implicitly managed within the application logic (by querying the locale of the platform running the application).

How to use the sample

This sample showcases the workflow of configuring basemap style parameters by displaying a basemap with labels in different languages and launches with a Viewpoint set over Bulgaria, Greece and Turkey, as they use three different alphabets: Cyrillic, Greek, and Latin, respectively. By default, the BasemapStyleLanguageStrategy is set to LOCAL which displays all labels in their corresponding local language. This can be changed to GLOBAL, which displays all labels in English. The SpecificLanguage setting sets all labels to a selected language and overrides the BasemapStyleLanguageStrategy settings.

Pan and zoom to navigate the map and see how different labels are displayed in these countries depending on the selected BasemapStyleLanguageStrategy and SpecificLanguage: all English, all Greek, all Bulgarian, all Turkish, or each their own.

How it works

  1. Create a BasemapStyleParameters object.
  2. Configure customization preferences on the BasemapStyleParameters object, for instance:
    • setting the LanguageStrategy to BasemapStyleLanguageStrategy.LOCAL or
    • setSpecificLanguage("el") changes the label language to Greek.
  3. The SpecificLanguage always overrides the LanguageStrategy, which means the specific language needs to be set to an empty string in order to use the language strategy.
  4. Create a basemap using a BasemapStyle and the BasemapStyleParameters.
  5. Assign the configured basemap to the Map's basemap property.
  6. To modify the basemap style, for example if you want to change your preferences, repeat the above steps.

Relevant API

  • Basemap
  • BasemapStyleLanguageStrategy
  • BasemapStyleParameters
  • Map
  • MapView

About the data

The main data for this sample is the BasemapStyle which include basemaps that support both language localization and global language setting. The supported languages, along with their language code, can be found in the API's documentation.

Tags

basemap style, language, language strategy, map, point, viewpoint

Sample Code

ConfigureBasemapStyleParametersSample.java
Use dark colors for code blocksCopy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 /*  * Copyright 2024 Esri.  *  * Licensed under the Apache License, Version 2.0 (the "License"); you may not  * use this file except in compliance with the License. You may obtain a copy of  * the License at  *  * http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the  * License for the specific language governing permissions and limitations under  * the License.  */  package com.esri.samples.configure_basemap_style_parameters;  import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; import com.esri.arcgisruntime.geometry.Point; import com.esri.arcgisruntime.loadable.LoadStatus; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.Basemap; import com.esri.arcgisruntime.mapping.BasemapStyle; import com.esri.arcgisruntime.mapping.BasemapStyleLanguageStrategy; import com.esri.arcgisruntime.mapping.BasemapStyleParameters; import com.esri.arcgisruntime.mapping.view.MapView; import com.esri.arcgisruntime.mapping.Viewpoint; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.Border; import javafx.scene.layout.BorderStroke; import javafx.scene.layout.BorderStrokeStyle; import javafx.scene.layout.BorderWidths; import javafx.scene.layout.CornerRadii; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.text.Font; import javafx.stage.Stage;  public class ConfigureBasemapStyleParametersSample extends Application {  private MapView mapView;  private ArcGISMap map;  private BasemapStyleParameters basemapStyleParameters;  private VBox languageStrategyBox;  private RadioButton localRadioButton;  private ComboBox<String> specificLanguageComboBox;  private ToggleGroup languageStrategyGroup;   @Override  public void start(Stage stage) {   try {  // create stack pane and application scene  StackPane stackPane = new StackPane();  Scene scene = new Scene(stackPane);   // set title, size, and add scene to stage  stage.setTitle("Configure Basemap Style Parameters Sample");  stage.setWidth(800);  stage.setHeight(700);  stage.setScene(scene);  stage.show();   // authentication with an API key or named user is required to access basemaps and other location services  String yourAPIKey = System.getProperty("apiKey");  ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);   languageStrategyGroup = new ToggleGroup();  languageStrategyBox = new VBox();  var languageStrategyLabel = setupLabel("Set Language Strategy:");   RadioButton globalRadioButton = createRadioButton("Global", false);  localRadioButton = createRadioButton("Local", true);   Label specificLanguageLabel = setupLabel("Set Specific Language:");   specificLanguageComboBox = new ComboBox<>();  specificLanguageComboBox.getItems().addAll("Bulgarian", "Greek", "Turkish", "none");  specificLanguageComboBox.getSelectionModel().select("none");  specificLanguageComboBox.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {  setNewBasemap();  });   languageStrategyBox.getChildren().addAll(globalRadioButton, localRadioButton);   VBox controlsVBox = new VBox(10);  controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.5)"),  CornerRadii.EMPTY,  Insets.EMPTY)));  controlsVBox.setPadding(new Insets(10.0));  controlsVBox.setMaxSize(300, 100);  controlsVBox.getStyleClass().add("panel-region");  controlsVBox.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));  controlsVBox.getChildren().addAll(languageStrategyLabel, languageStrategyBox, specificLanguageLabel, specificLanguageComboBox);   map = new ArcGISMap();  mapView = new MapView();   map.addDoneLoadingListener(() -> {  if (map.getLoadStatus() == LoadStatus.LOADED) {  // add the map view and control panel to the stack pane  stackPane.getChildren().addAll(mapView, controlsVBox);  StackPane.setAlignment(controlsVBox, Pos.TOP_RIGHT);  } else if (map.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {  new Alert(Alert.AlertType.ERROR, "Map failed to load: " + map.getLoadError().getMessage()).show();  }  });   mapView.setMap(map);  setNewBasemap();  // Focus the viewpoint on an area where the different languages are best showcased: Bulgaria / Greece / Turkey  // as they use three different alphabets: Cyrillic, Greek, and Latin, respectively.  // Thus, showcasing the different functionalities in the most obvious way:  // all English, all Greek, all Bulgarian, all Turkish, or each their own.  mapView.setViewpoint(new Viewpoint(new Point(3144804, 4904598), 10000000));  } catch (Exception e) {  // on any error, display the stack trace.  e.printStackTrace();  }  }   /**  * Basemap is immutable so need to create a new one to set new parameters. Uses an OpenStreetMap basemap style,  * as they support localization.  */  private void setNewBasemap() {  if (basemapStyleParameters == null) {  basemapStyleParameters = new BasemapStyleParameters();  }   basemapStyleParameters.setLanguageStrategy(localRadioButton.isSelected() ?  BasemapStyleLanguageStrategy.LOCAL : BasemapStyleLanguageStrategy.GLOBAL);   var newValue = specificLanguageComboBox.getValue();   switch (newValue) {  // A SpecificLanguage setting overrides the BasemapStyleLanguageStrategy settings when  // the BasemapStyleParameters.specificLanguageProperty() is a non-empty string.  // Setting the specific language back to an empty string allows the strategy to be used.  case "none" -> basemapStyleParameters.setSpecificLanguage("");  case "Bulgarian" -> basemapStyleParameters.setSpecificLanguage("bg");  case "Greek" -> basemapStyleParameters.setSpecificLanguage("el");  case "Turkish" -> basemapStyleParameters.setSpecificLanguage("tr");   }  languageStrategyBox.setDisable(!newValue.equals("none"));  Basemap basemap = new Basemap(BasemapStyle.OSM_LIGHT_GRAY, basemapStyleParameters);  map.setBasemap(basemap);  }   /**  * Creates a new radio button for the control box.  *  * @param text The text displayed by the radio button.  * @param selected Whether the radio button is selected.  * @return the created radio button.  */  private RadioButton createRadioButton(String text, boolean selected) {  var radioButton = new RadioButton(text);  radioButton.setToggleGroup(languageStrategyGroup);  radioButton.setTextFill(Color.WHITE);  radioButton.setSelected(selected);  radioButton.setOnAction(e -> setNewBasemap());  return radioButton;  }   /**  * Creates a label for the control box.  *  * @param title The text displayed by the label.  * @return the created label.  */  private Label setupLabel(String title) {  var languageStrategyLabel = new Label(title);  languageStrategyLabel.setStyle("-fx-font-weight: bold; -fx-text-color: black;");  languageStrategyLabel.setFont(new Font(14));  languageStrategyLabel.setTextFill(Color.WHITE);  return languageStrategyLabel;  }   /**  * Stops and releases all resources used in application.  */  @Override  public void stop() {   if (mapView != null) {  mapView.dispose();  }  }   /**  * Opens and runs application.  *  * @param args arguments passed to this application  */  public static void main(String[] args) {   Application.launch(args);  } }

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.