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);
}
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());
}
}
}
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");
}
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);
}
}
}
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);
}
Aggregations