Handling Zooming function using Direct ScaleValue of Zoomlevel

480
1
09-24-2019 08:23 AM
S_MMaruf
New Contributor II

Hi,

I want  to develop zoom function (ZoomIn and ZoomOut)  by using ScaleValue of those ZoomLevel. At first , I stored those scalevalue of zoomlevels  in a array and I also create two button action (eg. ZoomIn and ZoomOut ) and   for ZoomIn fuction , i increase index number of array and for zoomOut function decrease index number of array to get map into desire zoom level. but in my map application , MapView is not zoomIn or Zoomout  ,  I use map.setReferenceScale() property but is not working , so my question is "is there any other property in which i use scaleValue of zoom levels for execute zoom function in in arcgis runtime sdk in Java ".  i have done some code for my application.

double [] ZoomScaleValueArr = {5.91657527591555E8,2.95828763795777E8,1.47914381897889E8,7.3957190948944E7,3.6978595474472E7,1.8489297737236E7,
9244648.868618,4622324.434309,2311162.217155,1155581.108577,577790.554289, 288895.277144,144447.638572, 72223.819286,36111.909643,
18055.954822,9027.977411,4513.988705,2256.994353,1128.497176,564.248588 };

public void setZoom(int zoom) {
if(minZoom <= zoom && zoom <= maxZoom)
{

double destScale = ZoomScaleValueArr[zoom];
//map do zooming to destinationScale
map.setReferenceScale(destScale);
Point centerPoint = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE).getTargetGeometry().getExtent().getCenter();
double currentReferenceScale = mapView.getMap().getReferenceScale();
Viewpoint newViewPoint = new Viewpoint(centerPoint, currentReferenceScale);
mapView.setViewpoint(newViewPoint);
System.out.println(currentReferenceScale);
System.out.println(centerPoint);
}

}

//zoomIn Function

zoomInBtn.setOnAction(actionEvent -> {
zoomOutBtn.setDisable(false);
zoomValue++;
map.setZoom(zoomValue);
if (zoomValue >= 15) {
zoomInBtn.setDisable(true);

}

});
//zoomOut Function
zoomOutBtn.setOnAction(actionEvent -> {
zoomInBtn.setDisable(false);
zoomValue--;
map.setZoom(zoomValue);

if (zoomValue <= 5) {

zoomOutBtn.setDisable(true);

}
});

0 Kudos
1 Reply
MarkBaird
Esri Regular Contributor

I'm not sure that you want to be changing the reference scale of your map.  This is for working with annotation for example where you want to set the optimal scale for viewing your data on the map.  This doesn't change the scale of the map.  This explains why your app isn't functioning as you expected.

I've not tried out your code, but I suspect you simply want to change the scale of your MapView.  So if you wanted to alter the scale of your MapView to 1:50000 for example you would use the following code:

mapView.setViewpointScaleAsync(50000);

There are various methods on the MapView class which work with ViewPoints you can experiment with.

MapView (ArcGIS Runtime SDK for Java 100.6.0) 

0 Kudos