התאמה אישית של גרסה 1.0 של Android Consumer SDK

התאמה אישית של עט הסימון

בגרסאות קודמות של Consumer SDK, השתמשתם באובייקט MarkerStyleOptions של Consumer SDK כדי להתאים אישית את מאפייני סגנון הסמנים. בגרסה 1.0 של ה-SDK לצרכנים משתמשים ישירות באובייקט MarkerOptions מה-SDK של מפות Google.

// 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));

התאמה אישית של Polyline

בגרסאות קודמות של Consumer SDK, השתמשתם באובייקט PolylineStyleOptions של Consumer SDK כדי להתאים אישית את המאפיינים של סגנון קו פוליגוני. בגרסה 1.0 של Consumer SDK, משתמשים באובייקט PolylineOptions מ-Maps SDK כדי להתאים אישית את מאפייני הסגנון הבסיסי של קו פוליגוני, ובאובייקט TrafficStyle כדי להתאים אישית את צבעי התנועה בקווים פוליגוניים.

קווים פוליגוניים לתנועת גולשים זמינים בגרסת האלפא של ה-SDK בגרסה 1.0. אם תעבורת הנתונים גלויה, צבעי התנועה יבטלו את צבע הקו הפוליגוני הבסיסי. כברירת מחדל, התנועה לא מוצגת. השדות ב-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. הכלל הזה חל גם על PolylineOptions הבסיס וגם על TrafficStyle.

// 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));