/** * Creates a new placemark object and assigns specific elements read from the XmlPullParser * to the Placemark and stores this into the given Container. */ private static void setContainerPlacemark(XmlPullParser parser, HashMap<KmlPlacemark, Object> containerPlacemarks) throws XmlPullParserException, IOException { containerPlacemarks.put(KmlFeatureParser.createPlacemark(parser), null); }
/** * Convert a string coordinate from a string into a LatLngAlt object * * @param coordinateString coordinate string to convert from * @return LatLngAlt object created from given coordinate string */ private static LatLngAlt convertToLatLngAlt(String coordinateString) { return convertToLatLngAlt(coordinateString, LAT_LNG_ALT_SEPARATOR); }
/** * Convert a string of coordinates into an array of LatLngs * * @param coordinatesString coordinates string to convert from * @return array of LatLng objects created from the given coordinate string array */ private static ArrayList<LatLng> convertToLatLngArray(String coordinatesString) { ArrayList<LatLngAlt> latLngAltsArray = convertToLatLngAltArray(coordinatesString); ArrayList<LatLng> coordinatesArray = new ArrayList<LatLng>(); for (LatLngAlt latLngAlt : latLngAltsArray) { coordinatesArray.add(latLngAlt.latLng); } return coordinatesArray; }
/** * Creates a new Geometry object (Created if "Point", "LineString", "Polygon" or * "MultiGeometry" tag is detected by the XmlPullParser) * * @param geometryType Type of geometry object to create */ private static Geometry createGeometry(XmlPullParser parser, String geometryType) throws IOException, XmlPullParserException { int eventType = parser.getEventType(); while (!(eventType == END_TAG && parser.getName().equals(geometryType))) { if (eventType == START_TAG) { if (parser.getName().equals("Point")) { return createPoint(parser); } else if (parser.getName().equals("LineString")) { return createLineString(parser); } else if (parser.getName().equals("Track")) { return createTrack(parser); } else if (parser.getName().equals("Polygon")) { return createPolygon(parser); } else if (parser.getName().equals("MultiGeometry")) { return createMultiGeometry(parser); } else if (parser.getName().equals("MultiTrack")) { return createMultiTrack(parser); } } eventType = parser.next(); } return null; }
mPlacemarks.put(KmlFeatureParser.createPlacemark(mParser), null); mGroundOverlays.put(KmlFeatureParser.createGroundOverlay(mParser), null);
if (eventType == START_TAG) { if (parser.getName().equals("Icon")) { imageUrl = getImageUrl(parser); } else if (parser.getName().equals("drawOrder")) { drawOrder = Float.parseFloat(parser.nextText()); visibility = Integer.parseInt(parser.nextText()); } else if (parser.getName().equals("ExtendedData")) { properties.putAll(setExtendedDataProperties(parser)); } else if (parser.getName().equals("rotation")) { rotation = getRotation(parser); } else if (parser.getName().matches(PROPERTY_REGEX) || parser.getName().equals("color")) { properties.put(parser.getName(), parser.nextText()); latLonBox = createLatLngBounds(compassPoints.get("north"), compassPoints.get("south"), compassPoints.get("east"), compassPoints.get("west")); return new KmlGroundOverlay(imageUrl, latLonBox, drawOrder, visibility, properties,
} else if (parser.getName().equals(GROUND_OVERLAY)) { containerGroundOverlays .put(KmlFeatureParser.createGroundOverlay(parser), null);
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);
String coordinateString = parser.nextText(); LatLngAlt latLngAlt = convertToLatLngAlt(coordinateString, " "); latLngs.add(latLngAlt.latLng); if (latLngAlt.altitude != null) { properties.putAll(setExtendedDataProperties(parser));
/** * Creates a new KmlMultiGeometry object * * @return KmlMultiGeometry object */ private static KmlMultiGeometry createMultiGeometry(XmlPullParser parser) throws XmlPullParserException, IOException { ArrayList<Geometry> geometries = new ArrayList<Geometry>(); // Get next otherwise have an infinite loop int eventType = parser.next(); while (!(eventType == END_TAG && parser.getName().equals("MultiGeometry"))) { if (eventType == START_TAG && parser.getName().matches(GEOMETRY_REGEX)) { geometries.add(createGeometry(parser, parser.getName())); } eventType = parser.next(); } return new KmlMultiGeometry(geometries); }
/** * Creates a new KmlPolygon object. Parses only one outer boundary and no or many inner * boundaries containing the coordinates. * * @return KmlPolygon object */ private static KmlPolygon createPolygon(XmlPullParser parser) throws XmlPullParserException, IOException { // Indicates if an outer boundary needs to be defined Boolean isOuterBoundary = false; List<LatLng> outerBoundary = new ArrayList<>(); List<List<LatLng>> innerBoundaries = new ArrayList<>(); int eventType = parser.getEventType(); while (!(eventType == END_TAG && parser.getName().equals("Polygon"))) { if (eventType == START_TAG) { if (parser.getName().matches(BOUNDARY_REGEX)) { isOuterBoundary = parser.getName().equals("outerBoundaryIs"); } else if (parser.getName().equals("coordinates")) { if (isOuterBoundary) { outerBoundary = convertToLatLngArray(parser.nextText()); } else { innerBoundaries.add(convertToLatLngArray(parser.nextText())); } } } eventType = parser.next(); } return new KmlPolygon(outerBoundary, innerBoundaries); }
public void testGroundOverlay() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_ground_overlay); KmlGroundOverlay groundOverlay = KmlFeatureParser.createGroundOverlay(xmlPullParser); assertNotNull(groundOverlay); assertEquals(groundOverlay.getProperty("name"), "Sample Ground Overlay"); assertNotNull(groundOverlay.getImageUrl()); assertEquals(groundOverlay.getGroundOverlayOptions().getZIndex(), 99.0f); assertTrue(groundOverlay.getGroundOverlayOptions().isVisible()); assertNotNull(groundOverlay.getLatLngBox()); xmlPullParser = createParser(R.raw.amu_ground_overlay_color); groundOverlay = KmlFeatureParser.createGroundOverlay(xmlPullParser); assertNotNull(groundOverlay); }
public void testExtendedData() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_multiple_placemarks); KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser); assertNotNull(placemark.getProperty("holeNumber")); }
/** * Convert a string of coordinates into an array of LatLngAlts * * @param coordinatesString coordinates string to convert from * @return array of LatLngAlt objects created from the given coordinate string array */ private static ArrayList<LatLngAlt> convertToLatLngAltArray(String coordinatesString) { ArrayList<LatLngAlt> latLngAltsArray = new ArrayList<LatLngAlt>(); // Need to trim to avoid whitespace around the coordinates such as tabs String[] coordinates = coordinatesString.trim().split("(\\s+)"); for (String coordinate : coordinates) { latLngAltsArray.add(convertToLatLngAlt(coordinate)); } return latLngAltsArray; }
/** * Creates a new KmlLineString object * * @return KmlLineString object */ private static KmlLineString createLineString(XmlPullParser parser) throws XmlPullParserException, IOException { ArrayList<LatLng> coordinates = new ArrayList<LatLng>(); ArrayList<Double> altitudes = new ArrayList<Double>(); int eventType = parser.getEventType(); while (!(eventType == END_TAG && parser.getName().equals("LineString"))) { if (eventType == START_TAG && parser.getName().equals("coordinates")) { List <LatLngAlt> latLngAlts = convertToLatLngAltArray(parser.nextText()); for (LatLngAlt latLngAlt : latLngAlts) { coordinates.add(latLngAlt.latLng); if (latLngAlt.altitude != null) { altitudes.add(latLngAlt.altitude); } } } eventType = parser.next(); } return new KmlLineString(coordinates, altitudes); }
public void testPolygon() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_basic_placemark); KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser); assertNotNull(placemark); assertEquals(placemark.getGeometry().getGeometryType(), "Polygon"); KmlPolygon polygon = ((KmlPolygon) placemark.getGeometry()); assertEquals(polygon.getInnerBoundaryCoordinates().size(), 2); assertEquals(polygon.getOuterBoundaryCoordinates().size(), 5); }
/** * Creates a new KmlPoint object * * @return KmlPoint object */ private static KmlPoint createPoint(XmlPullParser parser) throws XmlPullParserException, IOException { LatLngAlt latLngAlt = null; int eventType = parser.getEventType(); while (!(eventType == END_TAG && parser.getName().equals("Point"))) { if (eventType == START_TAG && parser.getName().equals("coordinates")) { latLngAlt = convertToLatLngAlt(parser.nextText()); } eventType = parser.next(); } return new KmlPoint(latLngAlt.latLng, latLngAlt.altitude); }
public void testMultiGeometry() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_multigeometry_placemarks); KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser); assertNotNull( placemark ); assertEquals( placemark .getGeometry().getGeometryType(), "MultiGeometry"); KmlMultiGeometry multiGeometry = ((KmlMultiGeometry) placemark .getGeometry()); assertEquals(multiGeometry.getGeometryObject().size(), 3); }
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"); }
public void testProperties() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_multigeometry_placemarks); KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser); assertTrue( placemark.hasProperties()); assertEquals( placemark .getProperty("name"), "Placemark Test"); assertNull( placemark .getProperty("description")); }