Drawing on the Map
Directions Renderer

Directions Renderer

Sử dụng

demo.js
import React, { useRef } from "react";
import { MFDirectionsRenderer, MFMap } from "react-map4d-map";
 
const option = {
  routes: [
    [
      { lat: 16.078814, lng: 108.221592 },
      { lat: 16.078972, lng: 108.223034 },
      { lat: 16.075353, lng: 108.223513 },
    ],
    [
      { lat: 16.078814, lng: 108.221592 },
      { lat: 16.077491, lng: 108.221735 },
      { lat: 16.077659, lng: 108.223212 },
      { lat: 16.075353, lng: 108.223513 },
    ],
  ],
  originMarkerOptions: {
    position: { lat: 16.079774, lng: 108.220534 },
    title: "Start",
    draggable: true,
    visible: true,
  },
  destinationMarkerOptions: {
    position: { lat: 16.073661, lng: 108.222972 },
    title: "End",
    visible: true,
    draggable: true,
    userInteractionEnabled: false,
  },
 
  activeOutlineWidth: 0,
  inactiveOutlineWidth: 2,
  inactiveOutlineColor: "#FF00FF",
};
 
const DemoDirectionsRenderer = () => {
  return (
    <>
      <div style={{ width: "100%", height: "400px" }}>
        <MFMap
          options={{
            center: { lat: 16.077279, lng: 108.222275 },
            zoom: 16,
            controls: true,
          }}
          accessKey={"Your key"}
          version={"2.4"}
        >
          <MFDirectionsRenderer
            routes={option.routes}
            originMarkerOptions={option.originMarkerOptions}
            destinationMarkerOptions={option.destinationMarkerOptions}
            activeOutlineWidth={option.activeOutlineWidth}
            inactiveOutlineWidth={option.inactiveOutlineWidth}
            inactiveOutlineColor={option.inactiveOutlineColor}
          />
        </MFMap>
      </div>
    </>
  );
};
 
export default DemoDirectionsRenderer;

Kết quả

Props

NoNameisRequiredTypeDefault valueDescription
1routesfalsestring | RouteOptions (opens in a new tab)| ILatLng (opens in a new tab)[][]Truyền vào một mảng 2 chiều các tọa độ ILatLng (opens in a new tab) hoặc dữ liệu Route bằng JSON string trả về từ Map4D SDK API Route hoặc một đối tượng RouteOptions (opens in a new tab) để tạo Directions Renderer.
2activedIndexfalsenumberChỉ định index cho route được active trong Directions Renderer.
3activeStrokeWidthfalsenumberChỉ định độ rộng của active line theo đơn vị point.
4activeStrokeColorfaslestringChỉ định màu sắc của active line theo mã HEX (ví dụ "#FF0000").
5activeOutlineWidthfaslenumberChỉ định độ rộng của active outline theo đơn vị point.
6activeOutlineColorfaslestringChỉ định màu sắc của active outline theo mã HEX (ví dụ "#FF0000").
7activeStrokePatternfaslePatternItem (opens in a new tab)Chỉ định pattern của active line. Tương tự như pattern của Polyline
8inactiveStrokeWidthfaslenumberChỉ định độ rộng của inactive line theo đơn vị point.
9inactiveStrokeColorfaslestringChỉ định màu sắc của inactive line theo mã HEX (ví dụ "#FF0000").
10inactiveOutlineWidthfaslenumberChỉ định độ rộng của inactive outline theo đơn vị point.
11inactiveOutlineColorfaslestringChỉ định màu sắc của inactive outline theo mã HEX (ví dụ "#FF0000").
12inactiveStrokePatternfaslePatternItem (opens in a new tab)Chỉ định pattern của inactive outline. Tương tự như pattern của Polyline
13originMarkerOptionsfasleMarkerOptions (opens in a new tab)Chỉ định các options cho marker bắt đầu.
14destinationMarkerOptionsfasleMarkerOptions (opens in a new tab)Chỉ định các options cho marker kết thúc.
15waypointMarkerOptionsfasleMarkerOptions (opens in a new tab)[]Là mảng marker option chỉ định các marker waypoint. Các marker waypoint này có vị trí nằm ngoài route
16onMarkerDragEndfasleFunctionChỉ định options callback sau khi thực hiện việc kéo Marker. Callback được gọi với tham số args là đối tượng chứa tọa độ LatLng của các Marker trong Directions Renderer.
17onHoverfasle(args) => voidEvent khi hover vào direction renderer
18onCreatedfasle(renderer) => voidEvent sau khi direction renderer
Last updated on April 12, 2023