/** * Adds placemarks with their corresponding styles onto the map * * @param kmlContainers An arraylist of folders */ private void addContainerGroupToMap(Iterable<KmlContainer> kmlContainers, boolean containerVisibility) { for (KmlContainer container : kmlContainers) { boolean isContainerVisible = getContainerVisibility(container, containerVisibility); if (container.getStyles() != null) { // Stores all found styles from the container putStyles(container.getStyles()); } if (container.getStyleMap() != null) { // Stores all found style maps from the container super.assignStyleMap(container.getStyleMap(), getStylesRenderer()); } addContainerObjectToMap(container, isContainerVisible); if (container.hasContainers()) { addContainerGroupToMap(container.getContainers(), isContainerVisible); } } }
/** * Removes all the KML data from the map and clears all the stored placemarks of those which * are in a container. */ private void removeContainers(Iterable<KmlContainer> containers) { for (KmlContainer container : containers) { removePlacemarks(container.getPlacemarksHashMap()); removeGroundOverlays(container.getGroundOverlayHashMap()); removeContainers(container.getContainers()); } }
/** * Gets the visibility of the container * * @param kmlContainer container to check visibility of * @param isParentContainerVisible true if the parent container is visible, false otherwise * @return true if this container is visible, false otherwise */ static boolean getContainerVisibility(KmlContainer kmlContainer, boolean isParentContainerVisible) { boolean isChildContainerVisible = true; if (kmlContainer.hasProperty("visibility")) { String placemarkVisibility = kmlContainer.getProperty("visibility"); if (Integer.parseInt(placemarkVisibility) == 0) { isChildContainerVisible = false; } } return (isParentContainerVisible && isChildContainerVisible); }
/** * Assigns icons to markers with a url if put in a placemark tag that is nested in a folder. * * @param iconUrl url to obtain marker image * @param kmlContainers kml container which contains the marker */ private void addContainerGroupIconsToMarkers(String iconUrl, Iterable<KmlContainer> kmlContainers) { for (KmlContainer container : kmlContainers) { addIconToMarkers(iconUrl, container.getPlacemarksHashMap()); if (container.hasContainers()) { addContainerGroupIconsToMarkers(iconUrl, container.getContainers()); } } }
/** * Adds ground overlays in containers from a given URL onto the map * * @param groundOverlayUrl url of ground overlay * @param kmlContainers containers containing ground overlays to add to the map */ private void addGroundOverlayInContainerGroups(String groundOverlayUrl, Iterable<KmlContainer> kmlContainers, boolean containerVisibility) { for (KmlContainer container : kmlContainers) { boolean isContainerVisible = getContainerVisibility(container, containerVisibility); addGroundOverlayToMap(groundOverlayUrl, container.getGroundOverlayHashMap(), isContainerVisible); if (container.hasContainers()) { addGroundOverlayInContainerGroups(groundOverlayUrl, container.getContainers(), isContainerVisible); } } }
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 a ground overlay adds all the ground overlays onto the map and recursively adds all * ground overlays stored in the given containers * * @param groundOverlays ground overlays to add to the map * @param kmlContainers containers to check for ground overlays */ private void addGroundOverlays(HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays, Iterable<KmlContainer> kmlContainers) { addGroundOverlays(groundOverlays); for (KmlContainer container : kmlContainers) { addGroundOverlays(container.getGroundOverlayHashMap(), container.getContainers()); } }
public void testCreateContainerProperty() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_basic_folder); KmlContainer kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertTrue(kmlContainer.hasProperties()); assertEquals(kmlContainer.getProperty("name"), "Basic Folder"); xmlPullParser = createParser(R.raw.amu_unknown_folder); kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertTrue(kmlContainer.hasProperty("name")); }
public void testCreateContainerObjects() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_nested_folders); KmlContainer kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertNotNull(kmlContainer.getContainers()); int numberOfNestedContainers = 0; for (KmlContainer container : kmlContainer.getContainers()) { numberOfNestedContainers++; } assertEquals(numberOfNestedContainers, 2); }
/** * 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 testPolyStyleBooleanNumeric() throws Exception { XmlPullParser parser = createParser(com.google.maps.android.test.R.raw.amu_poly_style_boolean_numeric); KmlParser mParser = new KmlParser(parser); mParser.parseKml(); assertNotNull(mParser.getPlacemarks()); assertEquals(1, mParser.getContainers().size()); KmlContainer kmlContainer = mParser.getContainers().get(0); assertEquals(true, kmlContainer.hasPlacemarks()); HashMap<String, KmlStyle> styles = kmlContainer.getStyles(); KmlStyle kmlStyle = styles.get("#fireadvisory"); assertNotNull(kmlStyle); assertEquals(true, kmlStyle.hasFill()); assertEquals(false, kmlStyle.hasOutline()); }
public void testCreateContainerPlacemark() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_basic_folder); KmlContainer kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertTrue(kmlContainer.hasPlacemarks()); assertEquals(kmlContainer.getPlacemarksHashMap().size(), 1); xmlPullParser = createParser(R.raw.amu_multiple_placemarks); kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertTrue(kmlContainer.hasPlacemarks()); assertEquals(kmlContainer.getPlacemarksHashMap().size(), 2); }
public void testContainerHeirarchy() throws Exception { XmlPullParser parser = createParser(com.google.maps.android.test.R.raw.amu_document_nest); KmlParser mParser = new KmlParser(parser); mParser.parseKml(); assertEquals(mParser.getContainers().get(0).getContainerId(), "hasId"); assertEquals(mParser.getContainers().size(), 1); assertTrue(mParser.getContainers().get(0).hasContainers()); }
public void testCreateContainerGroundOverlay() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_ground_overlay); KmlContainer kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertEquals(kmlContainer.getGroundOverlayHashMap().size(), 2); }
public void testCDataEntity() throws Exception { XmlPullParser xmlPullParser = createParser(R.raw.amu_cdata); KmlContainer kmlContainer = KmlContainerParser.createContainer(xmlPullParser); assertEquals(kmlContainer.getProperty("description"), "TELEPORT"); }
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)); } }
public void testPolyStyleBooleanAlpha() throws Exception { XmlPullParser parser = createParser(com.google.maps.android.test.R.raw.amu_poly_style_boolean_alpha); KmlParser mParser = new KmlParser(parser); mParser.parseKml(); assertNotNull(mParser.getPlacemarks()); assertEquals(1, mParser.getContainers().size()); KmlContainer kmlContainer = mParser.getContainers().get(0); assertEquals(true, kmlContainer.hasPlacemarks()); HashMap<String, KmlStyle> styles = kmlContainer.getStyles(); KmlStyle kmlStyle = styles.get("#fireadvisory"); assertNotNull(kmlStyle); assertEquals(true, kmlStyle.hasFill()); assertEquals(false, kmlStyle.hasOutline()); }