/**
   * @see com.brantapps.polaris.api.Mappable#addMarker(com.brantapps.polaris.api.MapMarkerOptions)
   */
  @Override
  public MapMarker<?> addMarker(final MapMarkerOptions<?> mapMarkerOptions) {
    if (itemisedOverlay == null) {
      itemisedOverlay =
          new ItemizedOverlayWithFocus<OverlayItem>(
              new ArrayList<OverlayItem>(), this, getResourceProxy());
      itemisedOverlay.setFocusItemsOnTap(true);
      mapView.setUseSafeCanvas(false);
      mapView.getOverlays().add(itemisedOverlay);
    }

    final Marker marker = (Marker) mapMarkerOptions.get();
    final OverlayItem item =
        new OverlayItem(
            marker.title,
            marker.snippet,
            new org.osmdroid.util.GeoPoint(marker.latitude, marker.longitude));
    if (marker.bitmap != null) {
      item.setMarker(new BitmapDrawable(mapView.getResources(), marker.bitmap));
    } else if (marker.icon != 0) {
      item.setMarker(mapView.getResources().getDrawable(marker.icon));
    }
    if (marker.anchor == Marker.Anchor.CENTER) {
      item.setMarkerHotspot(OverlayItem.HotspotPlace.CENTER);
    }

    itemisedOverlay.addItem(item);
    final MapMarker<Marker> osmMapMarker = new OpenStreetMapMarker(marker);
    overlayItemToMarker.put(item, osmMapMarker);
    return osmMapMarker;
  }
  @Override
  protected void onPostExecute(Void result) {
    super.onPostExecute(result);

    MainActivity.map.getOverlays().clear();

    final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();

    // if (MainActivity.my_lat != 0 && MainActivity.my_lon != 0) {
    OverlayItem myLocationOverlayItem =
        new OverlayItem(
            "Here", "Current Position", new GeoPoint(MainActivity.my_lat, MainActivity.my_lon));
    myLocationOverlayItem.setMarker(MainActivity.myCurrentLocationMarker);
    items.add(myLocationOverlayItem);
    // }

    for (int i = 0; i < MainActivity.drones.size(); i++) {
      OverlayItem droneOverlayItem =
          new OverlayItem(
              "Here",
              "Current Position",
              new GeoPoint(
                  MainActivity.drones.get(i).getLat(), MainActivity.drones.get(i).getLon()));
      droneOverlayItem.setMarker(MainActivity.droneMarker);
      items.add(droneOverlayItem);
    }

    MainActivity.addMarkersOnMap(items);

    DroneAnimation animation = new DroneAnimation();
    animation.execute();
  }
  @Override
  protected boolean onSingleTapUpHelper(
      final int index, final OverlayItem item, final MapView mapView) {

    item1 = item;
    MapFragment.markerName = item.getSnippet();
    pointLatLon = item.getPoint();
    placeMarker = item.getTitle();
    return true;
  }
  private void plotAPlace(LatLon latLon, String title, String msg, int drawableToUse) {
    OverlayItem buildingItem =
        new OverlayItem(title, msg, new GeoPoint(latLon.getLatitude(), latLon.getLongitude()));

    // Create new marker
    Drawable icon = this.getResources().getDrawable(drawableToUse);

    // Set the bounding for the drawable
    icon.setBounds(
        0 - icon.getIntrinsicWidth() / 2,
        0 - icon.getIntrinsicHeight(),
        icon.getIntrinsicWidth() / 2,
        0);

    // Set the new marker to the overlay
    buildingItem.setMarker(icon);
    buildingOverlay.addItem(buildingItem);
  }
  /**
   * Plot a building onto the map
   *
   * @param building The building to put on the map
   * @param title The title to put in the dialog box when the building is tapped on the map
   * @param msg The message to display when the building is tapped
   * @param drawableToUse The icon to use. Can be R.drawable.ic_action_place (or any icon in the
   *     res/drawable directory)
   */
  private void plotABuilding(Building building, String title, String msg, int drawableToUse) {
    // CPSC 210 Students: You should not need to touch this method
    OverlayItem buildingItem =
        new OverlayItem(
            title,
            msg,
            new GeoPoint(building.getLatLon().getLatitude(), building.getLatLon().getLongitude()));

    // Create new marker
    Drawable icon = this.getResources().getDrawable(drawableToUse);

    // Set the bounding for the drawable
    icon.setBounds(
        0 - icon.getIntrinsicWidth() / 2,
        0 - icon.getIntrinsicHeight(),
        icon.getIntrinsicWidth() / 2,
        0);

    // Set the new marker to the overlay
    buildingItem.setMarker(icon);
    buildingOverlay.addItem(buildingItem);
  }
 public void setLocation(GeoPoint location) {
   mOverlayItem = new OverlayItem("cast", "", location);
   mOverlayItem.setMarker(getDefaultMarker());
   removeAllItems();
   addItem(mOverlayItem);
 }
  ///////////////////// THIS IS TO DISPLAY PATH WHEN A* ALGORITHM DETERMINES THE
  // PATH/////////////////////////////
  public void showPathForEdges(ArrayList<Edge> pathData) {
    if (pathData == null || pathData.size() == 0) return;

    // HERE WE OBTAIN THE POINTS WHICH TOGETHER REPRESENT THE PATH
    pathPointList.clear();
    ArrayList<GeoPoint> edgeContourList;
    int color = 0;
    Edge edge;

    for (int i = (pathData.size() - 1); i >= 0; i--) {
      edge = pathData.get(i);
      color = edge.getEdgeColor();
      pathPointList.add(
          new PathPoint(
              edge.getToNode().getLatE6(),
              edge.getToNode().getLongE6(),
              color)); // this is the destination node's coords

      edgeContourList = edge.getEdgeContourList(mContext.getContentResolver());
      if (edgeContourList != null) {
        for (GeoPoint p : edgeContourList) {
          pathPointList.add(new PathPoint(p.getLatitudeE6(), p.getLongitudeE6(), color));
        }
      }

      if (i == 0) {
        // add the data of the first point of the first node
        pathPointList.add(
            new PathPoint(edge.getFromNode().getLatE6(), edge.getFromNode().getLongE6(), color));
      }
    }

    // HERE WE GET THE PATH INDICATORS LIST
    pathIndicatorList.clear();
    pathIndicatorOverlays.removeAllItems();
    Node n;
    int currentType = Edge.TYPE_WALK;
    Resources r = mapView.getResources();
    int indicatorCount = 0;
    int prevEdgeType = -1;
    String title = "";
    for (int i = 0; i < pathData.size(); i++) {
      try {
        edge = pathData.get(i);

        if (edge.getEdgeType() == Edge.TYPE_WAIT) {
          // special case: if the final destination is a bus/tram stop
          // we add a final indicator for destination node
          if (i == (pathData.size() - 1)) { // last edge. must display destination
            n = edge.getToNode();
            indicatorCount++;
            OverlayItem item =
                new OverlayItem(
                    indicatorCount + ":path_indicator" + n.getID(),
                    null,
                    "Reach destination at " + n.getTitle(),
                    n.getGeoPoint(),
                    DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
            item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
            pathIndicatorOverlays.addItem(item);
            break;
          }

          if (edge.getCostForEdge() > 0) title = edge.getFromNode().getTitle();
          continue;
        }

        if (i == 0) { // first edge. must display start point
          currentType = edge.getEdgeType();
          n = edge.getFromNode();
          if (n.getTitle() != null) title = n.getTitle();
          indicatorCount++;
          String descText = edge.getLineName();
          if (edge.getEdgeType() == Edge.TYPE_WALK) {
            if (edge.getCostForEdge() == Edge.DUMMY_EDGE_COST)
              descText = "Walk from your starting location";
            else descText = descText.replace("Alight", "Start").replace("#NODE_NAME#", title);
          } else {
            descText =
                descText
                    .replace("Board", "Start at " + title + " and board")
                    .replace("#NODE_NAME#", "");
          }

          OverlayItem item =
              new OverlayItem(
                  indicatorCount + ":path_indicator" + n.getID(),
                  null,
                  descText,
                  n.getGeoPoint(),
                  DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
          item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
          pathIndicatorOverlays.addItem(item);
        } else {
          if (edge.getEdgeType() != currentType) {
            // if there is a change in the type of edge
            currentType = edge.getEdgeType();
            n = edge.getFromNode();
            if (n.getTitle() != null) title = n.getTitle();
            indicatorCount++;
            String descText = edge.getLineName();
            if (prevEdgeType != Edge.TYPE_WALK && edge.getEdgeType() != Edge.TYPE_WALK)
              descText = descText.replace("Board", "Alight and change to");
            descText = descText.replace("#NODE_NAME#", title);
            OverlayItem item =
                new OverlayItem(
                    indicatorCount + ":path_indicator" + n.getID(),
                    null,
                    descText,
                    n.getGeoPoint(),
                    DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
            item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
            pathIndicatorOverlays.addItem(item);
          }
        }

        // add a final indicator for destination node
        if (i == (pathData.size() - 1)) { // last edge. must display destination
          n = edge.getToNode();
          indicatorCount++;
          OverlayItem item =
              new OverlayItem(
                  indicatorCount + ":path_indicator" + n.getID(),
                  null,
                  "Reach destination at " + n.getTitle(),
                  n.getGeoPoint(),
                  DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
          item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
          pathIndicatorOverlays.addItem(item);
        }

        prevEdgeType = edge.getEdgeType();
      } catch (Exception ignore) {
        ignore.printStackTrace();
      }
    }

    pathOverlay.setPoints(pathPointList);
    mapView.postInvalidate();
  }
 private void onDrawFocusBubble(Canvas canvas, int zoomLevel, Projection projection) {
   if (mItemWithBubble != null) {
     projection.toPixels(mItemWithBubble.getPoint(), mCurScreenCoords);
     onDrawItem(canvas, zoomLevel, (Item) mItemWithBubble, mCurScreenCoords);
   }
 }