Search in sources :

Example 1 with GeoJsonFeature

use of com.google.maps.android.data.geojson.GeoJsonFeature in project android-maps-utils by googlemaps.

the class Renderer method addFeature.

/**
     * Adds a new Feature to the map if its geometry property is not null.
     *
     * @param feature feature to add to the map
     */
public void addFeature(Feature feature) {
    Object mapObject = FEATURE_NOT_ON_MAP;
    if (feature instanceof GeoJsonFeature) {
        setFeatureDefaultStyles((GeoJsonFeature) feature);
    }
    if (mLayerOnMap) {
        if (mFeatures.containsKey(feature)) {
            // Remove current map objects before adding new ones
            removeFromMap(mFeatures.get(feature));
        }
        if (feature.hasGeometry()) {
            // Create new map object
            if (feature instanceof KmlPlacemark) {
                boolean isPlacemarkVisible = getPlacemarkVisibility(feature);
                String placemarkId = feature.getId();
                Geometry geometry = feature.getGeometry();
                KmlStyle style = getPlacemarkStyle(placemarkId);
                KmlStyle inlineStyle = ((KmlPlacemark) feature).getInlineStyle();
                mapObject = addKmlPlacemarkToMap((KmlPlacemark) feature, geometry, style, inlineStyle, isPlacemarkVisible);
            } else {
                mapObject = addGeoJsonFeatureToMap(feature, feature.getGeometry());
            }
        }
    }
    mFeatures.put(feature, mapObject);
}
Also used : GeoJsonFeature(com.google.maps.android.data.geojson.GeoJsonFeature) KmlMultiGeometry(com.google.maps.android.data.kml.KmlMultiGeometry) KmlStyle(com.google.maps.android.data.kml.KmlStyle) GeoJsonLineString(com.google.maps.android.data.geojson.GeoJsonLineString) GeoJsonMultiLineString(com.google.maps.android.data.geojson.GeoJsonMultiLineString) KmlPlacemark(com.google.maps.android.data.kml.KmlPlacemark)

Example 2 with GeoJsonFeature

use of com.google.maps.android.data.geojson.GeoJsonFeature in project android-maps-utils by googlemaps.

the class GeoJsonDemoActivity method addColorsToMarkers.

/**
     * Adds a point style to all features to change the color of the marker based on its magnitude
     * property
     */
private void addColorsToMarkers(GeoJsonLayer layer) {
    // Iterate over all the features stored in the layer
    for (GeoJsonFeature feature : layer.getFeatures()) {
        // Check if the magnitude property exists
        if (feature.getProperty("mag") != null && feature.hasProperty("place")) {
            double magnitude = Double.parseDouble(feature.getProperty("mag"));
            // Get the icon for the feature
            BitmapDescriptor pointIcon = BitmapDescriptorFactory.defaultMarker(magnitudeToColor(magnitude));
            // Create a new point style
            GeoJsonPointStyle pointStyle = new GeoJsonPointStyle();
            // Set options for the point style
            pointStyle.setIcon(pointIcon);
            pointStyle.setTitle("Magnitude of " + magnitude);
            pointStyle.setSnippet("Earthquake occured " + feature.getProperty("place"));
            // Assign the point style to the feature
            feature.setPointStyle(pointStyle);
        }
    }
}
Also used : GeoJsonFeature(com.google.maps.android.data.geojson.GeoJsonFeature) GeoJsonPointStyle(com.google.maps.android.data.geojson.GeoJsonPointStyle) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor)

Aggregations

GeoJsonFeature (com.google.maps.android.data.geojson.GeoJsonFeature)2 BitmapDescriptor (com.google.android.gms.maps.model.BitmapDescriptor)1 GeoJsonLineString (com.google.maps.android.data.geojson.GeoJsonLineString)1 GeoJsonMultiLineString (com.google.maps.android.data.geojson.GeoJsonMultiLineString)1 GeoJsonPointStyle (com.google.maps.android.data.geojson.GeoJsonPointStyle)1 KmlMultiGeometry (com.google.maps.android.data.kml.KmlMultiGeometry)1 KmlPlacemark (com.google.maps.android.data.kml.KmlPlacemark)1 KmlStyle (com.google.maps.android.data.kml.KmlStyle)1