コード例 #1
0
ファイル: OverlayDemo.java プロジェクト: zefangaiya/MyAndroid
  public void initOverlay() {
    // add marker overlay
    addOverlay(39.963175, 116.400244, R.drawable.icon_marka, 9);
    addOverlay(39.942821, 116.369199, R.drawable.icon_markb, 5);
    MarkerOptions ooC = (MarkerOptions) addOverlay(39.939723, 116.425541, R.drawable.icon_markc, 7);
    MarkerOptions ooD = (MarkerOptions) addOverlay(39.906965, 116.401394, R.drawable.icon_markd, 0);
    ooC.perspective(false).anchor(0.5f, 0.5f).rotate(30);
    ooD.period(10);

    //		ArrayList<BitmapDescriptor> giflist = new ArrayList<BitmapDescriptor>();
    //		giflist.add(bdA);
    //		giflist.add(bdB);
    //		giflist.add(bdC);

    BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
    mBitmapList.add(bd);
    // add ground overlay
    LatLng southwest = new LatLng(39.92235, 116.380338);
    LatLng northeast = new LatLng(39.947246, 116.414977);
    LatLngBounds bounds = new LatLngBounds.Builder().include(northeast).include(southwest).build();

    BitmapDescriptor bdGround = BitmapDescriptorFactory.fromResource(R.drawable.ground_overlay);

    mBitmapList.add(bdGround);
    OverlayOptions ooGround =
        new GroundOverlayOptions().positionFromBounds(bounds).image(bdGround).transparency(0.8f);
    mBaiduMap.addOverlay(ooGround);

    MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(bounds.getCenter());
    mBaiduMap.setMapStatus(u);

    mBaiduMap.setOnMarkerDragListener(
        new OnMarkerDragListener() {
          public void onMarkerDrag(Marker marker) {}

          public void onMarkerDragEnd(Marker marker) {
            Toast.makeText(
                    OverlayDemo.this,
                    "拖拽结束,新位置:"
                        + marker.getPosition().latitude
                        + ", "
                        + marker.getPosition().longitude,
                    Toast.LENGTH_LONG)
                .show();
          }

          public void onMarkerDragStart(Marker marker) {}
        });
  }
コード例 #2
0
    private void perform(MarkerModifier markerModifier) {
      // Don't show small clusters. Render the markers inside, instead.
      if (!shouldRenderAsCluster(cluster)) {
        for (T item : cluster.getItems()) {
          Marker marker = mMarkerCache.get(item);
          MarkerWithPosition markerWithPosition;
          if (marker == null) {
            MarkerOptions markerOptions = new MarkerOptions();
            if (animateFrom != null) {
              markerOptions.position(animateFrom);
              markerOptions.icon(item.getBitmapDescriptor());
            } else {
              markerOptions.position(item.getPosition());
              markerOptions.icon(item.getBitmapDescriptor());
            }
            onBeforeClusterItemRendered(item, markerOptions);
            marker = mClusterManager.getMarkerCollection().addMarker(markerOptions);
            markerWithPosition = new MarkerWithPosition(marker);
            mMarkerCache.put(item, marker);
            if (animateFrom != null) {
              markerModifier.animate(markerWithPosition, animateFrom, item.getPosition());
            }
          } else {
            markerWithPosition = new MarkerWithPosition(marker);
          }
          onClusterItemRendered(item, marker);
          newMarkers.add(markerWithPosition);
        }
        return;
      }

      MarkerOptions markerOptions =
          new MarkerOptions().position(animateFrom == null ? cluster.getPosition() : animateFrom);

      onBeforeClusterRendered(cluster, markerOptions);

      Marker marker = mClusterManager.getClusterMarkerCollection().addMarker(markerOptions);
      mMarkerToCluster.put(marker, cluster);
      mClusterToMarker.put(cluster, marker);
      MarkerWithPosition markerWithPosition = new MarkerWithPosition(marker);
      if (animateFrom != null) {
        markerModifier.animate(markerWithPosition, animateFrom, cluster.getPosition());
      }
      onClusterRendered(cluster, marker);
      newMarkers.add(markerWithPosition);
    }
コード例 #3
0
 /**
  * er for a Cluster is added to the map. Called before the mark The default implementation draws a
  * circle with a rough count of the number of items.
  */
 protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) {
   int bucket = getBucket(cluster);
   BitmapDescriptor descriptor = mIcons.get(bucket);
   if (descriptor == null) {
     mColoredCircleBackground.getPaint().setColor(getColor(bucket));
     descriptor =
         BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon(getClusterText(bucket)));
     mIcons.put(bucket, descriptor);
   }
   // TODO: consider adding anchor(.5, .5) (Individual markers will overlap more often)
   markerOptions.icon(descriptor);
 }
コード例 #4
0
ファイル: ActivityMain.java プロジェクト: hihua/hihuacode
  @Override
  public void onRelation(final EntityLocation entityLocation, final boolean auto) {
    if (mWaitfor != null) {
      mWaitfor.close();
      mWaitfor = null;
    }

    if (!auto) {
      int id = R.string.request_relation_success;
      if (entityLocation == null) id = R.string.request_relation_fail;

      final Toast toast = Toast.makeText(this, id, Toast.LENGTH_LONG);
      toast.show();
    }

    if (mHandler == null) mHandler = new Handler();

    final int delayed = 2 * 60 * 1000;
    mHandler.postDelayed(this, delayed);

    if (mEntityRelation == null || entityLocation == null) {
      mapViewRefresh(mLatitude, mLongitude, mZoom);
      return;
    }

    final String to = mEntityRelation.getTo();
    if (to == null) {
      mapViewRefresh(mLatitude, mLongitude, mZoom);
      return;
    }

    final String sColor = entityLocation.getColor();
    final List<EntityLocations> locations = entityLocation.getLocations();
    if (locations == null) {
      mapViewRefresh(mLatitude, mLongitude, mZoom);
      return;
    }

    int color = 0, alpha = 20;

    try {
      color = Color.parseColor(sColor);
    } catch (Exception e) {
      color = Color.argb(alpha, 255, 0, 0);
    }

    color = Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));

    if (locations.size() > 0) {
      mBaiduMap.clear();

      int i = 0;
      for (final EntityLocations entityLocations : locations) {
        addTime(sColor, entityLocations, i);
        final int j = i + 1;
        final String name = to.toLowerCase(Locale.ENGLISH) + j;

        final double latitude = entityLocations.getLatitude();
        final double longitude = entityLocations.getLongitude();
        final double accuracy = entityLocations.getRadius();

        if (i == 0) {
          mLatitude = latitude;
          mLongitude = longitude;
        }

        final MarkerOptions markerOptions = new MarkerOptions();
        final CircleOptions circleOptions = new CircleOptions();
        final LatLng latLng = new LatLng(latitude, longitude);
        markerOptions.position(latLng);
        circleOptions.center(latLng);
        circleOptions.radius((int) accuracy);
        circleOptions.fillColor(color);
        circleOptions.stroke(new Stroke(1, color));

        if (mBitmapDescriptor.containsKey(name)) {
          final BitmapDescriptor bitmapDescriptor = mBitmapDescriptor.get(name);
          markerOptions.icon(bitmapDescriptor);
          mBaiduMap.addOverlay(markerOptions);
        } else {
          final BitmapDescriptor bitmapDescriptor = Images.getIcon(name);
          if (bitmapDescriptor != null) {
            markerOptions.icon(bitmapDescriptor);
            mBitmapDescriptor.put(name, bitmapDescriptor);
            mBaiduMap.addOverlay(markerOptions);
          }
        }

        mBaiduMap.addOverlay(circleOptions);
        i++;
      }

      mapViewRefresh(mLatitude, mLongitude, 17.0f, 800);
    }
  }