下面列出了怎么用com.google.android.gms.maps.model.GroundOverlay的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Given a Marker, Polyline, Polygon or an array of these and removes it from the map
*
* @param mapObject map object or array of map objects to remove from the map
*/
protected void removeFromMap(Object mapObject) {
if (mapObject instanceof Marker) {
mMarkers.remove((Marker) mapObject);
} else if (mapObject instanceof Polyline) {
mPolylines.remove((Polyline) mapObject);
} else if (mapObject instanceof Polygon) {
mPolygons.remove((Polygon) mapObject);
} else if (mapObject instanceof GroundOverlay) {
mGroundOverlays.remove((GroundOverlay) mapObject);
} else if (mapObject instanceof ArrayList) {
for (Object mapObjectElement : (ArrayList) mapObject) {
removeFromMap(mapObjectElement);
}
}
}
/**
* Adds ground overlays from a given URL onto the map
*
* @param groundOverlayUrl url of ground overlay
* @param groundOverlays hashmap of ground overlays to add to the map
*/
private void addGroundOverlayToMap(String groundOverlayUrl,
HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays, boolean containerVisibility) {
BitmapDescriptor groundOverlayBitmap = getCachedGroundOverlayImage(groundOverlayUrl);
for (KmlGroundOverlay kmlGroundOverlay : groundOverlays.keySet()) {
if (kmlGroundOverlay.getImageUrl().equals(groundOverlayUrl)) {
GroundOverlayOptions groundOverlayOptions = kmlGroundOverlay.getGroundOverlayOptions()
.image(groundOverlayBitmap);
GroundOverlay mapGroundOverlay = attachGroundOverlay(groundOverlayOptions);
if (!containerVisibility) {
mapGroundOverlay.setVisible(false);
}
groundOverlays.put(kmlGroundOverlay, mapGroundOverlay);
}
}
}
public void addOverlay(LatLng place) {
GroundOverlay groundOverlay = mMap.addGroundOverlay(new
GroundOverlayOptions()
.position(place, 100)
.transparency(0.5f)
.zIndex(3)
.image(BitmapDescriptorFactory.fromBitmap(drawableToBitmap(getActivity().getResources().getDrawable(R.drawable.map_overlay)))));
startOverlayAnimation(groundOverlay);
}
@Test
public void shouldEmmitGroundOverlay() throws Exception {
TestSubscriber<GroundOverlay> testSubscriber = new TestSubscriber<>();
new GroundOverlayClickFunc().call(googleMap)
.subscribe(testSubscriber);
verify(googleMap).setOnGroundOverlayClickListener(argumentCaptor.capture());
argumentCaptor.getValue().onGroundOverlayClick(null);
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertValue(null);
}
/**
* Removes all ground overlays in the given hashmap
*
* @param groundOverlays hashmap of ground overlays to remove
*/
protected void removeGroundOverlays(HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays) {
for (GroundOverlay groundOverlay : groundOverlays.values()) {
// Ground overlay values may be null if their image was not yet downloaded
if (groundOverlay != null) {
mGroundOverlays.remove(groundOverlay);
}
}
}
/**
* Stores all given data
*
* @param styles hashmap of styles
* @param styleMaps hashmap of style maps
* @param features hashmap of features
* @param folders array of containers
* @param groundOverlays hashmap of ground overlays
*/
protected void storeData(HashMap<String, KmlStyle> styles,
HashMap<String, String> styleMaps,
HashMap<KmlPlacemark, Object> features,
ArrayList<KmlContainer> folders,
HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays) {
mStyles = styles;
mStyleMaps = styleMaps;
mFeatures.putAll(features);
mContainers = folders;
mGroundOverlayMap = groundOverlays;
}
KmlContainer(HashMap<String, String> properties, HashMap<String, KmlStyle> styles,
HashMap<KmlPlacemark, Object> placemarks, HashMap<String, String> styleMaps,
ArrayList<KmlContainer> containers, HashMap<KmlGroundOverlay, GroundOverlay>
groundOverlay, String Id) {
mProperties = properties;
mPlacemarks = placemarks;
mStyles = styles;
mStyleMap = styleMaps;
mContainers = containers;
mGroundOverlays = groundOverlay;
mContainerId = Id;
}
/**
* Stores all given data from KMZ file
*
* @param styles hashmap of styles
* @param styleMaps hashmap of style maps
* @param features hashmap of features
* @param folders array of containers
* @param groundOverlays hashmap of ground overlays
* @param images hashmap of images
*/
/*package*/ void storeKmzData(HashMap<String, KmlStyle> styles,
HashMap<String, String> styleMaps,
HashMap<KmlPlacemark, Object> features,
ArrayList<KmlContainer> folders,
HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays,
HashMap<String, Bitmap> images) {
storeData(styles, styleMaps, features, folders, groundOverlays);
for (Map.Entry<String, Bitmap> entry : images.entrySet()) {
cacheBitmap(entry.getKey(), entry.getValue());
}
}
/**
* 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());
}
}
/**
* 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 (getCachedGroundOverlayImage(groundOverlayUrl) != null) {
addGroundOverlayToMap(groundOverlayUrl, getGroundOverlayMap(), true);
} else {
mGroundOverlayUrls.add(groundOverlayUrl);
}
}
}
}
@Override
public void onGroundOverlayClick(GroundOverlay groundOverlay) {
Collection collection = mAllObjects.get(groundOverlay);
if (collection != null && collection.mGroundOverlayClickListener != null) {
collection.mGroundOverlayClickListener.onGroundOverlayClick(groundOverlay);
}
}
@Override
public void onGroundOverlayClick(GroundOverlay groundOverlay)
{
onClick((CustomTag) groundOverlay.getTag());
}
@Override
public void onGroundOverlayClick(GroundOverlay groundOverlay) {
onClick((CustomTag) groundOverlay.getTag());
}
/**
* Toggles the visibility between 100% and 50% when a {@link GroundOverlay} is clicked.
*/
@Override
public void onGroundOverlayClick(GroundOverlay groundOverlay) {
// Toggle transparency value between 0.0f and 0.5f. Initial default value is 0.0f.
groundOverlayRotated.setTransparency(0.5f - groundOverlayRotated.getTransparency());
}
/**
* Creates a new KmlContainer objects and assigns specific elements read from the XmlPullParser
* to the new KmlContainer.
*
* @param parser XmlPullParser object reading from a KML file
* @return KmlContainer object with properties read from the XmlPullParser
*/
private static KmlContainer assignPropertiesToContainer(XmlPullParser parser)
throws XmlPullParserException, IOException {
String startTag = parser.getName();
String containerId = null;
HashMap<String, String> containerProperties = new HashMap<String, String>();
HashMap<String, KmlStyle> containerStyles = new HashMap<String, KmlStyle>();
HashMap<? extends Feature, Object> containerPlacemarks = new HashMap<>();
ArrayList<KmlContainer> nestedContainers = new ArrayList<KmlContainer>();
HashMap<String, String> containerStyleMaps = new HashMap<String, String>();
HashMap<KmlGroundOverlay, GroundOverlay> containerGroundOverlays
= new HashMap<KmlGroundOverlay, GroundOverlay>();
if (parser.getAttributeValue(null, "id") != null) {
containerId = parser.getAttributeValue(null, "id");
}
parser.next();
int eventType = parser.getEventType();
while (!(eventType == END_TAG && parser.getName().equals(startTag))) {
if (eventType == START_TAG) {
if (parser.getName().matches(UNSUPPORTED_REGEX)) {
KmlParser.skip(parser);
} else if (parser.getName().matches(CONTAINER_REGEX)) {
nestedContainers.add(assignPropertiesToContainer(parser));
} else if (parser.getName().matches(PROPERTY_REGEX)) {
containerProperties.put(parser.getName(), parser.nextText());
} else if (parser.getName().equals(STYLE_MAP)) {
setContainerStyleMap(parser, containerStyleMaps);
} else if (parser.getName().equals(STYLE)) {
setContainerStyle(parser, containerStyles);
} else if (parser.getName().equals(PLACEMARK)) {
setContainerPlacemark(parser, (HashMap<KmlPlacemark, Object>) containerPlacemarks);
} else if (parser.getName().equals(EXTENDED_DATA)) {
setExtendedDataProperties(parser, containerProperties);
} else if (parser.getName().equals(GROUND_OVERLAY)) {
containerGroundOverlays
.put(KmlFeatureParser.createGroundOverlay(parser), null);
}
}
eventType = parser.next();
}
return new KmlContainer(containerProperties, containerStyles, (HashMap<KmlPlacemark, Object>) containerPlacemarks,
containerStyleMaps, nestedContainers, containerGroundOverlays, containerId);
}
/**
* @return A list of Ground Overlays
*/
/* package */ HashMap<KmlGroundOverlay, GroundOverlay> getGroundOverlays() {
return mGroundOverlays;
}
@Override
protected void removeObjectFromMap(GroundOverlay object) {
object.remove();
}
public GroundOverlay addGroundOverlay(GroundOverlayOptions opts) {
GroundOverlay groundOverlay = mMap.addGroundOverlay(opts);
super.add(groundOverlay);
return groundOverlay;
}
public void showAll() {
for (GroundOverlay groundOverlay : getGroundOverlays()) {
groundOverlay.setVisible(true);
}
}
public void hideAll() {
for (GroundOverlay groundOverlay : getGroundOverlays()) {
groundOverlay.setVisible(false);
}
}
public boolean remove(GroundOverlay groundOverlay) {
return super.remove(groundOverlay);
}
public java.util.Collection<GroundOverlay> getGroundOverlays() {
return getObjects();
}
/**
* Stores all given data from KML file
*
* @param styles hashmap of styles
* @param styleMaps hashmap of style maps
* @param features hashmap of features
* @param folders array of containers
* @param groundOverlays hashmap of ground overlays
*/
/*package*/ void storeKmlData(HashMap<String, KmlStyle> styles,
HashMap<String, String> styleMaps,
HashMap<KmlPlacemark, Object> features,
ArrayList<KmlContainer> folders,
HashMap<KmlGroundOverlay, GroundOverlay> groundOverlays) {
storeData(styles, styleMaps, features, folders, groundOverlays);
}
/**
* Gets the ground overlays on the current layer
*
* @return mGroundOverlayMap hashmap contains the ground overlays
*/
public HashMap<KmlGroundOverlay, GroundOverlay> getGroundOverlayMap() {
return mGroundOverlayMap;
}
/**
* Adds a ground overlay to the map
*
* @param groundOverlayOptions GroundOverlay style options to be added to the map
* @return new GroundOverlay object created from the given GroundOverlayOptions
*/
protected GroundOverlay attachGroundOverlay(GroundOverlayOptions groundOverlayOptions) {
return mGroundOverlays.addGroundOverlay(groundOverlayOptions);
}
/**
* Gets all of the ground overlays which were set in the container
*
* @return A set of ground overlays
*/
/* package */ HashMap<KmlGroundOverlay, GroundOverlay> getGroundOverlayHashMap() {
return mGroundOverlays;
}