Unable to zoom in and zoom out on arcGIS map in android

12-05-2023 03:04 AM
New Contributor

I have a map that I am working with. Let share the link of the map here:


I am trying to implement this in Android.

This is my code:


package com.example.arcgis;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ZoomControls;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Item;

import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.DrawStatusChangedEvent;
import com.esri.arcgisruntime.mapping.view.DrawStatusChangedListener;
import com.esri.arcgisruntime.mapping.view.LayerViewStateChangedEvent;
import com.esri.arcgisruntime.mapping.view.LayerViewStateChangedListener;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
MapView mapView = findViewById(R.id.mapView);

String apiKey = "";

// Create a PortalItem using the item ID
String itemId = "90522831f84048008015cfa83e686782";
// String itemId = "41281c51f9de45edaf1c8ed44bb10e30";

// Create a Portal object
Portal portal = new Portal("https://www.arcgis.com");

// Create a PortalItem using the Portal and item ID
PortalItem portalItem = new PortalItem(portal, itemId);

// Create an ArcGISMap from the PortalItem
ArcGISMap arcGISMap = new ArcGISMap(portalItem);

// Set the ArcGISMap to the MapView

// mapView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Point zoomToPoint = new Point(24.7136, 34.05500, mapView.getSpatialReference());
double scale = 90000.0; // Adjust this value as needed
mapView.setViewpointCenterAsync(zoomToPoint, scale);


mapView.addLayerViewStateChangedListener(new LayerViewStateChangedListener() {
public void layerViewStateChanged(LayerViewStateChangedEvent layerViewStateChangedEvent) {


ZoomControls zoomControls = findViewById(R.id.zoomControls);

zoomControls.setOnZoomInClickListener(v -> mapView.setViewpointScaleAsync(mapView.getMapScale() / 1.5));
zoomControls.setOnZoomOutClickListener(v -> mapView.setViewpointScaleAsync(mapView.getMapScale() * 1.5));

zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Zoom in by dividing the current scale
mapView.setViewpointScaleAsync(mapView.getMapScale() / 1.5);

zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Zoom out by multiplying the current scale
mapView.setViewpointScaleAsync(mapView.getMapScale() * 1.5);


Android Menifiest Permission:

<uses-permission android:name="android.permission.INTERNET" />

build.gradle File:


I have attached the videos to show the problems. The map is zoomed in and I cannot zoom out because zooming functionality is not working.

If anyone needs more information, kindly let me know

0 Kudos
1 Reply
Esri Regular Contributor

The scale is being locked to the visible range of your basemap.   If you change it to display at all scales, you will be able to zoom at all scales.    I set the visible range to world, and apps built with the Maps SDK were able to zoom all of the scales.   This is not specific to your code, it is how the Maps SDKs work.




0 Kudos