/** * 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()); } }
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)); }
/** * 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()); } } }
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); }
/** * 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()); } }
/** * 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); } } }
/** * 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); } } }
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)); } }