-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-marker.html
80 lines (62 loc) · 2.03 KB
/
custom-marker.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom marker</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v2.0.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.0.1/mapbox-gl.css' rel='stylesheet' />
<style>
html,
body {
margin: 0;
}
#map-container {
width: min(100vw, 800px);
height: min(80vw, 500px);
}
.restaurant-marker.mapboxgl-marker {
background-color: #3FB1CF;
background-image: url(https://www.gstatic.com/images/icons/material/system_gm/2x/restaurant_black_18dp.png);
background-position: center;
background-repeat: no-repeat;
background-size: 16px;
border: 4px solid #FFF;
box-shadow: 0 1px 2px 1px rgb(0 0 0 / 10%);
animation: pulse_shadow 2.3s ease-out infinite;
border-radius: 500%;
box-sizing: border-box;
width: 34px;
height: 34px;
}
@keyframes pulse_shadow {
0% { box-shadow: 0 0 0 0 rgb(63 177 207 / 90%); }
100% { box-shadow: 0 0 0 25px rgb(63 177 207 / 0%); }
}
</style>
</head>
<body>
<div id="map-container"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiaWFnb2JydW5vIiwiYSI6ImNram41cDI1bjBhYWEyeXFscGp5ZG15bnAifQ.kGQsH0C6Li7MwXrOWr1Qmw';
const carnaubalLatLng = new mapboxgl.LngLat(-40.941498, -4.162548);
// Init map
const map = new mapboxgl.Map({
container: document.getElementById('map-container'),
center: carnaubalLatLng, // starting position [lng, lat]
zoom: 16.5, // starting zoom
style: 'mapbox://styles/mapbox/streets-v11', // stylesheet location
});
map.on('load', () => {
showRestaurantMarker(carnaubalLatLng);
});
function showRestaurantMarker(lngLat) {
const el = document.createElement('div');
el.classList.add('restaurant-marker');
new mapboxgl.Marker(el)
.setLngLat(carnaubalLatLng)
.addTo(map);
}
</script>
</body>
</html>