Search in sources :

Example 1 with GeoJsonLayer

use of com.google.maps.android.geojson.GeoJsonLayer in project AirMapView by airbnb.

the class NativeGoogleMapFragment method setGeoJsonLayer.

@Override
public void setGeoJsonLayer(final AirMapGeoJsonLayer airMapGeoJsonLayer) throws JSONException {
    // clear any existing layers
    clearGeoJsonLayer();
    layerOnMap = new GeoJsonLayer(googleMap, new JSONObject(airMapGeoJsonLayer.geoJson));
    GeoJsonPolygonStyle style = layerOnMap.getDefaultPolygonStyle();
    style.setStrokeColor(airMapGeoJsonLayer.strokeColor);
    style.setStrokeWidth(airMapGeoJsonLayer.strokeWidth);
    style.setFillColor(airMapGeoJsonLayer.fillColor);
    layerOnMap.addLayerToMap();
}
Also used : GeoJsonLayer(com.google.maps.android.geojson.GeoJsonLayer) JSONObject(org.json.JSONObject) GeoJsonPolygonStyle(com.google.maps.android.geojson.GeoJsonPolygonStyle)

Example 2 with GeoJsonLayer

use of com.google.maps.android.geojson.GeoJsonLayer in project iosched by google.

the class MapUtils method processGeoJson.

public static GeoJsonLayer processGeoJson(Context context, GoogleMap mMap, JSONObject j) {
    GeoJsonLayer layer = new GeoJsonLayer(mMap, j);
    Iterator<GeoJsonFeature> iterator = layer.getFeatures().iterator();
    final IconGenerator labelIconGenerator = MapUtils.getLabelIconGenerator(context);
    while (iterator.hasNext()) {
        GeoJsonFeature feature = iterator.next();
        // get data
        final String id = feature.getProperty("id");
        final String typeString = feature.getProperty("type");
        final int type = MapUtils.detectMarkerType(typeString);
        final String label = feature.getProperty("title");
        GeoJsonPointStyle pointStyle = new GeoJsonPointStyle();
        if (type == MarkerModel.TYPE_LABEL) {
            // Label markers contain the label as its icon
            pointStyle = MapUtils.createLabelMarker(labelIconGenerator, id, label);
        } else if (type == MarkerModel.TYPE_ICON) {
            // An icon marker is mapped to a drawable based on its full type name
            pointStyle = MapUtils.createIconMarker(typeString, id, false, context);
        } else if (type != MarkerModel.TYPE_INACTIVE) {
            // All other markers (that are not inactive) contain a pin icon
            pointStyle = MapUtils.createPinMarker(context, id);
        }
        // If the marker is invalid (e.g. the icon does not exist), remove it from the map.
        if (pointStyle == null) {
            iterator.remove();
        } else {
            pointStyle.setVisible(true);
            feature.setPointStyle(pointStyle);
        }
    }
    return layer;
}
Also used : GeoJsonFeature(com.google.maps.android.geojson.GeoJsonFeature) GeoJsonLayer(com.google.maps.android.geojson.GeoJsonLayer) GeoJsonPointStyle(com.google.maps.android.geojson.GeoJsonPointStyle) IconGenerator(com.google.maps.android.ui.IconGenerator)

Aggregations

GeoJsonLayer (com.google.maps.android.geojson.GeoJsonLayer)2 GeoJsonFeature (com.google.maps.android.geojson.GeoJsonFeature)1 GeoJsonPointStyle (com.google.maps.android.geojson.GeoJsonPointStyle)1 GeoJsonPolygonStyle (com.google.maps.android.geojson.GeoJsonPolygonStyle)1 IconGenerator (com.google.maps.android.ui.IconGenerator)1 JSONObject (org.json.JSONObject)1