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

    • 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 rendered
        geoJsonFile - GeoJSON data to add to the layer
        markerManager - marker manager to create marker collection from
        polygonManager - polygon manager to create polygon collection from
        polylineManager - polyline manager to create polyline collection from
        groundOverlayManager - 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 rendered
        resourceId - GeoJSON file to add to the layer
        context - context of the application, required to open the GeoJSON file
        markerManager - marker manager to create marker collection from
        polygonManager - polygon manager to create polygon collection from
        polylineManager - polyline manager to create polyline collection from
        groundOverlayManager - ground overlay manager to create ground overlay collection from
        Throws:
        java.io.IOException - if the file cannot be open for read
        org.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 rendered
        geoJsonFile - 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 rendered
        resourceId - GeoJSON file to add to the layer
        context - context of the application, required to open the GeoJSON file
        Throws:
        java.io.IOException - if the file cannot be open for read
        org.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 class Layer
      • getFeatures

        public java.lang.Iterable<GeoJsonFeature> getFeatures()
        Gets an iterable of all Feature elements that have been added to the layer
        Overrides:
        getFeatures in class Layer
        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 class java.lang.Object