Hi
I have a map that I am working with. Let share the link of the map here:
https://www.arcgis.com/home/item.html?id=90522831f84048008015cfa83e686782
https://www.arcgis.com/apps/mapviewer/index.html?webmap=90522831f84048008015cfa83e686782
I am trying to implement this in Android.
This is my code:
MainActivity:
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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView = findViewById(R.id.mapView);
String apiKey = "";
ArcGISRuntimeEnvironment.setApiKey(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.setMap(arcGISMap);
// 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.setViewpointScaleAsync(1000.0);
mapView.addLayerViewStateChangedListener(new LayerViewStateChangedListener() {
@Override
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() {
@Override
public void onClick(View v) {
// Zoom in by dividing the current scale
mapView.setViewpointScaleAsync(mapView.getMapScale() / 1.5);
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
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:
implementation("com.esri.arcgisruntime:arcgis-android:100.15.3")
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
Thanks