Class GeoJsonLayer
- java.lang.Object
-
- com.google.maps.android.data.Layer
-
- com.google.maps.android.data.geojson.GeoJsonLayer
-
public class GeoJsonLayer extends Layer
A class that allows the developer to import GeoJSON data, style it and interact with the imported data.To create a new GeoJsonLayer from a resource stored locally
GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.resource, getApplicationContext());
To render the imported GeoJSON data onto the layer
layer.addLayerToMap();
To remove the rendered data from the layer
layer.removeLayerFromMap();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GeoJsonLayer.GeoJsonOnFeatureClickListener
-
Nested classes/interfaces inherited from class com.google.maps.android.data.Layer
Layer.OnFeatureClickListener
-
-
Constructor Summary
Constructors Constructor Description GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, int resourceId, android.content.Context context)
Creates a new GeoJsonLayer object.GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, int resourceId, android.content.Context context, MarkerManager markerManager, PolygonManager polygonManager, PolylineManager polylineManager, GroundOverlayManager groundOverlayManager)
Creates a new GeoJsonLayer object.GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, org.json.JSONObject geoJsonFile)
Creates a new GeoJsonLayer object.GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, org.json.JSONObject geoJsonFile, MarkerManager markerManager, PolygonManager polygonManager, PolylineManager polylineManager, GroundOverlayManager groundOverlayManager)
Creates a new GeoJsonLayer object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFeature(GeoJsonFeature feature)
Adds a GeoJsonFeature to the layer.void
addLayerToMap()
Adds all the GeoJsonFeature objects parsed from the given GeoJSON data onto the mapcom.google.android.gms.maps.model.LatLngBounds
getBoundingBox()
Gets the LatLngBounds containing the coordinates of the bounding box for the FeatureCollection.java.lang.Iterable<GeoJsonFeature>
getFeatures()
Gets an iterable of all Feature elements that have been added to the layervoid
removeFeature(GeoJsonFeature feature)
Removes the given GeoJsonFeature from the layerjava.lang.String
toString()
-
Methods inherited from class com.google.maps.android.data.Layer
getContainerFeature, getDefaultLineStringStyle, getDefaultPointStyle, getDefaultPolygonStyle, getFeature, getMap, isLayerOnMap, removeLayerFromMap, setMap, setOnFeatureClickListener
-
-
-
-
Constructor Detail
-
GeoJsonLayer
public GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, org.json.JSONObject geoJsonFile, MarkerManager markerManager, PolygonManager polygonManager, PolylineManager polylineManager, GroundOverlayManager groundOverlayManager)
Creates a new GeoJsonLayer object. Default styles are applied to the GeoJsonFeature objects. addLayerToMap() must be called to trigger rendering onto a map. Use this constructor with shared object managers in order to handle multiple layers with their own event handlers on the map.- Parameters:
map
- map where the layer is to be renderedgeoJsonFile
- GeoJSON data to add to the layermarkerManager
- marker manager to create marker collection frompolygonManager
- polygon manager to create polygon collection frompolylineManager
- polyline manager to create polyline collection fromgroundOverlayManager
- ground overlay manager to create ground overlay collection from
-
GeoJsonLayer
public GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, int resourceId, android.content.Context context, MarkerManager markerManager, PolygonManager polygonManager, PolylineManager polylineManager, GroundOverlayManager groundOverlayManager) throws java.io.IOException, org.json.JSONException
Creates a new GeoJsonLayer object. Default styles are applied to the GeoJsonFeature objects. addLayerToMap() must be called to trigger rendering onto a map. Use this constructor with shared object managers in order to handle multiple layers with their own event handlers on the map.- Parameters:
map
- map where the layer is to be renderedresourceId
- GeoJSON file to add to the layercontext
- context of the application, required to open the GeoJSON filemarkerManager
- marker manager to create marker collection frompolygonManager
- polygon manager to create polygon collection frompolylineManager
- polyline manager to create polyline collection fromgroundOverlayManager
- ground overlay manager to create ground overlay collection from- Throws:
java.io.IOException
- if the file cannot be open for readorg.json.JSONException
- if the JSON file has invalid syntax and cannot be parsed successfully
-
GeoJsonLayer
public GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, org.json.JSONObject geoJsonFile)
Creates a new GeoJsonLayer object. Default styles are applied to the GeoJsonFeature objects. addLayerToMap() must be called to trigger rendering onto a map.- Parameters:
map
- map where the layer is to be renderedgeoJsonFile
- GeoJSON data to add to the layer
-
GeoJsonLayer
public GeoJsonLayer(com.google.android.gms.maps.GoogleMap map, int resourceId, android.content.Context context) throws java.io.IOException, org.json.JSONException
Creates a new GeoJsonLayer object. Default styles are applied to the GeoJsonFeature objects. addLayerToMap() must be called to trigger rendering onto a map.- Parameters:
map
- map where the layer is to be renderedresourceId
- GeoJSON file to add to the layercontext
- context of the application, required to open the GeoJSON file- Throws:
java.io.IOException
- if the file cannot be open for readorg.json.JSONException
- if the JSON file has invalid syntax and cannot be parsed successfully
-
-
Method Detail
-
addLayerToMap
public void addLayerToMap()
Adds all the GeoJsonFeature objects parsed from the given GeoJSON data onto the map- Specified by:
addLayerToMap
in classLayer
-
getFeatures
public java.lang.Iterable<GeoJsonFeature> getFeatures()
Gets an iterable of all Feature elements that have been added to the layer- Overrides:
getFeatures
in classLayer
- Returns:
- iterable of Feature elements
-
addFeature
public void addFeature(GeoJsonFeature feature)
Adds a GeoJsonFeature to the layer. If the point, linestring or polygon style is set to null, the relevant default styles are applied.- Parameters:
feature
- GeoJsonFeature to add to the layer
-
removeFeature
public void removeFeature(GeoJsonFeature feature)
Removes the given GeoJsonFeature from the layer- Parameters:
feature
- feature to remove
-
getBoundingBox
public com.google.android.gms.maps.model.LatLngBounds getBoundingBox()
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.- Returns:
- LatLngBounds containing bounding box of FeatureCollection, null if no bounding box
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-