コード例 #1
0
  /**
   * @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;
  }
コード例 #2
0
  ///////////////////// 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();
  }