}
- *
- * To render the imported GeoJSON data onto the layer
- * {@code
layer.addLayer();}
- *
- * To remove the rendered data from the layer
- * {@code
layer.clearLayer();
}
- */
-public class GeoJsonLayer {
-
- private final GeoJsonRenderer mRenderer;
-
- private GeoJsonPointStyle mDefaultPointStyle;
-
- private GeoJsonLineStringStyle mDefaultLineStringStyle;
-
- private GeoJsonPolygonStyle mDefaultPolygonStyle;
-
- private LatLngBounds mBoundingBox;
-
- /**
- * Creates a new GeoJsonLayer object
- *
- * @param map map where the layer is to be rendered
- * @param geoJsonFile GeoJSON data to add to the layer
- */
- public GeoJsonLayer(GoogleMap map, JSONObject geoJsonFile) {
- if (geoJsonFile == null) {
- throw new IllegalArgumentException("GeoJSON file cannot be null");
- }
- mDefaultPointStyle = new GeoJsonPointStyle();
- mDefaultLineStringStyle = new GeoJsonLineStringStyle();
- mDefaultPolygonStyle = new GeoJsonPolygonStyle();
- mBoundingBox = null;
- GeoJsonParser parser = new GeoJsonParser(geoJsonFile);
- // Assign GeoJSON bounding box for FeatureCollection
- mBoundingBox = parser.getBoundingBox();
- HashMap geoJsonFeatures = new HashMap();
- for (GeoJsonFeature feature : parser.getFeatures()) {
- geoJsonFeatures.put(feature, null);
- }
- mRenderer = new GeoJsonRenderer(map, geoJsonFeatures);
- }
-
- /**
- * Creates a new GeoJsonLayer object
- *
- * @param map map where the layer is to be rendered
- * @param resourceId GeoJSON file to add to the layer
- * @param context context of the application, required to open the GeoJSON file
- * @throws IOException if the file cannot be open for read
- * @throws JSONException if the JSON file has invalid syntax and cannot be parsed successfully
- */
- public GeoJsonLayer(GoogleMap map, int resourceId, Context context)
- throws IOException, JSONException {
- this(map, createJsonFileObject(context.getResources().openRawResource(resourceId)));
- }
-
- /**
- * Takes a character input stream and converts it into a JSONObject
- *
- * @param stream character input stream representing the GeoJSON file
- * @return JSONObject with the GeoJSON data
- * @throws IOException if the file cannot be opened for read
- * @throws JSONException if the JSON file has poor structure
- */
- private static JSONObject createJsonFileObject(InputStream stream)
- throws IOException, JSONException {
- String line;
- StringBuilder result = new StringBuilder();
- // Reads from stream
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
- try {
- // Read each line of the GeoJSON file into a string
- while ((line = reader.readLine()) != null) {
- result.append(line);
- }
- } finally {
- reader.close();
- }
- // Converts the result string into a JSONObject
- return new JSONObject(result.toString());
- }
-
- /**
- * Gets an iterable of all GeoJsonFeature elements that have been added to the layer
- *
- * @return iterable of GeoJsonFeature elements
- */
- public Iterable getFeatures() {
- return mRenderer.getFeatures();
- }
-
- /**
- * Adds all the GeoJsonFeature objects parsed from the given GeoJSON data onto the map. Default
- * styles are applied if the features haven't been previously added to the layer or if the
- * layer has been cleared.
- */
- public void addLayer() {
- for (GeoJsonFeature feature : mRenderer.getFeatures()) {
- addFeature(feature);
- }
- }
-
- /**
- * Adds a GeoJsonFeature to the layer. If the point, linestring or poylgon style is set to
- * null, the relevant default styles are applied.
- *
- * @param feature GeoJsonFeature to add to the layer
- */
- public void addFeature(GeoJsonFeature feature) {
- // Check if no style and apply default styles
- if (feature.getPointStyle() == null) {
- feature.setPointStyle(mDefaultPointStyle);
- }
- if (feature.getLineStringStyle() == null) {
- feature.setLineStringStyle(mDefaultLineStringStyle);
- }
- if (feature.getPolygonStyle() == null) {
- feature.setPolygonStyle(mDefaultPolygonStyle);
- }
- mRenderer.addFeature(feature);
- }
-
- /**
- * Removes the given GeoJsonFeature from the layer
- *
- * @param feature feature to remove
- */
- public void removeFeature(GeoJsonFeature feature) {
- mRenderer.removeFeature(feature);
- }
-
- /**
- * Gets the map on which the layer is rendered
- *
- * @return map on which the layer is rendered
- */
- public GoogleMap getMap() {
- return mRenderer.getMap();
- }
-
- /**
- * Renders the layer on the given map. The layer on the current map is removed and
- * added to the given map.
- *
- * @param map to render the layer on, if null the layer is cleared from the current map
- */
- public void setMap(GoogleMap map) {
- mRenderer.setMap(map);
- }
-
- /**
- * Clears all of the GeoJsonFeatures from the layer. All styles are removed from the
- * GeoJsonFeatures.
- */
- public void clearLayer() {
- mRenderer.removeLayerFromMap();
- }
-
- /**
- * Gets the default style used to render GeoJsonPoints
- *
- * @return default style used to render GeoJsonPoints
- */
- public GeoJsonPointStyle getDefaultPointStyle() {
- return mDefaultPointStyle;
- }
-
- /**
- * Sets the default style to use when rendering GeoJsonPoints. This style is only applied to
- * GeoJsonPoints that are added after this method is called.
- *
- * @param geoJsonPointStyle to set as the default style for GeoJsonPoints
- */
- public void setDefaultPointStyle(GeoJsonPointStyle geoJsonPointStyle) {
- if (geoJsonPointStyle == null) {
- throw new IllegalArgumentException("Default style cannot be null");
- }
- mDefaultPointStyle = geoJsonPointStyle;
- }
-
- /**
- * Gets the default style used to render GeoJsonLineStrings
- *
- * @return default style used to render GeoJsonLineStrings
- */
- public GeoJsonLineStringStyle getDefaultLineStringStyle() {
- return mDefaultLineStringStyle;
- }
-
- /**
- * Sets the default style to use when rendering GeoJsonLineStrings. This style is only applied
- * to GeoJsonLineStrings that are added after this method is called.
- *
- * @param geoJsonLineStringStyle to set as the default style for GeoJsonLineStrings
- */
- public void setDefaultLineStringStyle(GeoJsonLineStringStyle geoJsonLineStringStyle) {
- if (geoJsonLineStringStyle == null) {
- throw new IllegalArgumentException("Default style cannot be null");
- }
- mDefaultLineStringStyle = geoJsonLineStringStyle;
- }
-
- /**
- * Gets the default style used to render GeoJsonPolygons
- *
- * @return default style used to render GeoJsonPolygons
- */
- public GeoJsonPolygonStyle getDefaultPolygonStyle() {
- return mDefaultPolygonStyle;
- }
-
- /**
- * Sets the default style to use when rendering GeoJsonPolygons. This style is only applied to
- * GeoJsonPolygons that are added after this method is called.
- *
- * @param geoJsonPolygonStyle to set as the default style for GeoJsonPolygons
- */
- public void setDefaultPolygonStyle(GeoJsonPolygonStyle geoJsonPolygonStyle) {
- if (geoJsonPolygonStyle == null) {
- throw new IllegalArgumentException("Default style cannot be null");
- }
- mDefaultPolygonStyle = geoJsonPolygonStyle;
- }
-
- /**
- * Gets the LatLngBounds containing the coordinates of the bounding box for the
- * FeatureCollection. If the FeatureCollection did not have a bounding box or if the GeoJSON
- * file did not contain a FeatureCollection then null will be returned.
- *
- * @return LatLngBounds containing bounding box of FeatureCollection, null if no bounding box
- */
- public LatLngBounds getBoundingBox() {
- return mBoundingBox;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("Collection{");
- sb.append(",\n Point style=").append(mDefaultPointStyle);
- sb.append(",\n LineString style=").append(mDefaultLineStringStyle);
- sb.append(",\n Polygon style=").append(mDefaultPolygonStyle);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonLineString.java b/library/src/com/google/maps/android/geojson/GeoJsonLineString.java
deleted file mode 100644
index 73e94c205..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonLineString.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.model.LatLng;
-
-import java.util.List;
-
-/**
- * A GeoJsonLineString geometry contains a number of {@link com.google.android.gms.maps.model.LatLng}s.
- */
-public class GeoJsonLineString implements GeoJsonGeometry {
-
- private final static String GEOMETRY_TYPE = "LineString";
-
- private final List mCoordinates;
-
- /**
- * Creates a new GeoJsonLineString object
- *
- * @param coordinates list of coordinates of GeoJsonLineString to store
- */
- public GeoJsonLineString(List coordinates) {
- if (coordinates == null) {
- throw new IllegalArgumentException("Coordinates cannot be null");
- }
- mCoordinates = coordinates;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getType() {
- return GEOMETRY_TYPE;
- }
-
- /**
- * Gets the coordinates of the GeoJsonLineString
- *
- * @return list of coordinates of the GeoJsonLineString
- */
- public List getCoordinates() {
- return mCoordinates;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(GEOMETRY_TYPE).append("{");
- sb.append("\n coordinates=").append(mCoordinates);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonLineStringStyle.java b/library/src/com/google/maps/android/geojson/GeoJsonLineStringStyle.java
deleted file mode 100644
index c2ceb992b..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonLineStringStyle.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.model.PolylineOptions;
-
-import java.util.Observable;
-
-/**
- * A class that allows for GeoJsonLineString objects to be styled and for these styles to be
- * translated into a PolylineOptions object.
- */
-public class GeoJsonLineStringStyle extends Observable implements GeoJsonStyle {
-
- private final static String GEOMETRY_TYPE_REGEX
- = "LineString|MultiLineString|GeometryCollection";
-
- private final PolylineOptions mPolylineOptions;
-
- /**
- * Creates a new LineStringStyle object
- */
- public GeoJsonLineStringStyle() {
- mPolylineOptions = new PolylineOptions();
- }
-
- /**
- * Gets the type of geometries this style can be applied to
- *
- * @return type of geometries this style can be applied to
- */
- @Override
- public String getGeometryType() {
- return GEOMETRY_TYPE_REGEX;
- }
-
- /**
- * Gets the color of the GeoJsonLineString as a 32-bit ARGB color
- *
- * @return color of the GeoJsonLineString
- */
- public int getColor() {
- return mPolylineOptions.getColor();
- }
-
- /**
- * Sets the color of the GeoJsonLineString as a 32-bit ARGB color
- *
- * @param color color value of the GeoJsonLineString
- */
- public void setColor(int color) {
- mPolylineOptions.color(color);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonLineString is geodesic
- *
- * @return true if GeoJsonLineString is geodesic, false otherwise
- */
- public boolean isGeodesic() {
- return mPolylineOptions.isGeodesic();
- }
-
- /**
- * Sets whether the GeoJsonLineString is geodesic
- *
- * @param geodesic true if GeoJsonLineString is geodesic, false otherwise
- */
- public void setGeodesic(boolean geodesic) {
- mPolylineOptions.geodesic(geodesic);
- styleChanged();
- }
-
- /**
- * Gets the width of the GeoJsonLineString in screen pixels
- *
- * @return width of the GeoJsonLineString
- */
- public float getWidth() {
- return mPolylineOptions.getWidth();
- }
-
- /**
- * Sets the width of the GeoJsonLineString in screen pixels
- *
- * @param width width value of the GeoJsonLineString
- */
- public void setWidth(float width) {
- mPolylineOptions.width(width);
- styleChanged();
- }
-
- /**
- * Gets the z index of the GeoJsonLineString
- *
- * @return z index of the GeoJsonLineString
- */
- public float getZIndex() {
- return mPolylineOptions.getZIndex();
- }
-
- /**
- * Sets the z index of the GeoJsonLineString
- *
- * @param zIndex z index value of the GeoJsonLineString
- */
- public void setZIndex(float zIndex) {
- mPolylineOptions.zIndex(zIndex);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonLineString is visible
- *
- * @return true if the GeoJsonLineString visible, false if not visible
- */
- @Override
- public boolean isVisible() {
- return mPolylineOptions.isVisible();
- }
-
- /**
- * Sets whether the GeoJsonLineString is visible
- *
- * @param visible true if the GeoJsonLineString is visible, false if not visible
- */
- @Override
- public void setVisible(boolean visible) {
- mPolylineOptions.visible(visible);
- styleChanged();
- }
-
- /**
- * Notifies the observers, GeoJsonFeature objects, that the style has changed. Indicates to the
- * GeoJsonFeature that it should check whether a redraw is needed for the feature.
- */
- private void styleChanged() {
- setChanged();
- notifyObservers();
- }
-
- /**
- * Gets a new PolylineOptions object containing styles for the GeoJsonLineString
- *
- * @return new PolylineOptions object
- */
- public PolylineOptions toPolylineOptions() {
- PolylineOptions polylineOptions = new PolylineOptions();
- polylineOptions.color(mPolylineOptions.getColor());
- polylineOptions.geodesic(mPolylineOptions.isGeodesic());
- polylineOptions.visible(mPolylineOptions.isVisible());
- polylineOptions.width(mPolylineOptions.getWidth());
- polylineOptions.zIndex(mPolylineOptions.getZIndex());
- return polylineOptions;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("LineStringStyle{");
- sb.append("\n geometry type=").append(GEOMETRY_TYPE_REGEX);
- sb.append(",\n color=").append(getColor());
- sb.append(",\n geodesic=").append(isGeodesic());
- sb.append(",\n visible=").append(isVisible());
- sb.append(",\n width=").append(getWidth());
- sb.append(",\n z index=").append(getZIndex());
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonMultiLineString.java b/library/src/com/google/maps/android/geojson/GeoJsonMultiLineString.java
deleted file mode 100644
index 71d223bb2..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonMultiLineString.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.google.maps.android.geojson;
-
-import java.util.List;
-
-/**
- * A GeoJsonMultiLineString geometry contains a number of {@link GeoJsonLineString}s.
- */
-public class GeoJsonMultiLineString implements GeoJsonGeometry {
-
- private final static String GEOMETRY_TYPE = "MultiLineString";
-
- private final List mGeoJsonLineStrings;
-
- /**
- * Creates a new GeoJsonMultiLineString object
- *
- * @param geoJsonLineStrings list of GeoJsonLineStrings to store
- */
- public GeoJsonMultiLineString(List geoJsonLineStrings) {
- if (geoJsonLineStrings == null) {
- throw new IllegalArgumentException("GeoJsonLineStrings cannot be null");
- }
- mGeoJsonLineStrings = geoJsonLineStrings;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getType() {
- return GEOMETRY_TYPE;
- }
-
- /**
- * Gets a list of GeoJsonLineStrings
- *
- * @return list of GeoJsonLineStrings
- */
- public List getLineStrings() {
- return mGeoJsonLineStrings;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(GEOMETRY_TYPE).append("{");
- sb.append("\n LineStrings=").append(mGeoJsonLineStrings);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonMultiPoint.java b/library/src/com/google/maps/android/geojson/GeoJsonMultiPoint.java
deleted file mode 100644
index cb3f2cf27..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonMultiPoint.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.google.maps.android.geojson;
-
-import java.util.List;
-
-/**
- * A GeoJsonMultiPoint geometry contains a number of {@link GeoJsonPoint}s.
- */
-public class GeoJsonMultiPoint implements GeoJsonGeometry {
-
- private final static String GEOMETRY_TYPE = "MultiPoint";
-
- private final List mGeoJsonPoints;
-
- /**
- * Creates a GeoJsonMultiPoint object
- *
- * @param geoJsonPoints list of GeoJsonPoints to store
- */
- public GeoJsonMultiPoint(List geoJsonPoints) {
- if (geoJsonPoints == null) {
- throw new IllegalArgumentException("GeoJsonPoints cannot be null");
- }
- mGeoJsonPoints = geoJsonPoints;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getType() {
- return GEOMETRY_TYPE;
- }
-
- /**
- * Gets a list of GeoJsonPoints
- *
- * @return list of GeoJsonPoints
- */
- public List getPoints() {
- return mGeoJsonPoints;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(GEOMETRY_TYPE).append("{");
- sb.append("\n points=").append(mGeoJsonPoints);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonMultiPolygon.java b/library/src/com/google/maps/android/geojson/GeoJsonMultiPolygon.java
deleted file mode 100644
index 6d57f5656..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonMultiPolygon.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.google.maps.android.geojson;
-
-import java.util.List;
-
-/**
- * A GeoJsonMultiPolygon geometry contains a number of {@link GeoJsonPolygon}s.
- */
-public class GeoJsonMultiPolygon implements GeoJsonGeometry {
-
- private final static String GEOMETRY_TYPE = "MultiPolygon";
-
- private final List mGeoJsonPolygons;
-
- /**
- * Creates a new GeoJsonMultiPolygon
- *
- * @param geoJsonPolygons list of GeoJsonPolygons to store
- */
- public GeoJsonMultiPolygon(List geoJsonPolygons) {
- if (geoJsonPolygons == null) {
- throw new IllegalArgumentException("GeoJsonPolygons cannot be null");
- }
- mGeoJsonPolygons = geoJsonPolygons;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getType() {
- return GEOMETRY_TYPE;
- }
-
- /**
- * Gets a list of GeoJsonPolygons
- *
- * @return list of GeoJsonPolygons
- */
- public List getPolygons() {
- return mGeoJsonPolygons;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(GEOMETRY_TYPE).append("{");
- sb.append("\n Polygons=").append(mGeoJsonPolygons);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonParser.java b/library/src/com/google/maps/android/geojson/GeoJsonParser.java
deleted file mode 100644
index bb9e3143d..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonParser.java
+++ /dev/null
@@ -1,478 +0,0 @@
-package com.google.maps.android.geojson;
-
-
-import com.google.android.gms.maps.model.LatLng;
-import com.google.android.gms.maps.model.LatLngBounds;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import android.util.Log;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-/**
- * Parses a JSONObject and places data into their appropriate GeoJsonFeature objects. Returns an
- * array of
- * GeoJsonFeature objects parsed from the GeoJSON file.
- */
-/* package */ class GeoJsonParser {
-
- private static final String LOG_TAG = "GeoJsonParser";
-
- // Feature object type
- private static final String FEATURE = "Feature";
-
- // Feature object geometry member
- private static final String FEATURE_GEOMETRY = "geometry";
-
- // Feature object id member
- private static final String FEATURE_ID = "id";
-
- // FeatureCollection type
- private static final String FEATURE_COLLECTION = "FeatureCollection";
-
- // FeatureCollection features array member
- private static final String FEATURE_COLLECTION_ARRAY = "features";
-
- // Geometry coordinates member
- private static final String GEOMETRY_COORDINATES_ARRAY = "coordinates";
-
- // GeometryCollection type
- private static final String GEOMETRY_COLLECTION = "GeometryCollection";
-
- // GeometryCollection geometries array member
- private static final String GEOMETRY_COLLECTION_ARRAY = "geometries";
-
- // Coordinates for bbox
- private static final String BOUNDING_BOX = "bbox";
-
- private static final String PROPERTIES = "properties";
-
- private static final String POINT = "Point";
-
- private static final String MULTIPOINT = "MultiPoint";
-
- private static final String LINESTRING = "LineString";
-
- private static final String MULTILINESTRING = "MultiLineString";
-
- private static final String POLYGON = "Polygon";
-
- private static final String MULTIPOLYGON = "MultiPolygon";
-
- private final JSONObject mGeoJsonFile;
-
- private final ArrayList mGeoJsonFeatures;
-
- private LatLngBounds mBoundingBox;
-
-
- /**
- * Creates a new GeoJsonParser
- *
- * @param geoJsonFile GeoJSON file to parse
- */
- /* package */ GeoJsonParser(JSONObject geoJsonFile) {
- mGeoJsonFile = geoJsonFile;
- mGeoJsonFeatures = new ArrayList();
- mBoundingBox = null;
- parseGeoJson();
- }
-
- private static boolean isGeometry(String type) {
- return type.matches(POINT + "|" + MULTIPOINT + "|" + LINESTRING + "|" + MULTILINESTRING +
- "|" + POLYGON + "|" + MULTIPOLYGON + "|" + GEOMETRY_COLLECTION);
- }
-
- /**
- * Parses a single GeoJSON feature which contains a geometry and properties member both of
- * which can be null. Also parses the bounding box and id members of the feature if they exist.
- *
- * @param geoJsonFeature feature to parse
- * @return GeoJsonFeature object
- */
- private static GeoJsonFeature parseFeature(JSONObject geoJsonFeature) {
- String id = null;
- LatLngBounds boundingBox = null;
- GeoJsonGeometry geometry = null;
- HashMap properties = new HashMap();
-
- try {
- if (geoJsonFeature.has(FEATURE_ID)) {
- id = geoJsonFeature.getString(FEATURE_ID);
- }
- if (geoJsonFeature.has(BOUNDING_BOX)) {
- boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX));
- }
- if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) {
- geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY));
- }
- if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) {
- properties = parseProperties(geoJsonFeature.getJSONObject("properties"));
- }
- } catch (JSONException e) {
- Log.w(LOG_TAG, "Feature could not be successfully parsed " + geoJsonFeature.toString());
- return null;
- }
- return new GeoJsonFeature(geometry, id, properties, boundingBox);
- }
-
- /**
- * Parses a bounding box given as a JSONArray of 4 elements in the order of lowest values for
- * all axes followed by highest values. Axes order of a bounding box follows the axes order of
- * geometries.
- *
- * @param coordinates array of 4 coordinates
- * @return LatLngBounds containing the coordinates of the bounding box
- * @throws JSONException if the bounding box could not be parsed
- */
- private static LatLngBounds parseBoundingBox(JSONArray coordinates) throws JSONException {
- // Lowest values for all axes
- LatLng southWestCorner = new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
- // Highest value for all axes
- LatLng northEastCorner = new LatLng(coordinates.getDouble(3), coordinates.getDouble(2));
- return new LatLngBounds(southWestCorner, northEastCorner);
- }
-
- /**
- * Parses a single GeoJSON geometry object containing a coordinates array or a geometries array
- * if it has type GeometryCollection
- *
- * @param geoJsonGeometry geometry object to parse
- * @return GeoJsonGeometry object
- */
- private static GeoJsonGeometry parseGeometry(JSONObject geoJsonGeometry) {
- try {
-
- String geometryType = geoJsonGeometry.getString("type");
-
- JSONArray geometryArray;
- if (geometryType.equals(GEOMETRY_COLLECTION)) {
- // GeometryCollection
- geometryArray = geoJsonGeometry.getJSONArray(GEOMETRY_COLLECTION_ARRAY);
- } else if (isGeometry(geometryType)) {
- geometryArray = geoJsonGeometry.getJSONArray(GEOMETRY_COORDINATES_ARRAY);
- } else {
- // No geometries or coordinates array
- return null;
- }
- return createGeometry(geometryType, geometryArray);
- } catch (JSONException e) {
- return null;
- }
- }
-
- /**
- * Converts a GeoJsonGeometry object into a GeoJsonFeature object. A geometry object has no ID,
- * properties or bounding box so it is set to null.
- *
- * @param geoJsonGeometry Geometry object to convert into a Feature object
- * @return new Feature object
- */
- private static GeoJsonFeature parseGeometryToFeature(JSONObject geoJsonGeometry) {
- GeoJsonGeometry geometry = parseGeometry(geoJsonGeometry);
- if (geometry != null) {
- return new GeoJsonFeature(geometry, null, new HashMap(), null);
- }
- Log.w(LOG_TAG, "Geometry could not be parsed");
- return null;
-
- }
-
- /**
- * Parses the properties of a GeoJSON feature into a hashmap
- *
- * @param properties GeoJSON properties member
- * @return hashmap containing property values
- * @throws JSONException if the properties could not be parsed
- */
- private static HashMap parseProperties(JSONObject properties)
- throws JSONException {
- HashMap propertiesMap = new HashMap();
- Iterator propertyKeys = properties.keys();
- while (propertyKeys.hasNext()) {
- String key = (String) propertyKeys.next();
- propertiesMap.put(key, properties.getString(key));
- }
- return propertiesMap;
- }
-
- /**
- * Creates a GeoJsonGeometry object from the given type of geometry and its coordinates or
- * geometries array
- *
- * @param geometryType type of geometry
- * @param geometryArray coordinates or geometries of the geometry
- * @return GeoJsonGeometry object
- * @throws JSONException if the coordinates or geometries could be parsed
- */
- private static GeoJsonGeometry createGeometry(String geometryType, JSONArray geometryArray)
- throws JSONException {
- if (geometryType.equals(POINT)) {
- return createPoint(geometryArray);
- } else if (geometryType.equals(MULTIPOINT)) {
- return createMultiPoint(geometryArray);
- } else if (geometryType.equals(LINESTRING)) {
- return createLineString(geometryArray);
- } else if (geometryType.equals(MULTILINESTRING)) {
- return createMultiLineString(geometryArray);
- } else if (geometryType.equals(POLYGON)) {
- return createPolygon(geometryArray);
- } else if (geometryType.equals(MULTIPOLYGON)) {
- return createMultiPolygon(geometryArray);
- } else if (geometryType.equals(GEOMETRY_COLLECTION)) {
- return createGeometryCollection(geometryArray);
- }
- return null;
- }
-
- /**
- * Creates a new GeoJsonPoint object
- *
- * @param coordinates array containing the coordinates for the GeoJsonPoint
- * @return GeoJsonPoint object
- * @throws JSONException if coordinates cannot be parsed
- */
- private static GeoJsonPoint createPoint(JSONArray coordinates) throws JSONException {
- return new GeoJsonPoint(parseCoordinate(coordinates));
- }
-
- /**
- * Creates a new GeoJsonMultiPoint object containing an array of GeoJsonPoint objects
- *
- * @param coordinates array containing the coordinates for the GeoJsonMultiPoint
- * @return GeoJsonMultiPoint object
- * @throws JSONException if coordinates cannot be parsed
- */
- private static GeoJsonMultiPoint createMultiPoint(JSONArray coordinates) throws JSONException {
- ArrayList geoJsonPoints = new ArrayList();
- for (int i = 0; i < coordinates.length(); i++) {
- geoJsonPoints.add(createPoint(coordinates.getJSONArray(i)));
- }
- return new GeoJsonMultiPoint(geoJsonPoints);
- }
-
- /**
- * Creates a new GeoJsonLineString object
- *
- * @param coordinates array containing the coordinates for the GeoJsonLineString
- * @return GeoJsonLineString object
- * @throws JSONException if coordinates cannot be parsed
- */
- private static GeoJsonLineString createLineString(JSONArray coordinates) throws JSONException {
- return new GeoJsonLineString(parseCoordinatesArray(coordinates));
- }
-
- /**
- * Creates a new GeoJsonMultiLineString object containing an array of GeoJsonLineString objects
- *
- * @param coordinates array containing the coordinates for the GeoJsonMultiLineString
- * @return GeoJsonMultiLineString object
- * @throws JSONException if coordinates cannot be parsed
- */
- private static GeoJsonMultiLineString createMultiLineString(JSONArray coordinates)
- throws JSONException {
- ArrayList geoJsonLineStrings = new ArrayList();
- for (int i = 0; i < coordinates.length(); i++) {
- geoJsonLineStrings.add(createLineString(coordinates.getJSONArray(i)));
- }
- return new GeoJsonMultiLineString(geoJsonLineStrings);
- }
-
- /**
- * Creates a new GeoJsonPolygon object
- *
- * @param coordinates array containing the coordinates for the GeoJsonPolygon
- * @return GeoJsonPolygon object
- * @throws JSONException if coordinates cannot be parsed
- */
- private static GeoJsonPolygon createPolygon(JSONArray coordinates) throws JSONException {
- return new GeoJsonPolygon(parseCoordinatesArrays(coordinates));
- }
-
- /**
- * Creates a new GeoJsonMultiPolygon object containing an array of GeoJsonPolygon objects
- *
- * @param coordinates array containing the coordinates for the GeoJsonMultiPolygon
- * @return GeoJsonPolygon object
- * @throws JSONException if coordinates cannot be parsed
- */
- private static GeoJsonMultiPolygon createMultiPolygon(JSONArray coordinates)
- throws JSONException {
- ArrayList geoJsonPolygons = new ArrayList();
- for (int i = 0; i < coordinates.length(); i++) {
- geoJsonPolygons.add(createPolygon(coordinates.getJSONArray(i)));
- }
- return new GeoJsonMultiPolygon(geoJsonPolygons);
- }
-
- /**
- * Creates a new GeoJsonGeometryCollection object containing an array of GeoJsonGeometry
- * objects
- *
- * @param geometries array containing the geometries for the GeoJsonGeometryCollection
- * @return GeoJsonGeometryCollection object
- * @throws JSONException if geometries cannot be parsed
- */
- private static GeoJsonGeometryCollection createGeometryCollection(JSONArray geometries)
- throws JSONException {
- ArrayList geometryCollectionElements
- = new ArrayList();
-
- for (int i = 0; i < geometries.length(); i++) {
- JSONObject geometryElement = geometries.getJSONObject(i);
- GeoJsonGeometry geometry = parseGeometry(geometryElement);
- if (geometry != null) {
- // Do not add geometries that could not be parsed
- geometryCollectionElements.add(geometry);
- }
- }
- return new GeoJsonGeometryCollection(geometryCollectionElements);
- }
-
- /**
- * Parses an array containing a coordinate into a LatLng object
- *
- * @param coordinates array containing the GeoJSON coordinate
- * @return LatLng object
- * @throws JSONException if coordinate cannot be parsed
- */
- private static LatLng parseCoordinate(JSONArray coordinates) throws JSONException {
- // GeoJSON stores coordinates as Lng, Lat so we need to reverse
- return new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
- }
-
- /**
- * Parses an array containing coordinates into an ArrayList of LatLng objects
- *
- * @param coordinates array containing the GeoJSON coordinates
- * @return ArrayList of LatLng objects
- * @throws JSONException if coordinates cannot be parsed
- */
- private static ArrayList parseCoordinatesArray(JSONArray coordinates)
- throws JSONException {
- ArrayList coordinatesArray = new ArrayList();
-
- for (int i = 0; i < coordinates.length(); i++) {
- coordinatesArray.add(parseCoordinate(coordinates.getJSONArray(i)));
- }
- return coordinatesArray;
- }
-
- /**
- * Parses an array of arrays containing coordinates into an ArrayList of an ArrayList of LatLng
- * objects
- *
- * @param coordinates array of an array containing the GeoJSON coordinates
- * @return ArrayList of an ArrayList of LatLng objects
- * @throws JSONException if coordinates cannot be parsed
- */
- private static ArrayList> parseCoordinatesArrays(JSONArray coordinates)
- throws JSONException {
- ArrayList> coordinatesArray = new ArrayList>();
-
- for (int i = 0; i < coordinates.length(); i++) {
- coordinatesArray.add(parseCoordinatesArray(coordinates.getJSONArray(i)));
- }
- return coordinatesArray;
- }
-
- /**
- * Parses the GeoJSON file by type and adds the generated GeoJsonFeature objects to the
- * mFeatures array. Supported GeoJSON types include feature, feature collection and geometry.
- */
- private void parseGeoJson() {
- try {
- GeoJsonFeature feature;
- String type = mGeoJsonFile.getString("type");
-
- if (type.equals(FEATURE)) {
- feature = parseFeature(mGeoJsonFile);
- if (feature != null) {
- mGeoJsonFeatures.add(feature);
- }
- } else if (type.equals(FEATURE_COLLECTION)) {
- mGeoJsonFeatures.addAll(parseFeatureCollection(mGeoJsonFile));
- } else if (isGeometry(type)) {
- feature = parseGeometryToFeature(mGeoJsonFile);
- if (feature != null) {
- // Don't add null features
- mGeoJsonFeatures.add(feature);
- }
- } else {
- Log.w(LOG_TAG, "GeoJSON file could not be parsed.");
- }
- } catch (JSONException e) {
- Log.w(LOG_TAG, "GeoJSON file could not be parsed.");
- }
- }
-
- /**
- * Parses the array of GeoJSON features in a given GeoJSON feature collection. Also parses the
- * bounding box member of the feature collection if it exists.
- *
- * @param geoJsonFeatureCollection feature collection to parse
- * @return array of GeoJsonFeature objects
- */
- private ArrayList parseFeatureCollection(JSONObject geoJsonFeatureCollection) {
- JSONArray geoJsonFeatures;
- ArrayList features = new ArrayList();
- try {
- geoJsonFeatures = geoJsonFeatureCollection.getJSONArray(FEATURE_COLLECTION_ARRAY);
- if (geoJsonFeatureCollection.has(BOUNDING_BOX)) {
- mBoundingBox = parseBoundingBox(
- geoJsonFeatureCollection.getJSONArray(BOUNDING_BOX));
- }
- } catch (JSONException e) {
- Log.w(LOG_TAG, "Feature Collection could not be created.");
- return features;
- }
-
- for (int i = 0; i < geoJsonFeatures.length(); i++) {
- try {
- JSONObject feature = geoJsonFeatures.getJSONObject(i);
- if (feature.getString("type").equals(FEATURE)) {
- GeoJsonFeature parsedFeature = parseFeature(feature);
- if (parsedFeature != null) {
- // Don't add null features
- features.add(parsedFeature);
- } else {
- Log.w(LOG_TAG,
- "Index of Feature in Feature Collection that could not be created: "
- + i);
- }
- }
- } catch (JSONException e) {
- Log.w(LOG_TAG,
- "Index of Feature in Feature Collection that could not be created: " + i);
- }
- }
- return features;
- }
-
- /**
- * Gets the array of GeoJsonFeature objects
- *
- * @return array of GeoJsonFeatures
- */
- /* package */ ArrayList getFeatures() {
- return mGeoJsonFeatures;
- }
-
- /**
- * Gets the array containing the coordinates of the bounding box for the FeatureCollection. If
- * the FeatureCollection did not have a bounding box or if the GeoJSON file did not contain a
- * FeatureCollection then null will be returned.
- *
- * @return LatLngBounds object containing bounding box of FeatureCollection, null if no bounding
- * box
- */
- /* package */ LatLngBounds getBoundingBox() {
- return mBoundingBox;
- }
-
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonPoint.java b/library/src/com/google/maps/android/geojson/GeoJsonPoint.java
deleted file mode 100644
index 4050cc2df..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonPoint.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.model.LatLng;
-
-/**
- * A GeoJsonPoint geometry contains a single {@link com.google.android.gms.maps.model.LatLng}.
- */
-public class GeoJsonPoint implements GeoJsonGeometry {
-
- private final static String GEOMETRY_TYPE = "Point";
-
- private final LatLng mCoordinates;
-
- /**
- * Creates a new GeoJsonPoint
- *
- * @param coordinate coordinate of GeoJsonPoint to store
- */
- public GeoJsonPoint(LatLng coordinate) {
- if (coordinate == null) {
- throw new IllegalArgumentException("Coordinate cannot be null");
- }
- mCoordinates = coordinate;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getType() {
- return GEOMETRY_TYPE;
- }
-
- /**
- * Gets the coordinates of the GeoJsonPoint
- *
- * @return coordinates of the GeoJsonPoint
- */
- public LatLng getCoordinates() {
- return mCoordinates;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(GEOMETRY_TYPE).append("{");
- sb.append("\n coordinates=").append(mCoordinates);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonPointStyle.java b/library/src/com/google/maps/android/geojson/GeoJsonPointStyle.java
deleted file mode 100644
index 70ecf0d08..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonPointStyle.java
+++ /dev/null
@@ -1,314 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.model.BitmapDescriptor;
-import com.google.android.gms.maps.model.MarkerOptions;
-
-import java.util.Observable;
-
-/**
- * A class that allows for GeoJsonPoint objects to be styled and for these styles to be translated
- * into a MarkerOptions object.
- */
-public class GeoJsonPointStyle extends Observable implements GeoJsonStyle {
-
- private final static String GEOMETRY_TYPE_REGEX = "Point|MultiPoint|GeometryCollection";
-
- private final MarkerOptions mMarkerOptions;
-
-
- /**
- * Creates a new PointStyle object
- */
- public GeoJsonPointStyle() {
- mMarkerOptions = new MarkerOptions();
- }
-
- /**
- * Gets the type of geometries this style can be applied to
- *
- * @return type of geometries this style can be applied to
- */
- @Override
- public String getGeometryType() {
- return GEOMETRY_TYPE_REGEX;
- }
-
- /**
- * Gets the alpha of the GeoJsonPoint. This is a value from 0 to 1, where 0 means the marker is
- * completely transparent and 1 means the marker is completely opaque.
- *
- * @return alpha of the GeoJsonPoint
- */
- public float getAlpha() {
- return mMarkerOptions.getAlpha();
- }
-
- /**
- * Sets the alpha of the GeoJsonPoint. This is a value from 0 to 1, where 0 means the marker is
- * completely transparent and 1 means the marker is completely opaque.
- *
- * @param alpha alpha value of the GeoJsonPoint
- */
- public void setAlpha(float alpha) {
- mMarkerOptions.alpha(alpha);
- styleChanged();
- }
-
- /**
- * Gets the Anchor U coordinate of the GeoJsonPoint. Normalized to [0, 1], of the anchor from
- * the left edge. This is equivalent to the same U value used in {@link
- * com.google.android.gms.maps.model.MarkerOptions#getAnchorU()}.
- *
- * @return Anchor U coordinate of the GeoJsonPoint
- */
- public float getAnchorU() {
- return mMarkerOptions.getAnchorU();
- }
-
- /**
- * Gets the Anchor V coordinate of the GeoJsonPoint. Normalized to [0, 1], of the anchor from
- * the top edge. This is equivalent to the same V value used in {@link
- * com.google.android.gms.maps.model.MarkerOptions#getAnchorV()}.
- *
- * @return Anchor V coordinate of the GeoJsonPoint
- */
- public float getAnchorV() {
- return mMarkerOptions.getAnchorV();
- }
-
- /**
- * Sets the Anchor U and V coordinates of the GeoJsonPoint. The anchor point is specified in
- * the
- * continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image,
- * and (1, 1) is the bottom-right corner. The U & V values are the same U & V values used in
- * {@link com.google.android.gms.maps.model.MarkerOptions#anchor(float, float)} ()}.
- *
- * @param anchorU Anchor U coordinate of the GeoJsonPoint
- * @param anchorV Anchor V coordinate of the GeoJsonPoint
- */
- public void setAnchor(float anchorU, float anchorV) {
- mMarkerOptions.anchor(anchorU, anchorV);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonPoint is draggable
- *
- * @return true if GeoJsonPoint is draggable, false if not draggable
- */
- public boolean isDraggable() {
- return mMarkerOptions.isDraggable();
- }
-
- /**
- * Sets the GeoJsonPoint to be draggable
- *
- * @param draggable true if GeoJsonPoint is draggable, false if not draggable
- */
- public void setDraggable(boolean draggable) {
- mMarkerOptions.draggable(draggable);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonPoint is flat
- *
- * @return true if GeoJsonPoint is flat, false if not flat
- */
- public boolean isFlat() {
- return mMarkerOptions.isFlat();
- }
-
- /**
- * Sets the GeoJsonPoint to be flat
- *
- * @param flat true if GeoJsonPoint is flat, false if not flat
- */
- public void setFlat(boolean flat) {
- mMarkerOptions.flat(flat);
- styleChanged();
- }
-
- /**
- * Gets a bitmap image for the GeoJsonPoint
- *
- * @return bitmap descriptor for the GeoJsonPoint
- */
- public BitmapDescriptor getIcon() {
- return mMarkerOptions.getIcon();
- }
-
- /**
- * Sets a bitmap image for the GeoJsonPoint
- *
- * @param bitmap bitmap descriptor for the GeoJsonPoint
- */
- public void setIcon(BitmapDescriptor bitmap) {
- mMarkerOptions.icon(bitmap);
- styleChanged();
- }
-
- /**
- * Gets the info window anchor U coordinate of the GeoJsonPoint. Normalized to [0, 1], of the
- * info window anchor from the left edge. This is equivalent to the same U value used in {@link
- * com.google.android.gms.maps.model.MarkerOptions#getInfoWindowAnchorU()}.
- *
- * @return info window anchor U coordinate of the GeoJsonPoint
- */
- public float getInfoWindowAnchorU() {
- return mMarkerOptions.getInfoWindowAnchorU();
- }
-
- /**
- * Gets the info window anchor V coordinate of the GeoJsonPoint. Normalized to [0, 1], of the
- * info window anchor from the top edge. This is equivalent to the same V value used in {@link
- * com.google.android.gms.maps.model.MarkerOptions#getInfoWindowAnchorV()}.
- *
- * @return info window anchor V coordinate of the GeoJsonPoint
- */
- public float getInfoWindowAnchorV() {
- return mMarkerOptions.getInfoWindowAnchorV();
- }
-
- /**
- * Sets the info window anchor U and V coordinates of the GeoJsonPoint. This is specified in
- * the
- * same coordinate system as the anchor. The U & V values are the same U & V values used in
- * {@link com.google.android.gms.maps.model.MarkerOptions#infoWindowAnchor(float, float)}.
- *
- * @param infoWindowAnchorU info window anchor U coordinate of the GeoJsonPoint
- * @param infoWindowAnchorV info window anchor V coordinate of the GeoJsonPoint
- */
- public void setInfoWindowAnchor(float infoWindowAnchorU, float infoWindowAnchorV) {
- mMarkerOptions.infoWindowAnchor(infoWindowAnchorU, infoWindowAnchorV);
- styleChanged();
- }
-
- /**
- * Gets the rotation of the GeoJsonPoint in degrees clockwise about the marker's anchor point
- *
- * @return rotation of the GeoJsonPoint
- */
- public float getRotation() {
- return mMarkerOptions.getRotation();
- }
-
-
- /**
- * Sets the rotation of the GeoJsonPoint in degrees clockwise about the marker's anchor point
- *
- * @param rotation rotation value of the GeoJsonPoint
- */
- public void setRotation(float rotation) {
- mMarkerOptions.rotation(rotation);
- styleChanged();
- }
-
- /**
- * Gets the snippet of the GeoJsonPoint
- *
- * @return snippet of the GeoJsonPoint
- */
- public String getSnippet() {
- return mMarkerOptions.getSnippet();
- }
-
- /**
- * Sets the snippet of the GeoJsonPoint
- *
- * @param snippet sets the snippet value of the GeoJsonPoint
- */
- public void setSnippet(String snippet) {
- mMarkerOptions.snippet(snippet);
- styleChanged();
- }
-
- /**
- * Gets the title of the GeoJsonPoint
- *
- * @return title of the GeoJsonPoint
- */
- public String getTitle() {
- return mMarkerOptions.getTitle();
- }
-
- /**
- * Sets the title of the GeoJsonPoint
- *
- * @param title title value of the GeoJsonPoint
- */
- public void setTitle(String title) {
- mMarkerOptions.title(title);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonPoint is visible
- *
- * @return true if GeoJsonPoint is visible, false if not visible
- */
- @Override
- public boolean isVisible() {
- return mMarkerOptions.isVisible();
- }
-
- /**
- * Sets whether the GeoJsonPoint is visible
- *
- * @param visible true if GeoJsonPoint is visible, false if not visible
- */
- @Override
- public void setVisible(boolean visible) {
- mMarkerOptions.visible(visible);
- styleChanged();
- }
-
- /**
- * Notifies the observers, GeoJsonFeature objects, that the style has changed. Indicates to the
- * GeoJsonFeature that it should check whether a redraw is needed for the feature.
- */
- private void styleChanged() {
- setChanged();
- notifyObservers();
- }
-
- /**
- * Gets a new MarkerOptions object containing styles for the GeoJsonPoint
- *
- * @return new MarkerOptions object
- */
- public MarkerOptions toMarkerOptions() {
- MarkerOptions markerOptions = new MarkerOptions();
- markerOptions.alpha(mMarkerOptions.getAlpha());
- markerOptions.anchor(mMarkerOptions.getAnchorU(), mMarkerOptions.getAnchorV());
- markerOptions.draggable(mMarkerOptions.isDraggable());
- markerOptions.flat(mMarkerOptions.isFlat());
- markerOptions.icon(mMarkerOptions.getIcon());
- markerOptions.infoWindowAnchor(mMarkerOptions.getInfoWindowAnchorU(),
- mMarkerOptions.getInfoWindowAnchorV());
- markerOptions.rotation(mMarkerOptions.getRotation());
- markerOptions.snippet(mMarkerOptions.getSnippet());
- markerOptions.title(mMarkerOptions.getTitle());
- markerOptions.visible(mMarkerOptions.isVisible());
- return markerOptions;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("PointStyle{");
- sb.append("\n geometry type=").append(GEOMETRY_TYPE_REGEX);
- sb.append(",\n alpha=").append(getAlpha());
- sb.append(",\n anchor U=").append(getAnchorU());
- sb.append(",\n anchor V=").append(getAnchorV());
- sb.append(",\n draggable=").append(isDraggable());
- sb.append(",\n flat=").append(isFlat());
- sb.append(",\n info window anchor U=").append(getInfoWindowAnchorU());
- sb.append(",\n info window anchor V=").append(getInfoWindowAnchorV());
- sb.append(",\n rotation=").append(getRotation());
- sb.append(",\n snippet=").append(getSnippet());
- sb.append(",\n title=").append(getTitle());
- sb.append(",\n visible=").append(isVisible());
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonPolygon.java b/library/src/com/google/maps/android/geojson/GeoJsonPolygon.java
deleted file mode 100644
index 81c9e7bff..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonPolygon.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.model.LatLng;
-
-import java.util.List;
-
-/**
- * A GeoJsonPolygon geometry contains an array of arrays of {@link com.google.android.gms.maps.model.LatLng}s.
- * The first array is the polygon exterior boundary. Subsequent arrays are holes.
- */
-
-public class GeoJsonPolygon implements GeoJsonGeometry {
-
- private final static String GEOMETRY_TYPE = "Polygon";
-
- private final List extends List> mCoordinates;
-
- /**
- * Creates a new GeoJsonPolygon object
- *
- * @param coordinates list of list of coordinates of GeoJsonPolygon to store
- */
- public GeoJsonPolygon(
- List extends List> coordinates) {
- if (coordinates == null) {
- throw new IllegalArgumentException("Coordinates cannot be null");
- }
- mCoordinates = coordinates;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getType() {
- return GEOMETRY_TYPE;
- }
-
- /**
- * Gets a list of a list of coordinates of the GeoJsonPolygons
- *
- * @return list of a list of coordinates of the GeoJsonPolygon
- */
- public List extends List> getCoordinates() {
- return mCoordinates;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder(GEOMETRY_TYPE).append("{");
- sb.append("\n coordinates=").append(mCoordinates);
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonPolygonStyle.java b/library/src/com/google/maps/android/geojson/GeoJsonPolygonStyle.java
deleted file mode 100644
index 8a4b0f262..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonPolygonStyle.java
+++ /dev/null
@@ -1,188 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.model.PolygonOptions;
-
-import java.util.Observable;
-
-/**
- * A class that allows for GeoJsonPolygon objects to be styled and for these styles to be
- * translated into a PolygonOptions object
- */
-public class GeoJsonPolygonStyle extends Observable implements GeoJsonStyle {
-
- private final static String GEOMETRY_TYPE_REGEX = "Polygon|MultiPolygon|GeometryCollection";
-
- private final PolygonOptions mPolygonOptions;
-
- /**
- * Creates a new PolygonStyle object
- */
- public GeoJsonPolygonStyle() {
- mPolygonOptions = new PolygonOptions();
- }
-
- /**
- * Gets the type of geometries this style can be applied to
- *
- * @return type of geometries this style can be applied to
- */
- @Override
- public String getGeometryType() {
- return GEOMETRY_TYPE_REGEX;
- }
-
- /**
- * Gets the fill color of the GeoJsonPolygon as a 32-bit ARGB color
- *
- * @return fill color of the GeoJsonPolygon
- */
- public int getFillColor() {
- return mPolygonOptions.getFillColor();
- }
-
- /**
- * Sets the fill color of the GeoJsonPolygon as a 32-bit ARGB color
- *
- * @param fillColor fill color value of the GeoJsonPolygon
- */
- public void setFillColor(int fillColor) {
- mPolygonOptions.fillColor(fillColor);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonPolygon is geodesic
- *
- * @return true if GeoJsonPolygon is geodesic, false if not geodesic
- */
- public boolean isGeodesic() {
- return mPolygonOptions.isGeodesic();
- }
-
- /**
- * Sets whether the GeoJsonPolygon is geodesic
- *
- * @param geodesic true if GeoJsonPolygon is geodesic, false if not geodesic
- */
- public void setGeodesic(boolean geodesic) {
- mPolygonOptions.geodesic(geodesic);
- styleChanged();
- }
-
- /**
- * Gets the stroke color of the GeoJsonPolygon as a 32-bit ARGB color
- *
- * @return stroke color of the GeoJsonPolygon
- */
- public int getStrokeColor() {
- return mPolygonOptions.getStrokeColor();
- }
-
- /**
- * Sets the stroke color of the GeoJsonPolygon as a 32-bit ARGB color
- *
- * @param strokeColor stroke color value of the GeoJsonPolygon
- */
- public void setStrokeColor(int strokeColor) {
- mPolygonOptions.strokeColor(strokeColor);
- styleChanged();
- }
-
- /**
- * Gets the stroke width of the GeoJsonPolygon in screen pixels
- *
- * @return stroke width of the GeoJsonPolygon
- */
- public float getStrokeWidth() {
- return mPolygonOptions.getStrokeWidth();
- }
-
- /**
- * Sets the stroke width of the GeoJsonPolygon in screen pixels
- *
- * @param strokeWidth stroke width value of the GeoJsonPolygon
- */
- public void setStrokeWidth(float strokeWidth) {
- mPolygonOptions.strokeWidth(strokeWidth);
- styleChanged();
- }
-
- /**
- * Gets the z index of the GeoJsonPolygon
- *
- * @return z index of the GeoJsonPolygon
- */
- public float getZIndex() {
- return mPolygonOptions.getZIndex();
- }
-
- /**
- * Sets the z index of the GeoJsonPolygon
- *
- * @param zIndex z index value of the GeoJsonPolygon
- */
- public void setZIndex(float zIndex) {
- mPolygonOptions.zIndex(zIndex);
- styleChanged();
- }
-
- /**
- * Gets whether the GeoJsonPolygon is visible
- *
- * @return true if GeoJsonPolygon is visible, false if not visible
- */
- @Override
- public boolean isVisible() {
- return mPolygonOptions.isVisible();
- }
-
- /**
- * Sets whether the GeoJsonPolygon is visible
- *
- * @param visible true if GeoJsonPolygon is visible, false if not visible
- */
- @Override
- public void setVisible(boolean visible) {
- mPolygonOptions.visible(visible);
- styleChanged();
- }
-
- /**
- * Notifies the observers, GeoJsonFeature objects, that the style has changed. Indicates to the
- * GeoJsonFeature that it should check whether a redraw is needed for the feature.
- */
- private void styleChanged() {
- setChanged();
- notifyObservers();
- }
-
- /**
- * Gets a new PolygonOptions object containing styles for the GeoJsonPolygon
- *
- * @return new PolygonOptions object
- */
- public PolygonOptions toPolygonOptions() {
- PolygonOptions polygonOptions = new PolygonOptions();
- polygonOptions.fillColor(mPolygonOptions.getFillColor());
- polygonOptions.geodesic(mPolygonOptions.isGeodesic());
- polygonOptions.strokeColor(mPolygonOptions.getStrokeColor());
- polygonOptions.strokeWidth(mPolygonOptions.getStrokeWidth());
- polygonOptions.visible(mPolygonOptions.isVisible());
- polygonOptions.zIndex(mPolygonOptions.getZIndex());
- return polygonOptions;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("PolygonStyle{");
- sb.append("\n geometry type=").append(GEOMETRY_TYPE_REGEX);
- sb.append(",\n fill color=").append(getFillColor());
- sb.append(",\n geodesic=").append(isGeodesic());
- sb.append(",\n stroke color=").append(getStrokeColor());
- sb.append(",\n stroke width=").append(getStrokeWidth());
- sb.append(",\n visible=").append(isVisible());
- sb.append(",\n z index=").append(getZIndex());
- sb.append("\n}\n");
- return sb.toString();
- }
-}
diff --git a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java
deleted file mode 100644
index 133a97828..000000000
--- a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java
+++ /dev/null
@@ -1,336 +0,0 @@
-package com.google.maps.android.geojson;
-
-import com.google.android.gms.maps.GoogleMap;
-import com.google.android.gms.maps.model.Marker;
-import com.google.android.gms.maps.model.MarkerOptions;
-import com.google.android.gms.maps.model.Polygon;
-import com.google.android.gms.maps.model.PolygonOptions;
-import com.google.android.gms.maps.model.Polyline;
-import com.google.android.gms.maps.model.PolylineOptions;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Observable;
-import java.util.Observer;
-import java.util.Set;
-
-/**
- * Renders GeoJsonFeature objects onto the GoogleMap as Marker, Polyline and Polygon objects. Also
- * removes GeoJsonFeature objects and redraws features when updated.
- */
-/* package */ class GeoJsonRenderer implements Observer {
-
- private final static int POLYGON_OUTER_COORDINATE_INDEX = 0;
-
- private final static int POLYGON_INNER_COORDINATE_INDEX = 1;
-
- private final static Object FEATURE_NOT_ON_MAP = null;
-
- /**
- * Value is a Marker, Polyline, Polygon or an array of these that have been created from the
- * corresponding key
- */
- private final HashMap mFeatures;
-
- private GoogleMap mMap;
-
- /**
- * Creates a new GeoJsonRender object
- *
- * @param map map to place GeoJsonFeature objects on
- */
- /* package */ GeoJsonRenderer(GoogleMap map, HashMap features) {
- mMap = map;
- mFeatures = features;
- }
-
- /**
- * Given a Marker, Polyline, Polygon or an array of these and removes it from the map
- *
- * @param mapObject map object or array of map objects to remove from the map
- */
- private static void removeFromMap(Object mapObject) {
- if (mapObject instanceof Marker) {
- ((Marker) mapObject).remove();
- } else if (mapObject instanceof Polyline) {
- ((Polyline) mapObject).remove();
- } else if (mapObject instanceof Polygon) {
- ((Polygon) mapObject).remove();
- } else if (mapObject instanceof ArrayList) {
- for (Object mapObjectElement : (ArrayList) mapObject) {
- removeFromMap(mapObjectElement);
- }
- }
- }
-
- /**
- * Gets the GoogleMap that GeoJsonFeature objects are being placed on
- *
- * @return GoogleMap
- */
- /* package */ GoogleMap getMap() {
- return mMap;
- }
-
- /**
- * Changes the map that GeoJsonFeature objects are being drawn onto. Existing objects are
- * removed from the previous map and drawn onto the new map.
- *
- * @param map GoogleMap to place GeoJsonFeature objects on
- */
- /* package */ void setMap(GoogleMap map) {
- for (GeoJsonFeature feature : mFeatures.keySet()) {
- redrawFeatureToMap(feature, map);
- }
- }
-
- /**
- * Gets a set containing GeoJsonFeatures
- *
- * @return set containing GeoJsonFeatures
- */
- /* package */ Set getFeatures() {
- return mFeatures.keySet();
- }
-
- /**
- * Adds a new GeoJsonFeature to the map if its geometry property is not null.
- *
- * @param feature feature to add to the map
- */
- /* package */ void addFeature(GeoJsonFeature feature) {
- feature.addObserver(this);
- Object mapObject = null;
- if (mFeatures.containsKey(feature)) {
- // Remove current map objects before adding new ones
- removeFromMap(mFeatures.get(feature));
- }
- if (feature.hasGeometry()) {
- mapObject = addFeatureToMap(feature, feature.getGeometry());
- }
- mFeatures.put(feature, mapObject);
- }
-
- /**
- * Removes all GeoJsonFeature objects stored in the mFeatures hashmap from the map
- */
- /* package */ void removeLayerFromMap() {
- for (GeoJsonFeature feature : mFeatures.keySet()) {
- if (mFeatures.containsKey(feature)) {
- removeFromMap(mFeatures.get(feature));
- feature.deleteObserver(this);
- // Set styles to null
- feature.setPointStyle(null);
- feature.setLineStringStyle(null);
- feature.setPolygonStyle(null);
- }
- }
- }
-
- /**
- * Removes a GeoJsonFeature from the map if its geometry property is not null
- *
- * @param feature feature to remove from map
- */
- /* package */ void removeFeature(GeoJsonFeature feature) {
- // Check if given feature is stored
- if (mFeatures.containsKey(feature)) {
- removeFromMap(mFeatures.remove(feature));
- feature.deleteObserver(this);
- }
- }
-
- /**
- * Adds a new object onto the map using the GeoJsonGeometry for the coordinates and the
- * GeoJsonFeature for the styles.
- *
- * @param geoJsonFeature feature to get geometry style
- * @param geoJsonGeometry geometry to add to the map
- */
- private Object addFeatureToMap(GeoJsonFeature geoJsonFeature, GeoJsonGeometry geoJsonGeometry) {
- String geometryType = geoJsonGeometry.getType();
- if (geometryType.equals("Point")) {
- return addPointToMap(geoJsonFeature.getPointStyle(), (GeoJsonPoint) geoJsonGeometry);
- } else if (geometryType.equals("LineString")) {
- return addLineStringToMap(geoJsonFeature.getLineStringStyle(),
- (GeoJsonLineString) geoJsonGeometry);
- } else if (geometryType.equals("Polygon")) {
- return addPolygonToMap(geoJsonFeature.getPolygonStyle(),
- (GeoJsonPolygon) geoJsonGeometry);
- } else if (geometryType.equals("MultiPoint")) {
- return addMultiPointToMap(geoJsonFeature.getPointStyle(),
- (GeoJsonMultiPoint) geoJsonGeometry);
- } else if (geometryType.equals("MultiLineString")) {
- return addMultiLineStringToMap(geoJsonFeature.getLineStringStyle(),
- ((GeoJsonMultiLineString) geoJsonGeometry));
- } else if (geometryType.equals("MultiPolygon")) {
- return addMultiPolygonToMap(geoJsonFeature.getPolygonStyle(),
- ((GeoJsonMultiPolygon) geoJsonGeometry));
- } else if (geometryType.equals("GeometryCollection")) {
- return addGeometryCollectionToMap(geoJsonFeature,
- ((GeoJsonGeometryCollection) geoJsonGeometry).getGeometries());
- }
- return null;
- }
-
- /**
- * Adds a GeoJsonPoint to the map as a Marker
- *
- * @param geoJsonPointStyle contains relevant styling properties for the Marker
- * @param geoJsonPoint contains coordinates for the Marker
- * @return Marker object created from the given GeoJsonPoint
- */
- private Marker addPointToMap(GeoJsonPointStyle geoJsonPointStyle, GeoJsonPoint geoJsonPoint) {
- MarkerOptions markerOptions = geoJsonPointStyle.toMarkerOptions();
- markerOptions.position(geoJsonPoint.getCoordinates());
- return mMap.addMarker(markerOptions);
- }
-
- /**
- * Adds all GeoJsonPoint objects in GeoJsonMultiPoint to the map as multiple Markers
- *
- * @param geoJsonPointStyle contains relevant styling properties for the Markers
- * @param geoJsonMultiPoint contains an array of GeoJsonPoints
- * @return array of Markers that have been added to the map
- */
- private ArrayList addMultiPointToMap(GeoJsonPointStyle geoJsonPointStyle,
- GeoJsonMultiPoint geoJsonMultiPoint) {
- ArrayList markers = new ArrayList();
- for (GeoJsonPoint geoJsonPoint : geoJsonMultiPoint.getPoints()) {
- markers.add(addPointToMap(geoJsonPointStyle, geoJsonPoint));
- }
- return markers;
- }
-
- /**
- * Adds a GeoJsonLineString to the map as a Polyline
- *
- * @param geoJsonLineStringStyle contains relevant styling properties for the Polyline
- * @param geoJsonLineString contains coordinates for the Polyline
- * @return Polyline object created from given GeoJsonLineString
- */
- private Polyline addLineStringToMap(GeoJsonLineStringStyle geoJsonLineStringStyle,
- GeoJsonLineString geoJsonLineString) {
- PolylineOptions polylineOptions = geoJsonLineStringStyle.toPolylineOptions();
- // Add coordinates
- polylineOptions.addAll(geoJsonLineString.getCoordinates());
- return mMap.addPolyline(polylineOptions);
- }
-
- /**
- * Adds all GeoJsonLineString objects in the GeoJsonMultiLineString to the map as multiple
- * Polylines
- *
- * @param geoJsonLineStringStyle contains relevant styling properties for the Polylines
- * @param geoJsonMultiLineString contains an array of GeoJsonLineStrings
- * @return array of Polylines that have been added to the map
- */
- private ArrayList addMultiLineStringToMap(
- GeoJsonLineStringStyle geoJsonLineStringStyle,
- GeoJsonMultiLineString geoJsonMultiLineString) {
- ArrayList polylines = new ArrayList();
- for (GeoJsonLineString geoJsonLineString : geoJsonMultiLineString.getLineStrings()) {
- polylines.add(addLineStringToMap(geoJsonLineStringStyle, geoJsonLineString));
- }
- return polylines;
- }
-
- /**
- * Adds a GeoJsonPolygon to the map as a Polygon
- *
- * @param geoJsonPolygonStyle contains relevant styling properties for the Polygon
- * @param geoJsonPolygon contains coordinates for the Polygon
- * @return Polygon object created from given GeoJsonPolygon
- */
- private Polygon addPolygonToMap(GeoJsonPolygonStyle geoJsonPolygonStyle,
- GeoJsonPolygon geoJsonPolygon) {
- PolygonOptions polygonOptions = geoJsonPolygonStyle.toPolygonOptions();
- // First array of coordinates are the outline
- polygonOptions.addAll(geoJsonPolygon.getCoordinates().get(POLYGON_OUTER_COORDINATE_INDEX));
- // Following arrays are holes
- for (int i = POLYGON_INNER_COORDINATE_INDEX; i < geoJsonPolygon.getCoordinates().size();
- i++) {
- polygonOptions.addHole(geoJsonPolygon.getCoordinates().get(i));
- }
- return mMap.addPolygon(polygonOptions);
- }
-
- /**
- * Adds all GeoJsonPolygon in the GeoJsonMultiPolygon to the map as multiple Polygons
- *
- * @param geoJsonPolygonStyle contains relevant styling properties for the Polygons
- * @param geoJsonMultiPolygon contains an array of GeoJsonPolygons
- * @return array of Polygons that have been added to the map
- */
- private ArrayList addMultiPolygonToMap(GeoJsonPolygonStyle geoJsonPolygonStyle,
- GeoJsonMultiPolygon geoJsonMultiPolygon) {
- ArrayList polygons = new ArrayList();
- for (GeoJsonPolygon geoJsonPolygon : geoJsonMultiPolygon.getPolygons()) {
- polygons.add(addPolygonToMap(geoJsonPolygonStyle, geoJsonPolygon));
- }
- return polygons;
- }
-
- /**
- * Adds all GeoJsonGeometry objects stored in the GeoJsonGeometryCollection onto the map.
- * Supports recursive GeometryCollections.
- *
- * @param geoJsonFeature contains relevant styling properties for the GeoJsonGeometry inside
- * the GeoJsonGeometryCollection
- * @param geoJsonGeometries contains an array of GeoJsonGeometry objects
- * @return array of Marker, Polyline, Polygons that have been added to the map
- */
- private ArrayList