AnsweredAssumed Answered

How do i create polygon using mapviewhelper ?

Question asked by mohamedezzeri on Aug 1, 2016
Latest reply on Aug 1, 2016 by ANohe-esristaff

This is my code, but not working, is there any thing wrong !?

 

 

public void createPolygon() {

        arcMap.addLayer(graphicsLayer);

 

       String url = "http://.../polygons.json";

        final String resp = StudioUtilities.sendGetRequest(url);

        arcMap.setOnStatusChangedListener(new OnStatusChangedListener() {

        private static final long serialVersionUID = 1L;

        public void onStatusChanged(Object source, STATUS status) {

        try {

                 JSONObject jsonObject = new JSONObject(resp);

                 JSONArray jsonArray = jsonObject.getJSONArray("polygons");

                 

                 int count = 0;

                 while (count < jsonArray.length()) {

                 JSONObject polygon = jsonArray.getJSONObject(count);

                 JSONObject borderObject = polygon.getJSONObject("border");

                 JSONObject startPointObject = polygon.getJSONObject("starting_point");

                 final JSONArray pointsArray = polygon.getJSONArray("points");

                  double[][] p = {

                      {

                            33.599389, -7.610728
                       },

                       {

                            33.599985, -7.597180
                       },

                       {

                            33.588879, -7.617027
                       }

                  };
                  int loaded = mvHelper.addPolygonGraphic(p, "pol_t", "pol_st", "", Color.GREEN, Color.DKGRAY, 2, 0);

                  if (loaded < 0) {

                           Toast.makeText(ctx, "Marker Graphic not added to MapView", Toast.LENGTH_SHORT).show();

                  } else {

                           Toast.makeText(ctx, "Marker Graphic is added to MapView", Toast.LENGTH_SHORT).show();

                  }
                  count++;

              }

  } catch (JSONException e) {

            e.printStackTrace();

  }

  });

}

Outcomes