@fleetbase/leaflet-routing-machine

中文文档
3.2.17发布于 2025/05/30ISCCommonJS近 30 天下载 3561

ESM module Routing for Leaflet

原始使用文档
文档目录4 节
  1. Features
  2. Support and New Features
  3. Building
  4. Customize Waypoint Markers

Leaflet Routing Machine NPM version Leaflet 1.0 compatible! Join the chat at https://gitter.im/leaflet-routing-machine/Lobby

This plugin is barely maintained! It has been a good long while since I had any reason to work with routing or Leaflet, and it does not look like that will change. I do not spend time on maintaining this plugin, and only rarely can I find time to respond to issues. If you want to take over as maintainer, feel free to contact me at [email protected].

Find the way from A to B on a Leaflet map. The plugin supports multiple backends:

Features

  • Standard Leaflet control, with Leaflet look and feel
  • Routing from start to destination, with possibility of via points
  • Add, edit and remove waypoints through both address input and using the map
  • Multiple language support
  • Highly customizable for advanced use
  • Customizable look (theming / skins)
  • Open Source released under ISC License (more or less equivalent with the MIT license)

Go to the Leaflet Routing Machine site for more information, demos, tutorials and more.

Update 2020-04-06: Out of the box, Leaflet Routing Machine relies on OSRM's demo server. At this moment, the demo server (which is outside scope of the plugin and outside control of the plugin's author) is no longer maintained, and its SSL certificate has expired. The plugin will not work unless you configure a routing backend yourself. I am sorry to say that, to my knowledge, there is no good default.

Support and New Features

Leaflet Routing Machine is in many ways already a feature complete routing UI. Most likely, your requirements are already covered and require very little adaptation.

For questions and discussions, you might want to look at the Leaflet Routing Machine gitter.

Building

yarn bundle

This requires Node and npm, or yarn.

Usage

Download latest release, or obtain the latest release via unpkg.com.

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet-routing-machine.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet-routing-machine.js"></script>

or via npm/yarn:

npm install --save @fleetbase/leaflet-routing-machine
yarn add @fleetbase/leaflet-routing-machine
import * as L from 'leaflet';
import { OSRMv1, Control as RoutingControl } from '@fleetbase/leaflet-routing-machine';

const map = new L.Map();
const serviceUrl = 'https://routing.fleetbase.io';
const router = new OSRMv1({ serviceUrl, profile: 'driving' });
const routingControl = new RoutingControl({ waypoints: [...], router }).addTo(leafletMap);

Customize Waypoint Markers

You can now customize waypoint markers with markerOptions option for the RoutingControl.

import * as L from 'leaflet';
import { OSRMv1, Control as RoutingControl } from '@fleetbase/leaflet-routing-machine';

const map = new L.Map();
const serviceUrl = 'https://routing.fleetbase.io';
const router = new OSRMv1({ serviceUrl, profile: 'driving' });
const routingControl = new RoutingControl({ 
    waypoints: [...], 
    markerOptions: {
        icon: L.icon({ ... })
    },
    router 
}).addTo(leafletMap);

Go to the Leaflet Routing Machine site for more information, demos, tutorials and more.

版本与发布记录

@fleetbase/leaflet-routing-machine 共发布 6 个版本,首次发布于 2022/06/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.2.17latest2025/05/301.5 年前
3.2.162023/06/163 年前
3.2.152022/06/244 年前
3.2.142022/06/244 年前
3.2.132022/06/244 年前
3.2.122022/06/234 年前

关于 @fleetbase/leaflet-routing-machine 的常见问题

@fleetbase/leaflet-routing-machine 是什么?

ESM module Routing for Leaflet

如何安装 @fleetbase/leaflet-routing-machine?

在项目目录运行 npm install @fleetbase/leaflet-routing-machine,或使用 pnpm add / yarn add / bun add。

@fleetbase/leaflet-routing-machine 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fleetbase__leaflet-routing-machine 是否存在。

@fleetbase/leaflet-routing-machine 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@fleetbase/leaflet-routing-machine 可以商用吗?

@fleetbase/leaflet-routing-machine 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fleetbase/leaflet-routing-machine 的下载量有多少?

根据 npm 官方下载统计,@fleetbase/leaflet-routing-machine 在 2026/10/15 – 2026/11/13 这 30 天内被下载 3,561 次,日均约 119 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fleetbase/leaflet-routing-machine 还在维护吗?

最新版本 3.2.17 发布于 2025/05/30(1.5 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。