ปรับแต่งเครื่องหมาย
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ปรับแต่งรูปลักษณ์ของเครื่องหมายที่เพิ่มลงในแผนที่ ปรับแต่งรูปลักษณ์
ของเครื่องหมายที่เพิ่มลงในแผนที่ได้ 2 วิธีดังนี้
เครื่องหมายสไตล์ตามประเภท: ระบุออบเจ็กต์
MarkerOptions
เพื่อจัดรูปแบบเครื่องหมายสไตล์ประเภทเดียวกัน จากนั้นระบบจะใช้การเปลี่ยนแปลงที่คุณระบุหลังจากสร้างเครื่องหมายแต่ละรายการ โดยจะเขียนทับตัวเลือกเริ่มต้น
ดูตัวอย่างได้ที่
เปลี่ยนสไตล์ของเครื่องหมายโดยใช้ MarkerOptions
ในคำแนะนำนี้
เครื่องหมายสไตล์ตามข้อมูล: ระบุฟังก์ชันการปรับแต่งเพื่อ
จัดรูปแบบเครื่องหมายตามข้อมูล คุณจัดรูปแบบตามข้อมูลจากการแชร์การเดินทางหรือจากแหล่งที่มาภายนอกได้ดังนี้
ข้อมูลจากการแชร์การเดินทาง: การแชร์การเดินทางจะส่งข้อมูลเครื่องหมายไปยังฟังก์ชันการปรับแต่ง ซึ่งรวมถึงประเภทออบเจ็กต์ที่เครื่องหมายแสดง ได้แก่ ยานพาหนะ ต้นทาง จุดอ้างอิง หรือปลายทาง จากนั้นการจัดรูปแบบเครื่องหมายจะเปลี่ยนไป
ตามสถานะปัจจุบันขององค์ประกอบเครื่องหมาย เช่น จำนวน
จุดอ้างอิงที่เหลืออยู่จนกว่ายานพาหนะจะสิ้นสุดการเดินทาง
แหล่งที่มาภายนอก: คุณสามารถรวมข้อมูลการแชร์การเดินทางกับข้อมูลจากแหล่งที่มาภายนอก Fleet Engine และจัดรูปแบบเครื่องหมายตามข้อมูลดังกล่าวได้ด้วย
ดูตัวอย่างได้ที่
เปลี่ยนรูปแบบของเครื่องหมายโดยใช้ฟังก์ชันการปรับแต่ง
ในคู่มือนี้
เพิ่มการจัดการการคลิกไปยังเครื่องหมาย: ดูตัวอย่างได้ที่เพิ่มการจัดการการคลิก
ตัวเลือกการปรับแต่งเครื่องหมาย
ทั้ง 2 ตัวเลือกใช้พารามิเตอร์การปรับแต่งต่อไปนี้ใน Google
Maps JavaScript API ภายใต้
FleetEngineTripLocationProviderOptions
เปลี่ยนรูปแบบของเครื่องหมายโดยใช้ MarkerOptions
ตัวอย่างต่อไปนี้แสดงวิธีกำหนดค่ารูปแบบเครื่องหมายยานพาหนะด้วยออบเจ็กต์ MarkerOptions
ทำตามรูปแบบนี้เพื่อปรับแต่งสไตล์ของเครื่องหมาย
โดยใช้การปรับแต่งเครื่องหมายใดก็ได้ที่ระบุไว้ใน
ตัวเลือกการปรับแต่งเครื่องหมาย
JavaScript
deliveryVehicleMarkerCustomization = {
cursor: 'grab'
};
TypeScript
deliveryVehicleMarkerCustomization = {
cursor: 'grab'
};
เปลี่ยนรูปแบบของเครื่องหมายโดยใช้ฟังก์ชันการปรับแต่ง
ตัวอย่างต่อไปนี้แสดงวิธีกำหนดค่าการจัดรูปแบบเครื่องหมายยานพาหนะโดยใช้ฟังก์ชันการปรับแต่ง ทำตามรูปแบบนี้เพื่อปรับแต่งสไตล์ของเครื่องหมาย
โดยใช้พารามิเตอร์การปรับแต่งเครื่องหมายใดก็ได้ที่ระบุไว้ใน
ตัวเลือกการปรับแต่งเครื่องหมาย
JavaScript
vehicleMarkerCustomization =
(params) => {
var distance = params.trip.remainingWaypoints.length;
params.marker.setLabel(`${distance}`);
};
TypeScript
vehicleMarkerCustomization =
(params: TripMarkerCustomizationFunctionParams) => {
const distance = params.trip.remainingWaypoints.length;
params.marker.setLabel(`${distance}`);
};
เพิ่มการจัดการการคลิกลงในเครื่องหมาย
ตัวอย่างต่อไปนี้แสดงวิธีเพิ่มการจัดการการคลิกลงในเครื่องหมายยานพาหนะ
ทำตามรูปแบบนี้เพื่อเพิ่มการจัดการการคลิกไปยังเครื่องหมายใดก็ได้โดยใช้พารามิเตอร์การปรับแต่งเครื่องหมาย
ใดก็ได้ที่ระบุไว้ในตัวเลือกการปรับแต่งเครื่องหมาย
JavaScript
vehicleMarkerCustomization =
(params) => {
if (params.isNew) {
params.marker.addListener('click', () => {
// Perform desired action.
});
}
};
TypeScript
vehicleMarkerCustomization =
(params: TripMarkerCustomizationFunctionParams) => {
if (params.isNew) {
params.marker.addListener('click', () => {
// Perform desired action.
});
}
};
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eCustomize the look and feel of markers on the map based on marker type or underlying data like trip progress.\u003c/p\u003e\n"],["\u003cp\u003eUse \u003ccode\u003eMarkerOptions\u003c/code\u003e objects to style markers by type, such as setting the cursor for delivery vehicle markers.\u003c/p\u003e\n"],["\u003cp\u003eUse customization functions to style markers dynamically based on trip data, like displaying remaining waypoints.\u003c/p\u003e\n"],["\u003cp\u003eImplement custom click handling for markers to trigger specific actions when a user interacts with them.\u003c/p\u003e\n"],["\u003cp\u003eLeverage \u003ccode\u003eFleetEngineTripLocationProviderOptions\u003c/code\u003e to access marker customization parameters like \u003ccode\u003evehicleMarkerCustomization\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/mobility/journey-sharing/on-demand/android/customize-markers \"View this page for the Android platform docs.\") [iOS](/maps/documentation/mobility/journey-sharing/on-demand/ios/customize-markers \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-markers \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nCustomize the look and feel of markers added to the map. Customize the look\nand feel of markers added to the map in two ways:\n\n1. **Style markers based on type** : Specify a\n [`MarkerOptions`](/maps/documentation/javascript/reference/marker#MarkerOptions)\n object to style markers of the same type. The changes you specify are\n then applied after each marker is created, overwriting any default options.\n For examples, see\n [Change the styling of markers using `MarkerOptions`](#markeropt) in this\n guide.\n\n2. **Style markers based on data**: Specify a customization function to\n style markers based on data. You can style based on data from journey\n sharing, or from outside sources:\n\n - **Data from trip sharing**: Trip sharing passes marker data to the\n customization function including the type of object the marker represents:\n vehicle, origin, waypoint or destination. Marker styling then changes\n based on the current state of the marker element. For example, the number\n of waypoints remaining until the vehicle finishes the trip.\n\n - **Outside sources**: You can combine the trip sharing data with\n data from sources outside Fleet Engine and style the marker based on that\n information as well.\n\n For examples, see\n [Change the styling of markers using customization functions](#vehicle-markers)\n in this guide.\n3. **Add click handling to markers** : For examples,\n see [Add click handling](#add-click).\n\nMarker customization options\n\nBoth options use the following customization parameters in the Google\nMaps JavaScript API under\n[`FleetEngineTripLocationProviderOptions`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions):\n\n- [`vehicleMarkerCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.vehicleMarkerCustomization)\n- [`originMarkerCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.originMarkerCustomization)\n- [`waypointMarkerCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.waypointMarkerCustomization)\n- [`destinationMarkerCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.destinationMarkerCustomization)\n\nChange the styling of markers using `MarkerOptions`\n\nThe following example shows how to configure vehicle marker styling with\na `MarkerOptions` object. Follow this pattern to customize the styling of any\nmarker using any of the marker customizations listed in\n[Marker customization options](#cust-options). \n\nJavaScript \n\n deliveryVehicleMarkerCustomization = {\n cursor: 'grab'\n };\n\nTypeScript \n\n deliveryVehicleMarkerCustomization = {\n cursor: 'grab'\n };\n\nChange the styling of markers using customization functions\n\nThe following example shows how to configure vehicle marker styling using\ncustomization functions. Follow this pattern to customize the styling of any\nmarker using any of the marker customization parameters listed in\n[Marker customization options](#cust-options). \n\nJavaScript \n\n vehicleMarkerCustomization =\n (params) =\u003e {\n var distance = params.trip.remainingWaypoints.length;\n params.marker.setLabel(`${distance}`);\n };\n\nTypeScript \n\n vehicleMarkerCustomization =\n (params: TripMarkerCustomizationFunctionParams) =\u003e {\n const distance = params.trip.remainingWaypoints.length;\n params.marker.setLabel(`${distance}`);\n };\n\nAdd click handling to markers\n\nThe following example shows how to add click handling to a vehicle marker.\nFollow this pattern to add click handling to any marker using any of the marker\ncustomization parameters listed in [Marker customization options](#cust-options). \n\nJavaScript \n\n vehicleMarkerCustomization =\n (params) =\u003e {\n if (params.isNew) {\n params.marker.addListener('click', () =\u003e {\n // Perform desired action.\n });\n }\n };\n\nTypeScript \n\n vehicleMarkerCustomization =\n (params: TripMarkerCustomizationFunctionParams) =\u003e {\n if (params.isNew) {\n params.marker.addListener('click', () =\u003e {\n // Perform desired action.\n });\n }\n };\n\nWhat's next\n\n- [Customize route polylines](/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-route-polylines)"]]