diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java index d6a8280c6a..0d21fd2c71 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java @@ -20,54 +20,54 @@ import java.util.List; public class GeoParseUtil { - public static String loadStringFromAssets(final Context context, final String fileName) throws IOException { - if (TextUtils.isEmpty(fileName)) { - throw new NullPointerException("No GeoJSON File Name passed in."); - } - InputStream is = context.getAssets().open(fileName); - BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); - return readAll(rd); + public static String loadStringFromAssets(final Context context, final String fileName) throws IOException { + if (TextUtils.isEmpty(fileName)) { + throw new NullPointerException("No GeoJSON File Name passed in."); } + InputStream is = context.getAssets().open(fileName); + BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + return readAll(rd); + } - public static List<LatLng> parseGeoJSONCoordinates(String geojsonStr) throws JSONException { - List<LatLng> latLngs = new ArrayList<>(); - JSONObject jsonObject = new JSONObject(geojsonStr); - JSONArray features = jsonObject.getJSONArray("features"); - int featureLength = features.length(); - for (int j = 0; j < featureLength; ++j) { - JSONObject feature = features.getJSONObject(j); - JSONObject geometry = feature.getJSONObject("geometry"); - String type = geometry.getString("type"); - JSONArray coordinates; - if (type.equals("Polygon")) { - coordinates = geometry.getJSONArray("coordinates").getJSONArray(0); - } else { - coordinates = geometry.getJSONArray("coordinates"); - } - int len = coordinates.length(); - for (int i = 0; i < len; ++i) { - if (coordinates.get(i) instanceof JSONArray) { - JSONArray coord = coordinates.getJSONArray(i); - double lng = coord.getDouble(0); - double lat = coord.getDouble(1); - latLngs.add(new LatLng(lat, lng)); - } else { - double lng = coordinates.getDouble(0); - double lat = coordinates.getDouble(1); - latLngs.add(new LatLng(lat, lng)); - break; - } - } + public static List<LatLng> parseGeoJsonCoordinates(String geojsonStr) throws JSONException { + List<LatLng> latLngs = new ArrayList<>(); + JSONObject jsonObject = new JSONObject(geojsonStr); + JSONArray features = jsonObject.getJSONArray("features"); + int featureLength = features.length(); + for (int j = 0; j < featureLength; ++j) { + JSONObject feature = features.getJSONObject(j); + JSONObject geometry = feature.getJSONObject("geometry"); + String type = geometry.getString("type"); + JSONArray coordinates; + if (type.equals("Polygon")) { + coordinates = geometry.getJSONArray("coordinates").getJSONArray(0); + } else { + coordinates = geometry.getJSONArray("coordinates"); + } + int len = coordinates.length(); + for (int i = 0; i < len; ++i) { + if (coordinates.get(i) instanceof JSONArray) { + JSONArray coord = coordinates.getJSONArray(i); + double lng = coord.getDouble(0); + double lat = coord.getDouble(1); + latLngs.add(new LatLng(lat, lng)); + } else { + double lng = coordinates.getDouble(0); + double lat = coordinates.getDouble(1); + latLngs.add(new LatLng(lat, lng)); + break; } - return latLngs; + } } + return latLngs; + } - private static String readAll(Reader rd) throws IOException { - StringBuilder sb = new StringBuilder(); - int cp; - while ((cp = rd.read()) != -1) { - sb.append((char) cp); - } - return sb.toString(); + private static String readAll(Reader rd) throws IOException { + StringBuilder sb = new StringBuilder(); + int cp; + while ((cp = rd.read()) != -1) { + sb.append((char) cp); } + return sb.toString(); + } } |