Search in sources :

Example 1 with KmlPlacemark

use of com.google.maps.android.data.kml.KmlPlacemark 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 KmlPlacemark

use of com.google.maps.android.data.kml.KmlPlacemark in project android-maps-utils by googlemaps.

the class KmlDemoActivity method moveCameraToKml.

private void moveCameraToKml(KmlLayer kmlLayer) {
    //Retrieve the first container in the KML layer
    KmlContainer container = kmlLayer.getContainers().iterator().next();
    //Retrieve a nested container within the first container
    container = container.getContainers().iterator().next();
    //Retrieve the first placemark in the nested container
    KmlPlacemark placemark = container.getPlacemarks().iterator().next();
    //Retrieve a polygon object in a placemark
    KmlPolygon polygon = (KmlPolygon) placemark.getGeometry();
    //Create LatLngBounds of the outer coordinates of the polygon
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (LatLng latLng : polygon.getOuterBoundaryCoordinates()) {
        builder.include(latLng);
    }
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;
    getMap().moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), width, height, 1));
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng) KmlContainer(com.google.maps.android.data.kml.KmlContainer) KmlPlacemark(com.google.maps.android.data.kml.KmlPlacemark) KmlPolygon(com.google.maps.android.data.kml.KmlPolygon)

Aggregations

KmlPlacemark (com.google.maps.android.data.kml.KmlPlacemark)2 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 GeoJsonFeature (com.google.maps.android.data.geojson.GeoJsonFeature)1 GeoJsonLineString (com.google.maps.android.data.geojson.GeoJsonLineString)1 GeoJsonMultiLineString (com.google.maps.android.data.geojson.GeoJsonMultiLineString)1 KmlContainer (com.google.maps.android.data.kml.KmlContainer)1 KmlMultiGeometry (com.google.maps.android.data.kml.KmlMultiGeometry)1 KmlPolygon (com.google.maps.android.data.kml.KmlPolygon)1 KmlStyle (com.google.maps.android.data.kml.KmlStyle)1