Android 消费者 SDK v1.0 自定义设置迁移

标记自定义

在早期版本的消费者 SDK 中,您使用了消费者 SDK 的 MarkerStyleOptions 对象,用于自定义标记样式属性。消费者 SDK v1.0,您可以直接使用 Maps SDK 中的 MarkerOptions 对象。

// Centering the marker anchor at (0.5, 0.5) is recommended.
// For vehicle markers, set flat to true to allow the vehicle marker to freely
// rotate flat on the map (rather than always have it face the camera).
MarkerOptions vehicleMarkerOptions = new MarkerOptions()
    .flat(true)
    .anchor(0.5f, 0.5f)
    .icon(vehicleIcon)
    .zIndex(1.0f);
consumerMapStyle.setMarkerStyleOptions(MarkerType.TRIP_VEHICLE);

ConsumerMapStyle 会返回 SDK 为 如果尚未设置样式,或者样式选项 已设为 null

// ConsumerMapStyle returns the SDK-set default style options if none has been set yet.
MarkerOptions defaultPickupPointStyleOptions = consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);

// Setting the style to null reverts the style back to the SDK-set default properties.
consumerMapStyle.setMarkerStyleOptions(MarkerType.PICKUP_POINT, /* markerStyleOptions= */ null);
MarkerOptions defaultPickupPointStyleOptions = consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);

如果您不想从头开始创建新样式,可以修改 样式。以下示例仅修改了取货图标,并使用 SDK 中其余标记选项的默认设置。

// getMarkerStyleOptions returns the default pickup point style options, since
// the custom style hasn't been set yet.
MarkerOptions pickupPointStyleOptions =
  consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);
// Modify the icon value and set the style.
consumerMapStyle.setMarkerStyleOptions(
  pickupPointStyleOptions.icon(pickupPointIcon));

多段线自定义

在早期版本的消费者 SDK 中,您使用了消费者 SDK 的 PolylineStyleOptions 对象,用于自定义多段线的样式属性。在 使用方 SDK v1.0,您将使用 Maps SDK 中的 PolylineOptions 对象 用于自定义基本多段线样式属性和 TrafficStyle 对象来自定义折线路况颜色。

如果消费者 SDK v1.0 的 Alpha 变体中提供了路况多段线 路况可见,则基础多段线的颜色会被路况覆盖 颜色。默认情况下,系统不会显示流量。TrafficStyle 中 以 SDK 指定的默认值填充。

// PolylineOptions is from Maps SDK
PolylineOptions polylineOptions = new PolylineOptions()
  .color(color)
  .width(width)
  .geodesic(geodesic)
  .startCap(startCap)
  .endCap(endCap)
  .zIndex(zIndex);
consumerMapStyle.setPolylineStyleOptions(
  PolylineType.ACTIVE_ROUTE, polylineOptions);

// TrafficStyle is from ConsumerSDK
TrafficStyle trafficStyle = TrafficStyle.builder()
  .setTrafficVisibility(true)
  .setTrafficColor(SpeedType.NO_DATA, Color.GREY)
  .setTrafficColor(SpeedType.NORMAL_VALUE, Color.BLUE)
  .setTrafficColor(SpeedType.SLOW_VALUE, Color.ORANGE)
  .setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)
  .build();
consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle);

ConsumerMapStyle 会针对指定的参数返回 SDK 的默认样式选项 如果尚未设置,或设置了样式选项,则使用多段线类型 至 null。这适用于基本 PolylineOptionsTrafficStyle

// ConsumerMapStyle returns the SDK's default style options if none has been set yet.
PolylineOptions defaultActiveRouteStyleOptions = consumerMapStyle.getPolylineStyleOptions(PolylineType.ACTIVE_ROUTE);

// Setting the style to null reverts the style back to the SDK-set default properties.
consumerMapStyle.setPolylineStyleOptions(
  PolylineType.ACTIVE_ROUTE, /* polylineStyleOptions= */ null);
PolylineOptions defaultActiveRouteStyleOptions =
  consumerMapStyle.getPolylineStyleOptions(PolylineType.ACTIVE_ROUTE);

如果您不想从头开始创建新样式,可以修改 样式。以下示例仅修改了基本的有效路线多段线 并将 SDK 的默认样式设置用于标记的其余部分 选项。

// Only customize the remaining route polyline color.
PolylineOptions remainingRouteStyleOptions =
     consumerMapStyle.getPolylineStyleOptions(PolylineType.REMAINING_ROUTE);
consumerMapStyle.setPolylineStyleOptions(
  remainingRouteStyleOptions.color(Color.DARK_BLUE));