public void addLayerToMap() { setLayerVisibility(true); mGroundOverlays = getGroundOverlayMap(); mContainers = getContainerList(); putStyles(); assignStyleMap(getStyleMaps(), getStylesRenderer()); addGroundOverlays(mGroundOverlays, mContainers); addContainerGroupToMap(mContainers, true); addPlacemarksToMap(getAllFeatures()); if (!mGroundOverlayImagesDownloaded) { downloadGroundOverlays(); } if (!mMarkerIconsDownloaded) { downloadMarkerIcons(); } }
/** * Iterates over the placemarks, gets its style or assigns a default one and adds it to the map * @param placemarks */ private void addPlacemarksToMap(HashMap<? extends Feature, Object> placemarks) { for (Feature kmlPlacemark : placemarks.keySet()) { addFeature(kmlPlacemark); } }
/** * 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 void testAssignStyleMap() { HashMap<String, String> styleMap = new HashMap<String, String>(); styleMap.put("BlueKey", "BlueValue"); HashMap<String, KmlStyle> styles = new HashMap<String, KmlStyle>(); KmlStyle blueStyle = new KmlStyle(); KmlStyle redStyle = new KmlStyle(); styles.put("BlueValue", blueStyle); styles.put("RedValue", redStyle); KmlRenderer renderer = new KmlRenderer(null, null); renderer.assignStyleMap(styleMap, styles); assertNotNull(styles.get("BlueKey")); assertEquals(styles.get("BlueKey"), styles.get("BlueValue")); styles.put("BlueValue", null); renderer.assignStyleMap(styleMap, styles); assertEquals(styles.get("BlueKey"), null); styleMap.put("BlueKey", "RedValue"); renderer.assignStyleMap(styleMap, styles); assertNotNull(styleMap.get("BlueKey")); assertEquals(styles.get("BlueKey"), redStyle); } }
/** * 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); } } }
/** * Creates a new KmlLayer object * * @param map GoogleMap object * @param stream InputStream containing KML file * @throws XmlPullParserException if file cannot be parsed */ public KmlLayer(GoogleMap map, InputStream stream, Context context) throws XmlPullParserException, IOException { if (stream == null) { throw new IllegalArgumentException("KML InputStream cannot be null"); } KmlRenderer mRenderer = new KmlRenderer(map, context); XmlPullParser xmlPullParser = createXmlParser(stream); KmlParser parser = new KmlParser(xmlPullParser); parser.parseKml(); stream.close(); mRenderer.storeKmlData(parser.getStyles(), parser.getStyleMaps(), parser.getPlacemarks(), parser.getContainers(), parser.getGroundOverlays()); storeRenderer(mRenderer); }
/** * Adds all given ground overlays to the map * * @param groundOverlays hashmap of ground overlays to add to the map */ private void addGroundOverlays(HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays) { for (KmlGroundOverlay groundOverlay : groundOverlays.keySet()) { String groundOverlayUrl = groundOverlay.getImageUrl(); if (groundOverlayUrl != null && groundOverlay.getLatLngBox() != null) { // Can't draw overlay if url and coordinates are missing if (getImagesCache().get(groundOverlayUrl) != null) { addGroundOverlayToMap(groundOverlayUrl, mGroundOverlays, true); } else if (!mGroundOverlayUrls.contains(groundOverlayUrl)) { mGroundOverlayUrls.add(groundOverlayUrl); } } } }
/** * 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 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()); } }