Zoom to an array of geometries

939
4
06-20-2017 07:08 AM
jonataspovoas
New Contributor III

I I've been creating an app for android using the Arcgis Runtime SDK for Android 100.0. In it, I have an activity that receives an array of points, and I need to zoom the map so this all geometries in the array are shown at the it.

I know that there's a method setExtent(geometry) that zoom to any geometry, but I need to set my Extent to an array of them.

0 Kudos
4 Replies
AlexanderNohe1
Occasional Contributor III

(untested)

                Double latMin = null;
                Double latMax = null;
                Double lonMin = null;
                Double lonMax = null;
                for (Geometry geom : geometryArray) {
                    Envelope item = geom.getExtent()
                    if(latMin == null) {
                        latMin = item.getYMin();
                        latMax = item.getYMax();
                        lonMin = item.getXMin();
                        lonMax = item.getXMax();
                    } else {
                        if (latMin > item.getYMin()) {
                            latMin = itemgetYMin();
                        }
                        if (latMax < item.getYMax()) {
                            latMax = item.getYMax();
                        }
                        if (lonMin > item.getXMin()) {
                            lonMin = item.getXMin();
                        }
                        if (lonMax < item.getXMax()) {
                            lonMax = item.getXMax();
                        }
                    }
                }

               Envelope ev = new Envelope(latMin, latMax, lonMin, lonMax, SpatialReferences.getWebMercator());

You probably want something like this 

ShellyGill1
Esri Contributor

Also look out for a new method in the next release - `GeometryEngine.combineExtents` is aimed at this sort of use - you will be able to pass in any type of geometry, either two single geometries, or an Iterable, and get back an Envelope that's the extent of all the geometries passed in. Until then Alexanders way works well!

AlexanderNohe1
Occasional Contributor III

Hey sgill-esristaff‌,

While we have you here, can you provide any insight into when the next release might come out?  I know a lot of people are excited to hear this news.


Thanks,

Alexander

0 Kudos
ShellyGill1
Esri Contributor

Sorry ANohe-esristaff‌, I dont have any public info available on that - it will be announced on the blogs though!