0

I'm using Java with ArcGIS 100.1.0—ArcGIS Runtime SDK for Android. I have a number of locations(Point s) on the map, after I added all the markers as graphics (on a graphic overlay), I want to zoom the map to be able to see all of them with the zoom adjusting to fit them on the map. I tried drawing a polygon and getting its envelope. And used

Envelope envelope = graphicsOverlay.getExtent();
mapView.setViewInsets(  envelope.getXMin() - DEFAULT_PADDING,
                        envelope.getYMax() + DEFAULT_PADDING,
                        envelope.getXMax() + DEFAULT_PADDING,
                        envelope.getYMin() - DEFAULT_PADDING);

and I get a very bad zoom (too close) and not displaying the whole graphics.

Then I tried :

//1-we create a polygon out of these locations
PointCollection corners = new PointCollection(spatialReference);
for(Point point : points){
    corners.add(point.getX(),point.getY());
}
Polygon polygon = new Polygon(corners);

//2- we get the extent
Envelope envelope = polygon.getExtent();
mapView.setViewInsets(  envelope.getXMin() - DEFAULT_PADDING,
                        envelope.getYMax() + DEFAULT_PADDING,
                        envelope.getXMax() + DEFAULT_PADDING,
                        envelope.getYMin() - DEFAULT_PADDING);

I still have the same unwanted result. Does anyone has and answer? Coming from Google Maps API v2 Android, I used to use the latlongBound to achieve this behavior.

Another solution would be to be able to evaluate the scale that I should apply to the mapview once I am able to get the extent of the overlay on which my markers/graphics (coming from Google Maps) are displayed. Does anyone know how to get that scale?

1 Answer 1

0

The problem was that i called mapview.setViewInsets(). This is the solution:

            //1- we compile the locations in a collection
            PointCollection corners = new PointCollection(points);

            //2- we get the extent
            Envelope envelope = new Polygon(corners).getExtent();

            //3- we move the camera
            moveWithAnimation(envelope,mapView);

The code to move the camera with animation :

    /**
     *  Move the camera with an animation
     * @param envelope to fix the borders of the desired view
     * @param mapView the mapview
     */
    private static void moveWithAnimation(final Envelope envelope, final MapView mapView){
        if(envelope != null && mapView != null){
            final ListenableFuture<Boolean> listenableFuture = mapView.setViewpointGeometryAsync(envelope,DEFAULT_PADDING);
            listenableFuture.addDoneListener(new Runnable() {
               @Override
               public void run() {
                   listenableFuture.removeDoneListener(this);
               }
           });
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.