2

I need to dynamically set the extent when the map loads. I have graphics that are being added to the map layer and want the extent to allow all the graphics to be shown.

Currently I am getting a min x and y value and max x and y value based off the points that are being used to add the graphics.

Then I try to use set extent with an envelope that contains the min and max values of x and y.

So am I missing something to set the bounds so that the map will show the correct portion of the map?

1
  • 1
    Any code to share? Are you setting the extent in the OnStatusChangedListener? Some operations can only be set after MapView has been initialized. – jdONeill Aug 22 '14 at 0:26
1

I'm not entirely familiar with the android API, but in the JavaScript API, there's a function that allows you to take an array of graphics and extract the bounds of all returned features as if it were a single feature, then use a centerAndZoom() method to zoom the map to the graphic. Maybe the Android API has something similar?

5
  • It is important that you wait for GraphicLayers to be initialized before trying to get extents used to set bounds dynamically. The Android API does not have a centerAndZoom() method. The API allows you to center but the developer manages the zoom. – jdONeill Aug 22 '14 at 19:22
  • It does. Just looked it up. Go to the android API reference and look up com.esri.android.map.MapView. Then scroll down the page and you find the available methods. It's the fourth method listed. HTTPS://developers.arcgis.com/android/api-reference – JavaScript_Guru Aug 22 '14 at 19:28
  • Yep, you are correct on the MapView, my bad, I was thinking of an issue we have when using the LocationDisplayManager which does not do this. Off topic though, until we find out when @venom is trying to set the bounds. – jdONeill Aug 22 '14 at 19:31
  • It should work. In the JS API, I do the same thing when a buffer query is included in the url. I just let the map load, and within 1 second, the geometry data is returned, converted to a graphic, then the map is zoomed to that extent. Should work the same in Android, from what little I have dabbled in it. – JavaScript_Guru Aug 22 '14 at 19:37
  • In Android it is more specific than that, the calls should be made after GraphicsLayers are loaded, this is ensured with OnStatusChangedListener. Queries should be run on a background thread. – jdONeill Aug 22 '14 at 19:40

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.