What I would do, if working with only one layer, is use the getFullExtent() method on that layer and then use mapView.setExtent to then set the extent that I would like to zoom to. This of course would all have to occur after the layer is fully initialized.
Layer.GetFullExtent()
Layer | ArcGIS Android 10.2.8 API
MapView.SetExtent()
MapView | ArcGIS Android 10.2.8 API
I hope this helps!
It didn't work, it's focus to the center of the map
Le 4 août 2016 13:05, "Alexander Nohe" <geonet@esri.com> a écrit :
GeoNet <https://community.esri.com/?et=watches.email.thread>
How to center the map depending on graphics on it ?
reply from Alexander Nohe
<https://community.esri.com/people/ANohe-esristaff?et=watches.email.thread>
in ArcGIS Runtime SDK for Android - View the full discussion
<https://community.esri.com/message/625776?et=watches.email.thread#comment-625776>
Are you waiting for the map to be fully initialized?
mapView.setOnStatusChangedListener(new OnStatusChangedListener() { @Override public void onStatusChanged(Object o, STATUS status) { if (status == STATUS.INITIALIZED) { //Do Something } } });
Additionally, are you placing your coordinates in web mercator projection?
Thx for the feedback, i dont understand what do you mean by mercator
projection, but i can tell you that i m placing my coordinates using
mvHelper.addMarkerGraphic and mvHelper.addPolygonGraphic
Le 5 août 2016 14:25, "Alexander Nohe" <geonet@esri.com> a écrit :
GeoNet <https://community.esri.com/?et=watches.email.thread>
How to center the map depending on graphics on it ?
reply from Alexander Nohe
<https://community.esri.com/people/ANohe-esristaff?et=watches.email.thread>
in ArcGIS Runtime SDK for Android - View the full discussion
<https://community.esri.com/message/626204?et=watches.email.thread#comment-626204>
This should explain projections:
Spatial references—ArcGIS Runtime SDK for Android | ArcGIS for Developers
Mapping Projections Explained
Additionally, what code are you using to zoom to the extent? It is possible that if you are zooming to -38, 71, that you will be zoomed into the center of the map because the map projections unit of measurement would then be in meters, not decimal degrees as you may expect.
Hi Alexander, thnx for your help,
I'm using the code below, and i want to center the camera after creating all of the markers and ploygons
//------------------
mvHelper = new MapViewHelper(arcMap); arcMap.setOnStatusChangedListener(new OnStatusChangedListener() { public void onStatusChanged(Object source, STATUS status) { if (status == STATUS.INITIALIZED) { mvHelper.setShowGraphicCallout(true); createMarker(); createPolygon(); arcMap.setExtent(graphicsLayer.getFullExtent()); } }
});
public void createMarker() { String url = "http://screendydev.cloudapp.net/screendy/files/projects/mytest/res/others/markers.json"; final String resp = StudioUtilities.sendGetRequest(url); final Drawable icon = ContextCompat.getDrawable(ctx, R.drawable.map_marker); try { JSONObject jsonObject = new JSONObject(resp); JSONArray jsonArray = jsonObject.getJSONArray("markers"); int count = 0; while (count < jsonArray.length()) { JSONObject marker = jsonArray.getJSONObject(count); int loaded = mvHelper.addMarkerGraphic( Double.parseDouble(marker.getString("latitude")), Double.parseDouble(marker.getString("longitude")), /*marker.getString("title"), marker.getString("subtitle"), null, icon, false, 0);*/ marker.getString("title"), marker.getString("subtitle"), null, icon, false, 1); if (loaded < 0) { Log.d("TAG", "Marker Graphic not added to MapView"); } else { graphicsLayer.getGraphic(loaded); } count++; } } catch (JSONException e) { e.printStackTrace(); } } //----------createPolygon------------//public void createPolygon() { String url = "http://screendydev.cloudapp.net/screendy/files/projects/mytest/res/others/polygons.json"; final String resp = StudioUtilities.sendGetRequest(url); try { JSONObject jsonObject = new JSONObject(resp); JSONArray jsonArray = jsonObject.getJSONArray("polygons"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject polygon = jsonArray.getJSONObject(i); JSONObject borderObject = polygon.getJSONObject("border"); JSONObject startPointObject = polygon.getJSONObject("starting_point"); final JSONArray pointsArray = polygon.getJSONArray("points"); double[][] p = new double[pointsArray.length()][2]; for (int j = 0; j < pointsArray.length(); j++) { try { final JSONObject point = pointsArray.getJSONObject(j); p[0] = Double.parseDouble(point.getString("latitude")); p [1] = Double.parseDouble(point.getString("longitude")); } catch (JSONException e) { e.printStackTrace(); } } String title = polygon.getString("title"); String subtitle = polygon.getString("subtitle"); int size = borderObject.getInt("size"); int bgColor = adjustAlpha(Color.parseColor(polygon.getString("background"))); int borderColor = Color.parseColor(borderObject.getString("color")); mvHelper.addPolygonGraphic(p, title, subtitle, "", bgColor, borderColor, size, 1); } } catch (JSONException e) { e.printStackTrace(); } }
It looks as though those JSON files you are using are not currently available.
They are working now, it was just some maintenance on our servers
2016-08-15 14:46 GMT+01:00 Alexander Nohe <geonet@esri.com>:
GeoNet <https://community.esri.com/?et=watches.email.thread>
How to center the map depending on graphics on it ?
reply from Alexander Nohe
<https://community.esri.com/people/ANohe-esristaff?et=watches.email.thread>
in ArcGIS Runtime SDK for Android - View the full discussion
<https://community.esri.com/message/628093-re-how-to-center-the-map-depending-on-graphics-on-it?commentID=628093&et=watches.email.thread#comment-628093>
Hi Alexander Nohe, i wish u have a good day, i still need your precious help in that problem, i wish that you could help me