Route Styling
When a routing layer is constructed, the default route color, origin, destination, and stop icons will be used whenrouteColor
, originIcon
, destinationIcon
, stopIcon
route options are not provided. To change these default route properties, either supply custom a color and icons when constructing a layer or use the update
function after a layer is created.
Requires Trimble Maps v3.1.0 or later.
x
67
1
2
<html lang="en">
3
<head>
4
<meta charset="utf-8" />
5
<link rel="stylesheet" href="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.css" />
6
<script src="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.js"></script>
7
<style>
8
body { margin: 0; padding: 0; }
9
10
#map {
11
position: absolute;
12
top: 0;
13
bottom: 0;
14
width: 100%;
15
}
16
17
</style>
18
</head>
19
<body>
20
<div id="map"></div>
21
22
<script>
23
// Create a route with custom color, origin icon, destination icon, and stop icon.
24
// Update a route with custom color and icons after a layer is created.
25
TrimbleMaps.setAPIKey('YOUR_API_KEY_HERE');
26
const map = new TrimbleMaps.Map({
27
container: 'map',
28
style: TrimbleMaps.Common.Style.TRANSPORTATION,
29
center: new TrimbleMaps.LngLat(-74.566234, 40.49944),
30
zoom: 8
31
});
32
const routeOptions = {
33
routeId: 'myRoute',
34
stops: [
35
new TrimbleMaps.LngLat(-74.566234, 40.49944),
36
new TrimbleMaps.LngLat(-74.528512, 40.386680),
37
new TrimbleMaps.LngLat(-74.629749, 40.26118)
38
],
39
routeColor: '#888888', // optional routeColor
40
originIcon: { // optional origin Icon
41
size: 1,
42
url: 'https://developer.trimblemaps.com/maps-sdk/img/marker_blue.png',
43
offset: [0, -6]
44
},
45
stopIcon: { // optional stop icon
46
size: 1,
47
url: 'https://developer.trimblemaps.com/maps-sdk/img/marker_blue.png',
48
offset: [0, -6]
49
}
50
};
51
const myRoute = new TrimbleMaps.Route(routeOptions);
52
map.on('load', function() {
53
myRoute.addTo(map);
54
setTimeout(function() {
55
routeOptions.routeColor = '#00ff00'; // update route color
56
routeOptions.destinationIcon = { // update destination icon
57
size: 1,
58
url: 'https://developer.trimblemaps.com/maps-sdk/img/marker_blue.png',
59
offset: [0, -6]
60
};
61
myRoute.update(routeOptions);
62
}, 8000);
63
});
64
</script>
65
</body>
66
</html>
67