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)); }
/** * Adds the marker icon stored in mMarkerIconCache, to the {@link com.google.android.gms.maps.model.Marker} * * @param iconUrl icon url of icon to add to markers * @param placemarks */ private void addIconToMarkers(String iconUrl, HashMap<KmlPlacemark, Object> placemarks) { for (Feature placemark : placemarks.keySet()) { KmlStyle urlStyle = getStylesRenderer().get(placemark.getId()); KmlStyle inlineStyle = ((KmlPlacemark) placemark).getInlineStyle(); if ("Point".equals(placemark.getGeometry().getGeometryType())) { boolean isInlineStyleIcon = inlineStyle != null && iconUrl .equals(inlineStyle.getIconUrl()); boolean isPlacemarkStyleIcon = urlStyle != null && iconUrl .equals(urlStyle.getIconUrl()); if (isInlineStyleIcon) { scaleBitmap(inlineStyle, placemarks, (KmlPlacemark) placemark); } else if (isPlacemarkStyleIcon) { scaleBitmap(urlStyle, placemarks, (KmlPlacemark) placemark); } } } }
/** * Sets a marker info window if no <text> tag was found in the KML document. This method sets * the marker title as the text found in the <name> start tag and the snippet as <description> * * @param style Style to apply */ private void setMarkerInfoWindow(KmlStyle style, Marker marker, final KmlPlacemark placemark) { boolean hasName = placemark.hasProperty("name"); boolean hasDescription = placemark.hasProperty("description"); boolean hasBalloonOptions = style.hasBalloonStyle(); boolean hasBalloonText = style.getBalloonOptions().containsKey("text"); if (hasBalloonOptions && hasBalloonText) { marker.setTitle(style.getBalloonOptions().get("text")); createInfoWindow(); } else if (hasBalloonOptions && hasName) { marker.setTitle(placemark.getProperty("name")); createInfoWindow(); } else if (hasName && hasDescription) { marker.setTitle(placemark.getProperty("name")); marker.setSnippet(placemark.getProperty("description")); createInfoWindow(); } else if (hasDescription) { marker.setTitle(placemark.getProperty("description")); createInfoWindow(); } else if (hasName) { marker.setTitle(placemark.getProperty("name")); createInfoWindow(); } }
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")); }
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 testInlineStyle() throws Exception { XmlPullParser parser = createParser(com.google.maps.android.test.R.raw.amu_inline_style); KmlParser mParser = new KmlParser(parser); mParser.parseKml(); assertNotNull(mParser.getPlacemarks()); assertEquals(mParser.getPlacemarks().size(), 1); for (KmlPlacemark placemark : mParser.getPlacemarks().keySet()) { KmlStyle inlineStyle = placemark.getInlineStyle(); assertNotNull(inlineStyle); assertEquals(inlineStyle.getPolylineOptions().getColor(), Color.parseColor("#000000")); assertEquals(inlineStyle.getPolygonOptions().getFillColor(), Color.parseColor("#ffffff")); assertEquals(inlineStyle.getPolylineOptions().getColor(), inlineStyle.getPolygonOptions().getStrokeColor()); assertEquals(placemark.getGeometry().getGeometryType(), "MultiGeometry"); } }
markerOptions = ((GeoJsonFeature) feature).getMarkerOptions(); } else if (feature instanceof KmlPlacemark) { markerOptions = ((KmlPlacemark) feature).getMarkerOptions(); polylineOptions = ((GeoJsonFeature) feature).getPolylineOptions(); } else if (feature instanceof KmlPlacemark) { polylineOptions = ((KmlPlacemark) feature).getPolylineOptions(); polygonOptions = ((GeoJsonFeature) feature).getPolygonOptions(); } else if (feature instanceof KmlPlacemark) { polygonOptions = ((KmlPlacemark) feature).getPolygonOptions();
public void testExtendedData() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_multiple_placemarks); KmlPlacemark placemark = KmlFeatureParser.createPlacemark(xmlPullParser); assertNotNull(placemark.getProperty("holeNumber")); }
return new KmlPlacemark(geometry, styleId, inlineStyle, properties);
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); }
KmlStyle inlineStyle, boolean isVisible) { String geometryType = geometry.getGeometryType(); boolean hasDrawOrder = placemark.hasProperty("drawOrder"); float drawOrder = 0; drawOrder = Float.parseFloat(placemark.getProperty("drawOrder")); } catch (NumberFormatException e) { hasDrawOrder = false;
/** * 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); } } }
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); }
Geometry geometry = feature.getGeometry(); KmlStyle style = getPlacemarkStyle(placemarkId); KmlStyle inlineStyle = ((KmlPlacemark) feature).getInlineStyle(); mapObject = addKmlPlacemarkToMap((KmlPlacemark) feature, geometry, style, inlineStyle, isPlacemarkVisible); } else {
public static void moveCameraToKml(KmlLayer kmlLayer, GoogleMap googleMap) { //TODO fixed error with some kml file https://developers.google.com/maps/documentation/android-api/utility/kml //Only use in this kml file correctly. LatLngBounds.Builder builder = new LatLngBounds.Builder(); KmlContainer container = kmlLayer.getContainers().iterator().next(); container = container.getContainers().iterator().next(); KmlPlacemark placemark = container.getPlacemarks().iterator().next(); KmlPolygon polygon = (KmlPolygon) placemark.getGeometry(); for (LatLng latLng : polygon.getOuterBoundaryCoordinates()) { builder.include(latLng); } googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 50)); } }