경로 다중선 맞춤설정
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 문서에서는 소비자 사용자를 위한 웹 기반 여정 추적 앱에서 사용하는 지도의 경로 다중선을 맞춤설정하는 방법을 설명합니다.
Consumer SDK를 사용하면 지도에서 여정의 경로에 대한 경로 폴리라인 표시 여부를 제어하거나 경로 폴리라인의 스타일을 지정할 수 있습니다. SDK는 여정의 활성 또는 남은 경로에 있는 각 좌표 쌍에 대해 google.maps.Polyline
객체를 만듭니다. 그런 다음 라이브러리는 다음 두 가지 상황에서 이러한 맞춤설정을 적용합니다.
- 지도를 추가하기 전에
- 객체에 사용된 데이터가 변경된 경우
경로 다중선 스타일 지정
마커의 스타일을 지정하는 것과 마찬가지로 맞춤설정 매개변수를 사용하여 경로 폴리라인의 스타일을 지정합니다. 여기에서 다음 방법 중 하나를 사용하여 스타일을 구성합니다.
- 가장 간단한 방법:
PolylineOptions
를 사용하여 일치하는 모든 Polyline
객체가 생성되거나 업데이트될 때 적용합니다.
- 고급: 맞춤설정 함수를 지정합니다.
맞춤설정 함수를 사용하면 Fleet Engine에서 전송한 데이터를 기반으로 객체를 개별적으로 스타일 지정할 수 있습니다. 이 함수는 이동의 현재 상태에 따라 각 객체의 스타일을 변경할 수 있습니다. 예를 들어 차량이 더 느리게 이동할 때
Polyline
객체의 색상을 더 어두운 색상으로 지정하거나 더 두껍게 만들 수 있습니다. Fleet Engine 외부 소스에서 조인하고 이 정보를 기반으로 Polyline
객체의 스타일을 지정할 수도 있습니다.
맞춤설정 매개변수
경로 폴리라인의 스타일을 지정할 때는 FleetEngineTripLocationProviderOptions
에 제공된 매개변수를 사용합니다. 이러한 파라미터는 차량 여정의 다양한 경로 상태를 제공합니다.
PolylineOptions
사용
다음 예에서는 PolylineOptions
를 사용하여 Polyline
객체의 스타일을 구성하는 방법을 보여줍니다. 이 패턴에 따라 앞서 나열된 폴리라인 맞춤설정을 사용하여 Polyline
객체의 스타일을 맞춤설정합니다.
자바스크립트
activePolylineCustomization = {
strokeWidth: 5,
strokeColor: 'black',
};
TypeScript
activePolylineCustomization = {
strokeWidth: 5,
strokeColor: 'black',
};
맞춤설정 함수를 사용하여 경로 폴리라인 스타일 지정
다음 예시에서는 활성 경로 폴리라인의 스타일을 구성하는 방법을 보여줍니다. 이 패턴에 따라 앞서 나열된 경로 폴리라인 맞춤설정 매개변수를 사용하여 Polyline
객체의 스타일을 맞춤설정합니다.
자바스크립트
// Color the route polyline objects in green if the vehicle is nearby.
activePolylineCustomization =
(params) => {
const distance = params.trip.remainingWaypoints[0].distanceMeters;
if (distance < 1000) {
// params.polylines contains an ordered list of Polyline objects for
// the path.
for (const polylineObject of params.polylines) {
polylineObject.setOptions({strokeColor: 'green'});
}
}
};
TypeScript
// Color the route Polyline objects in green if the vehicle is nearby.
activePolylineCustomization =
(params: TripPolylineCustomizationFunctionParams) => {
const distance = params.trip.remainingWaypoints[0].distanceMeters;
if (distance < 1000) {
// params.polylines contains an ordered list of Polyline objects for
// the path.
for (const polylineObject of params.polylines) {
polylineObject.setOptions({strokeColor: 'green'});
}
}
};
경로 다중선 공개 상태 관리
기본적으로 모든 Polyline
객체는 표시됩니다. Polyline
객체를 보이지 않게 하려면 visible
속성을 설정합니다.
자바스크립트
remainingPolylineCustomization = {visible: false};
TypeScript
remainingPolylineCustomization = {visible: false};
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThis documentation explains how to customize the appearance of route polylines within web-based journey tracking applications using the Consumer SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the style of polylines representing the traveled, active, and remaining portions of a journey's route.\u003c/p\u003e\n"],["\u003cp\u003eStyling can be achieved using simple \u003ccode\u003ePolylineOptions\u003c/code\u003e for uniform styling or with customization functions for dynamic, data-driven styling based on the trip's state.\u003c/p\u003e\n"],["\u003cp\u003eRoute polyline visibility can be controlled by setting the \u003ccode\u003evisible\u003c/code\u003e property to \u003ccode\u003efalse\u003c/code\u003e for the desired polyline customization parameter.\u003c/p\u003e\n"]]],["This document details customizing route polylines in web-based journey tracking apps using the Consumer SDK. You can control the visibility and style of route polylines via `PolylineOptions` for simple styling or through customization functions for more dynamic styling, based on data from Fleet Engine or external sources. Polylines can be customized for \"already traveled,\" \"actively traveled,\" and \"not-yet traveled\" paths using `takenPolylineCustomization`, `activePolylineCustomization`, and `remainingPolylineCustomization` parameters respectively. Visibility can be toggled using the `visible` property.\n"],null,["Select platform: [Android](/maps/documentation/mobility/journey-sharing/on-demand/android/customize-polylines \"View this page for the Android platform docs.\") [iOS](/maps/documentation/mobility/journey-sharing/on-demand/ios/customize-polylines \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-route-polylines \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis document covers how to customize route polylines for the map you use in\nyour web-based journey tracking app for consumer users.\n\nWith the Consumer SDK, you can control route polyline visibility or style the\nroute polyline for a journey's route on the map. The SDK creates a\n[`google.maps.Polyline`](/maps/documentation/javascript/reference/polygon#Polyline) object for each pair of coordinates in the journey's\nactive or remaining path. The library then applies these customizations in\ntwo situations:\n\n- before adding the objects to the map\n- when the data used for the objects have changed\n\nStyle route polylines\n\nSimilar to how you can style markers, you style route polylines using\n**customization parameters**. From there, you configure styling using one of the\nfollowing approaches:\n\n- **Simplest** : Use `PolylineOptions` to apply to all of the matched `Polyline` objects when they are created or updated.\n- **Advanced** : Specify a **customization function** . Customization functions allow for individual styling of the objects based on data sent by Fleet Engine. The function can change the styling of each object based on the current state of the journey; for example, coloring the `Polyline` object a deeper shade, or making it thicker when the vehicle is moving slower. You can even join against from sources outside Fleet Engine and style the `Polyline` object based on that information.\n\nCustomization parameters\n\nWhen styling route polylines, you use parameters provided in\n[`FleetEngineTripLocationProviderOptions`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions). These parameters provide for\ndifferent path states in the vehicle's journey, as follows:\n\n- **Already traveled** paths: Use [`takenPolylineCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.takenPolylineCustomization).\n- **Actively traveled** path: Use [`activePolylineCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.activePolylineCustomization).\n- **Not-yet traveled** path: Use [`remainingPolylineCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.remainingPolylineCustomization).\n\nUse `PolylineOptions`\n\nThe following example shows how to configure the styling for a `Polyline` object\nwith [`PolylineOptions`](/maps/documentation/javascript/reference/polygon#PolylineOptions). Follow this pattern to customize the styling of\nany `Polyline` object using any of the polyline customizations listed earlier.\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n activePolylineCustomization = {\n strokeWidth: 5,\n strokeColor: 'black',\n };\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n activePolylineCustomization = {\n strokeWidth: 5,\n strokeColor: 'black',\n };\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nUse customization functions to style route polylines\n\nThe following example shows how to configure styling for an active route\npolyline. Follow this pattern to customize the styling of any `Polyline` object\nusing any of the route polyline customization parameters listed earlier.\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n // Color the route polyline objects in green if the vehicle is nearby.\n activePolylineCustomization =\n (params) =\u003e {\n const distance = params.trip.remainingWaypoints[0].distanceMeters;\n if (distance \u003c 1000) {\n\n // params.polylines contains an ordered list of Polyline objects for\n // the path.\n for (const polylineObject of params.polylines) {\n polylineObject.setOptions({strokeColor: 'green'});\n }\n }\n };\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n // Color the route Polyline objects in green if the vehicle is nearby.\n activePolylineCustomization =\n (params: TripPolylineCustomizationFunctionParams) =\u003e {\n const distance = params.trip.remainingWaypoints[0].distanceMeters;\n if (distance \u003c 1000) {\n\n // params.polylines contains an ordered list of Polyline objects for\n // the path.\n for (const polylineObject of params.polylines) {\n polylineObject.setOptions({strokeColor: 'green'});\n }\n }\n };\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nControl route polyline visibility\n\nBy default, all `Polyline` objects are visible. To make a `Polyline` object\ninvisible, set its [`visible`](/maps/documentation/javascript/reference/polygon#PolylineOptions) property:\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n remainingPolylineCustomization = {visible: false};\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n remainingPolylineCustomization = {visible: false};\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]