├── .nvmrc
├── .husky
├── .gitignore
└── pre-commit
├── src
├── controls
│ ├── common.css
│ ├── loading-indicator
│ │ ├── types.ts
│ │ ├── main.ts
│ │ └── LoadingIndicatorControl.svelte
│ └── bearings
│ │ ├── main.ts
│ │ ├── types.ts
│ │ └── BearingsControl.svelte
├── tsconfig.json
├── env.d.ts
├── README.md
├── main.ts
└── directions
│ ├── helpers.ts
│ ├── layers.ts
│ ├── utils.ts
│ ├── types.ts
│ └── events.ts
├── .github
├── FUNDING.yml
├── release.yml
├── workflows
│ ├── build-deploy-demo.yml
│ ├── pull-request-checks.yml
│ └── build-publish-lib.yml
└── dependabot.yml
├── demo
├── env.d.ts
├── src
│ ├── assets
│ │ ├── map
│ │ │ ├── images
│ │ │ │ ├── routeline.png
│ │ │ │ ├── balloon-snappoint.png
│ │ │ │ ├── balloon-waypoint.png
│ │ │ │ ├── direction-arrow.png
│ │ │ │ └── balloon-hoverpoint.png
│ │ │ ├── style
│ │ │ │ ├── icons
│ │ │ │ │ ├── star-11.svg
│ │ │ │ │ └── circle-11.svg
│ │ │ │ ├── .travis.yml
│ │ │ │ └── README.md
│ │ │ ├── custom-directions.ts
│ │ │ ├── restyling-example-layers.ts
│ │ │ └── distance-measurement-directions.ts
│ │ └── styles
│ │ │ └── index.css
│ ├── main.ts
│ ├── examples
│ │ ├── README.md
│ │ ├── 9 Loading Indicator Control.svelte
│ │ ├── 8 Aborting Requests.svelte
│ │ ├── 3 Mapbox Directions API and Congestions.svelte
│ │ ├── 4 Origin and Destination.svelte
│ │ ├── 5 Show Routes' Directions.svelte
│ │ ├── 6 Touch-Friendly Features.svelte
│ │ ├── 12 Distance Measurement.svelte
│ │ ├── 2 Programmatical Control.svelte
│ │ ├── 13 Load and Save.svelte
│ │ ├── 1 User Interaction.svelte
│ │ ├── 11 Restyling.svelte
│ │ ├── 14 Multiple profiles.svelte
│ │ ├── 10 Bearings Support and Control.svelte
│ │ └── 7 Events.svelte
│ ├── App.svelte
│ ├── router.ts
│ ├── components
│ │ └── AppSidebar.svelte
│ └── Menu.svelte
├── index.html
└── README.md
├── doc
├── images
│ ├── public-filter.png
│ ├── demo-screenshot-1.png
│ ├── demo-screenshot-2.png
│ ├── demo-screenshot-3.png
│ ├── complex-customization.png
│ └── public-protected-filter.png
├── README.md
├── MAIN.md
├── BASIC_USAGE.md
├── CONTROLS.md
└── CUSTOMIZATION.md
├── postcss.config.cjs
├── typedoc.json
├── CODE_OF_CONDUCT.md
├── tsconfig.node.json
├── .prettierignore
├── svelte.config.cjs
├── .gitignore
├── vite.demo.config.ts
├── tailwind.config.cjs
├── tsconfig.json
├── vite.lib.config.ts
├── tsconfig.lib.json
├── .eslintrc.cjs
├── LICENSE
├── README.md
├── package.json
└── CONTRIBUTING.md
/.nvmrc:
--------------------------------------------------------------------------------
1 | 16
--------------------------------------------------------------------------------
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/src/controls/common.css:
--------------------------------------------------------------------------------
1 | /* Don't strip out! */
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [maplibre]
2 | open_collective: maplibre
--------------------------------------------------------------------------------
/src/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.lib.json"
3 | }
4 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | npx lint-staged
5 |
--------------------------------------------------------------------------------
/demo/env.d.ts:
--------------------------------------------------------------------------------
1 | ///
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | ## Edit the Style
21 |
22 | Use the [Maputnik CLI](http://openmaptiles.org/docs/style/maputnik/) to edit and develop the style.
23 | After you've started Maputnik open the editor on `localhost:8000`.
24 |
25 | ```
26 | maputnik --watch --file style.json
27 | ```
28 |
29 | ## License
30 |
31 | - [ ] Clarify license
32 |
--------------------------------------------------------------------------------
/demo/src/assets/map/custom-directions.ts:
--------------------------------------------------------------------------------
1 | import type maplibregl from "maplibre-gl";
2 | import type { MapLibreGlDirectionsConfiguration, Feature, LineString, Point } from "@maplibre/maplibre-gl-directions";
3 | import MapLibreGlDirections from "@maplibre/maplibre-gl-directions";
4 | import { MapLibreGlDirectionsNonCancelableEvent } from "@maplibre/maplibre-gl-directions";
5 |
6 | export default class CustomMapLibreGlDirections extends MapLibreGlDirections {
7 | constructor(map: maplibregl.Map, configuration?: Partial
66 | The LoadingIndicatorControl adds a simple spinning loader-icon which automatically appears whenever there's
67 | an ongoing routing-request.
68 |
62 | Instead of aborting routing-requests manually, you can set the requestTimeout configuration option to a
63 | number of ms that a routing-request is allowed to take before getting automatically aborted.
64 |
This example makes POST requests to the official Mapbox Directions API with the following options:
71 | 72 |76 | In this example the default layers used by the plugin are augmented with an additional "symbol" layer which is only 77 | rendered for the ORIGIN and DESTINATION waypoints. 78 |
79 | 80 |
81 | Note how you don't need to re-define all the layers from scratch thanks to the exported
82 | layersFactory function that returns all the default layers allowing for their augmentation and modification
83 |
Another example that demonstrates the ease of extending the original styles provided by the plugin.
73 | 74 |This time a "symbol" layer is added that shows the direction the selected route goes in.
75 | 76 | Note that you have to manually load and add the images you intend to use for the custom layers you 78 | add 80 |66 | Sometimes it's pretty hard to aim exactly at the selected route line to add a waypoint by dragging it when using the 67 | plugin on a touch device. 68 |
69 | 70 |
71 | The example shows how one could use the layersFactory's input parameters to handle that case by
72 | increasing the points by 1.5 and the lines by 2 times when the map is used on a touch-enabled device.
73 |
54 | Total Route Distance: 55 | {#if totalDistance} 56 | {totalDistance}m 57 | {:else} 58 | unknown 59 | {/if} 60 |
61 | 62 | Note that you might want to zoom in and out the map to toggle the distance-annotations visibility 65 | 66 |67 | This is an example of how one could use the plugin's extensibility interfaces to create a distance measurement tool 68 | out of it. 69 |
70 | 71 |
72 | Here we create a subclass of the MapLibreGlDirections main super class and augment the original
73 | buildRoutelines
74 | method to write each route leg's distance into a respective feature's properties object. These saved distances
75 | are then used by an additional "symbol" layer that displays them along the respective route's lines on the map.
76 |
79 | The total distance comes from the response's specific field and is updated each time there's the "fetchroutesend" or 80 | the "removewaypoint" event fired. 81 |
82 |Set waypoints to a predefined set
85 | 86 |Add a random waypoint at some random index
90 | 91 |Delete a random waypoint
95 | 96 |Clear the map from all the stuff added by the plugin
100 | 101 |localStorage to save routes, but you are obviously not restricted to it. There might
71 | instead be a file or a serverside-database or whatever else
73 |
74 | 75 | If you want to save/load the route, the obvious way to do so would be to save the list of waypoints whenever the 76 | route is updated and to make a new routing-request with the saved waypoints' coordinates whenever you need to load 77 | it. 78 |
79 | 80 |81 | But what if the underlying roads networks changes for some reason? You'll get a different route for the same set of 82 | waypoints. Moreover, if there are some severe construction works going on, you run into a risk of not getting any 83 | routes whatsoever. 84 |
85 | 86 |87 | Sometimes it's actually a good idea to save the route as a list of GeoJSON Features and be able to load these saved 88 | features whenever there's a need. This example shows how that could be done. 89 |
90 |{message}
84 | {/if} 85 | 86 | 90 | 91 | 95 | 96 | 100 | 101 | 105 | 106 |90 | It's completely up to you how to style the Directions' features shown on the map. You can either use the default 91 | styles provided by the plugin (see other examples), easily modify the default features' dimensions (see the 92 | Touch-Friendly Features example) or 93 | define your custom features' styles from scratch. 94 |
95 | 96 |This example demonstrates the last option.
97 |88 | This example showcases routing with multiple profiles. Segments corresponding to different profiles are displayed in 89 | different colors. Plugin provides default styles for typical OSRM profiles: car, bike, foot. Styles can be changed per profile via general style customization approach (consult the 93 | Restyling example). In case different profiles are used you can similarly 94 | style map features corresponding to each profile by targeting profile property of a feature (see 95 | default styles). 98 |
99 | 100 | Note that interactivity is not supported for multiple profiles 101 | 102 |Used profiles:
103 |73 | The bearings support 74 | allows to control in which direction the route would be continued from a given waypoint. 75 |
76 | 77 |
78 | In order to enable support for this API option on the plugin level, pass the bearings: true option to
79 | the plugin's configuration object. When this is done, each request would contain the bearings field. The
80 | problem with that is that the values for the waypoints' bearings are not populated correctly since we need some way to
81 | assign these bearings values to our waypoints.
82 |
Luckily, that's possible to achieve using the built-in Bearings Control.
85 | 86 | 90 | 91 | 95 | 96 | 100 | 101 | 105 | 106 | 110 | 111 | 115 | 116 | 120 | 121 | 129 | 130 | 138 | 139 | 147 | 148 | 156 | 157 | 161 | 162 | 166 |139 | This example listens for all the available events and logs them below. Interact with the map to see the emitted 140 | events. 141 |
142 | 143 | 147 | 148 | {#if preventDefault} 149 | 153 | {/if} 154 | 155 | 156 | While the "Prevent Default" checkbox above is selected, all the subsequent cancelable events will have their default 157 | behavior prevented by calling the event'spreventDefault() method. Such events will be displayed below
158 | as a strikethrough text.
159 |
160 | {#if preventDefault}
161 | Checking the "Force-allow adding waypoints" will make adding waypoints ignore its
162 | preventDefault() invocations
163 | {/if}
164 |
165 |
166 | {#if messages.length}
167 |
168 | {/if}
169 |
170 |