View on GitHub Sample viewer app

Display a basemap centered at an initial location and scale.

Image of set initial map location

Use case

You can set a map’s initial location when you want to highlight a particular feature or area to establish the context.

How to use the sample

When the map loads, note the specific location and scale of the initial map view.

How it works

  1. Create an ArcGISMap, specifying a basemap style.
  2. Display the map in a map view.
  3. Set a Viewpoint on the map view, specifying the latitude, longitude and scale.

Relevant API

  • ArcGISMap
  • BasemapStyle
  • MapView
  • Viewpoint

About the data

The map opens with a basemap centred over East Scotland.

Tags

basemap, center, envelope, extent, initial, lat, latitude, level of detail, location, LOD, long, longitude, scale, zoom level

Sample Code

module-info.java module-info.java SetInitialMapLocationSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.set_initial_map_location {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
exports com.esri.samples.set_initial_map_location;
}