Android Open Source - android-openmap-framework Hash Map Itemized Overlay






From Project

Back to project page android-openmap-framework.

License

The source code is released under:

Apache License

If you think the Android project android-openmap-framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jwetherell.openmap.overlay;
/* ww  w  .  jav a  2 s.  co m*/
import java.util.HashMap;

import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;


/**
 * This class extends ItemizedOverlay to handle the OverlayItems using a
 * HashMap.
 * 
 * @author Justin Wetherell <phishman3579@gmail.com>
 */
public class HashMapItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private HashMap<String, OverlayItem> mapOverlays = new HashMap<String, OverlayItem>();

    public HashMapItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }

    /**
     * Add OverlayItem to Overlay.
     * 
     * @param item
     *            OverlayItem to add.
     * @throws NullPointerException
     *             if item is NULL.
     */
    public void addOverlay(OverlayItem item) {
        if (item == null) throw new NullPointerException();

        mapOverlays.put(getKey(item), item);
        populate();
    }

    /**
     * Add OverlayItem with marker as it's default Drawable to Overlay.
     * 
     * @param item
     *            OverlayItem to add.
     * @throws NullPointerException
     *             if item is NULL.
     */
    public void addOverlay(OverlayItem item, Drawable marker) {
        if (item == null || marker == null) throw new NullPointerException();

        item.setMarker(boundCenterBottom(marker));
        mapOverlays.put(getKey(item), item);
        populate();
    }

    /**
     * Does the Overlay contain the given OverlayItem.
     * 
     * @param item
     *            OverlayItem to check for.
     * @return True of the OverlayItem is in this Overlay.
     */
    public boolean containsOverlay(OverlayItem item) {
        if (item == null) return false;

        String key = getKey(item);
        return mapOverlays.containsKey(key);
    }

    /**
     * Remove the given OverlayItem from the Overlay.
     * 
     * @param item
     *            OverlayItem to remove.
     */
    public void removeOverlay(OverlayItem item) {
        if (item == null) return;

        if (containsOverlay(item)) {
            mapOverlays.remove(getKey(item));
            populate();
        }
    }

    /**
     * Remove all OverlayItems from the Overlay.
     */
    public void clearOverlays() {
        mapOverlays.clear();
        populate();
    }

    private static String getKey(OverlayItem item) {
        if (item == null) throw new NullPointerException();

        return item.getTitle() + item.getSnippet();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected OverlayItem createItem(int i) {
        Object[] array = mapOverlays.values().toArray();
        OverlayItem item = (OverlayItem) array[i];
        return item;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int size() {
        return mapOverlays.size();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        if (canvas == null || mapView == null) throw new NullPointerException();

        // draw without a shadow
        super.draw(canvas, mapView, false);
    }
}




Java Source Code List

com.jwetherell.openmap.activity.CenteredMapActivity.java
com.jwetherell.openmap.activity.CustomMapActivity.java
com.jwetherell.openmap.activity.OpenMapDemo.java
com.jwetherell.openmap.activity.configure.ConfigureUser.java
com.jwetherell.openmap.common.Ellipsoid.java
com.jwetherell.openmap.common.GreatCircle.java
com.jwetherell.openmap.common.LatLonPoint.java
com.jwetherell.openmap.common.Length.java
com.jwetherell.openmap.common.MGRSPoint.java
com.jwetherell.openmap.common.MoreMath.java
com.jwetherell.openmap.common.Planet.java
com.jwetherell.openmap.common.ProjMath.java
com.jwetherell.openmap.common.UTMPoint.java
com.jwetherell.openmap.common.ZonedUTMPoint.java
com.jwetherell.openmap.data.MessageUtilities.java
com.jwetherell.openmap.data.UserData.java
com.jwetherell.openmap.overlay.HashMapItemizedOverlay.java
com.jwetherell.openmap.utilities.Utilities.java