Select to view content in your preferred language

How to center the map depending on graphics on it ?

5946
11
08-04-2016 04:50 AM
MohamedEzzerI
Deactivated User

How to center the map depending on graphics on it ?
it means that all graphics on map, (markers, plygons and polylines) must be shown

0 Kudos
11 Replies
AlexanderNohe1
Honored Contributor

Mohamed EzzerI

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!

MohamedEzzerI
Deactivated User

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>

0 Kudos
AlexanderNohe1
Honored Contributor

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?

0 Kudos
MohamedEzzerI
Deactivated User

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>

0 Kudos
AlexanderNohe1
Honored Contributor

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.

0 Kudos
MohamedEzzerI
Deactivated User

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());
        }
    }

});


//----------createMarker()------------//
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();
    }
}
0 Kudos
AlexanderNohe1
Honored Contributor

It looks as though those JSON files you are using are not currently available.

MohamedEzzerI
Deactivated User

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>

0 Kudos
MohamedEzzerI
Deactivated User

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

0 Kudos