Search in sources :

Example 6 with Geometry

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

the class KmlFeatureParser method createPlacemark.

/**
     * Creates a new Placemark object (created if a Placemark start tag is read by the
     * XmlPullParser and if a Geometry tag is contained within the Placemark tag)
     * and assigns specific elements read from the parser to the Placemark.
     */
/* package */
static KmlPlacemark createPlacemark(XmlPullParser parser) throws IOException, XmlPullParserException {
    String styleId = null;
    KmlStyle inlineStyle = null;
    HashMap<String, String> properties = new HashMap<String, String>();
    Geometry geometry = null;
    int eventType = parser.getEventType();
    while (!(eventType == END_TAG && parser.getName().equals("Placemark"))) {
        if (eventType == START_TAG) {
            if (parser.getName().equals(STYLE_URL_TAG)) {
                styleId = parser.nextText();
            } else if (parser.getName().matches(GEOMETRY_REGEX)) {
                geometry = createGeometry(parser, parser.getName());
            } else if (parser.getName().matches(PROPERTY_REGEX)) {
                properties.put(parser.getName(), parser.nextText());
            } else if (parser.getName().equals(EXTENDED_DATA)) {
                properties.putAll(setExtendedDataProperties(parser));
            } else if (parser.getName().equals(STYLE_TAG)) {
                inlineStyle = KmlStyleParser.createStyle(parser);
            }
        }
        eventType = parser.next();
    }
    return new KmlPlacemark(geometry, styleId, inlineStyle, properties);
}
Also used : Geometry(com.google.maps.android.data.Geometry) HashMap(java.util.HashMap)

Example 7 with Geometry

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

the class GeoJsonParserTest method testParseGeometryCollection.

public void testParseGeometryCollection() throws Exception {
    GeoJsonParser parser = new GeoJsonParser(validGeometryCollection());
    assertEquals(1, parser.getFeatures().size());
    for (GeoJsonFeature feature : parser.getFeatures()) {
        assertEquals("GeometryCollection", feature.getGeometry().getGeometryType());
        int size = 0;
        for (String property : feature.getPropertyKeys()) {
            size++;
        }
        assertEquals(2, size);
        assertEquals("Popsicles", feature.getId());
        GeoJsonGeometryCollection geometry = ((GeoJsonGeometryCollection) feature.getGeometry());
        assertEquals(1, geometry.getGeometries().size());
        for (Geometry geoJsonGeometry : geometry.getGeometries()) {
            assertEquals("GeometryCollection", geoJsonGeometry.getGeometryType());
        }
    }
}
Also used : Geometry(com.google.maps.android.data.Geometry)

Example 8 with Geometry

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

the class KmlFeatureParserTest method testMultiGeometries.

public void testMultiGeometries() throws Exception {
    XmlPullParser xmlPullParser = createParser(R.raw.amu_nested_multigeometry);
    KmlPlacemark feature = KmlFeatureParser.createPlacemark(xmlPullParser);
    assertEquals(feature.getProperty("name"), "multiPointLine");
    assertEquals(feature.getProperty("description"), "Nested MultiGeometry structure");
    assertEquals(feature.getGeometry().getGeometryType(), "MultiGeometry");
    ArrayList<Geometry> objects = (ArrayList<Geometry>) feature.getGeometry().getGeometryObject();
    assertEquals(objects.get(0).getGeometryType(), "Point");
    assertEquals(objects.get(1).getGeometryType(), "LineString");
    assertEquals(objects.get(2).getGeometryType(), "MultiGeometry");
    ArrayList<Geometry> subObjects = (ArrayList<Geometry>) objects.get(2).getGeometryObject();
    assertEquals(subObjects.get(0).getGeometryType(), "Point");
    assertEquals(subObjects.get(1).getGeometryType(), "LineString");
}
Also used : Geometry(com.google.maps.android.data.Geometry) XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayList(java.util.ArrayList)

Example 9 with Geometry

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

the class KmlRenderer method addContainerObjectToMap.

/**
     * Goes through the every placemark, style and properties object within a <Folder> tag
     *
     * @param kmlContainer Folder to obtain placemark and styles from
     */
private void addContainerObjectToMap(KmlContainer kmlContainer, boolean isContainerVisible) {
    for (Feature placemark : kmlContainer.getPlacemarks()) {
        boolean isPlacemarkVisible = getPlacemarkVisibility(placemark);
        boolean isObjectVisible = isContainerVisible && isPlacemarkVisible;
        if (placemark.getGeometry() != null) {
            String placemarkId = placemark.getId();
            Geometry geometry = placemark.getGeometry();
            KmlStyle style = getPlacemarkStyle(placemarkId);
            KmlStyle inlineStyle = ((KmlPlacemark) placemark).getInlineStyle();
            Object mapObject = addKmlPlacemarkToMap((KmlPlacemark) placemark, geometry, style, inlineStyle, isObjectVisible);
            kmlContainer.setPlacemark((KmlPlacemark) placemark, mapObject);
            putContainerFeature(mapObject, placemark);
        }
    }
}
Also used : Geometry(com.google.maps.android.data.Geometry) Feature(com.google.maps.android.data.Feature)

Example 10 with Geometry

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

the class GeoJsonParser method createGeometryCollection.

/**
     * Creates a new GeoJsonGeometryCollection object containing an array of Geometry
     * objects
     *
     * @param geometries array containing the geometries for the GeoJsonGeometryCollection
     * @return GeoJsonGeometryCollection object
     * @throws JSONException if geometries cannot be parsed
     */
private static GeoJsonGeometryCollection createGeometryCollection(JSONArray geometries) throws JSONException {
    ArrayList<Geometry> geometryCollectionElements = new ArrayList<>();
    for (int i = 0; i < geometries.length(); i++) {
        JSONObject geometryElement = geometries.getJSONObject(i);
        Geometry geometry = parseGeometry(geometryElement);
        if (geometry != null) {
            // Do not add geometries that could not be parsed
            geometryCollectionElements.add(geometry);
        }
    }
    return new GeoJsonGeometryCollection(geometryCollectionElements);
}
Also used : Geometry(com.google.maps.android.data.Geometry) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList)

Aggregations

Geometry (com.google.maps.android.data.Geometry)11 ArrayList (java.util.ArrayList)6 MultiGeometry (com.google.maps.android.data.MultiGeometry)3 HashMap (java.util.HashMap)2 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 Feature (com.google.maps.android.data.Feature)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1