Add Image
Add an icon to the map from an external URL and use it in a symbol layer. Requires Trimble Maps v3.0.0 or later.x
63
1
2
<html lang="en">
3
<head>
4
<meta charset="utf-8" />
5
<title>Add Image</title>
6
<meta name="viewport" content="width=device-width, initial-scale=1" />
7
<link rel="stylesheet" href="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.css" />
8
<script src="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.js"></script>
9
<style>
10
body {
11
margin: 0;
12
padding: 0;
13
}
14
html,
15
body,
16
#map {
17
height: 100%;
18
}
19
</style>
20
</head>
21
<body>
22
<div id="map"></div>
23
<script>
24
TrimbleMaps.setAPIKey('YOUR_API_KEY_HERE');
25
26
const map = new TrimbleMaps.Map({
27
container: 'map',
28
style: TrimbleMaps.Common.Style.TRANSPORTATION,
29
zoom: 2,
30
});
31
32
map.on('load', async () => {
33
image = await map.loadImage('https://upload.wikimedia.org/wikipedia/commons/7/7c/201408_cat.png');
34
map.addImage('cat', image.data);
35
map.addSource('point', {
36
'type': 'geojson',
37
'data': {
38
'type': 'FeatureCollection',
39
'features': [
40
{
41
'type': 'Feature',
42
'geometry': {
43
'type': 'Point',
44
'coordinates': [0, 0]
45
}
46
}
47
]
48
}
49
});
50
map.addLayer({
51
'id': 'points',
52
'type': 'symbol',
53
'source': 'point',
54
'layout': {
55
'icon-image': 'cat',
56
'icon-size': 0.25
57
}
58
});
59
});
60
</script>
61
</body>
62
</html>
63