Skip to content

Instantly share code, notes, and snippets.

@ryanbaumann
Forked from andrewharvey/index.html
Last active August 25, 2016 16:52
Show Gist options
  • Save ryanbaumann/02e50339378a73734aae05fbeb373f5f to your computer and use it in GitHub Desktop.
Save ryanbaumann/02e50339378a73734aae05fbeb373f5f to your computer and use it in GitHub Desktop.
Mapbox GL JS Marker Offset Example
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.22.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.22.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxhbnRnZW8tcHJlc2FsZXMiLCJhIjoiY2lweHA5bTN6MHdpMGZvbTI2ZjU3bHQycSJ9.6Co8WMXUf6EYDj7eRzf-gw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [151.20665426363286, -33.85372532383168],
zoom: 19
});
var img = document.createElement('img');
img.src = 'marker.png';
img.style.width = '100px';
img.style.height = '142px';
var marker = new mapboxgl.Marker(img, {
offset: {
x: -50,
y: -142
}
})
.setLngLat([151.20665426363286, -33.85372532383168])
.addTo(map);
var img2 = document.createElement('img');
img2.src = 'marker.png';
img2.style.width = '100px';
img2.style.height = '142px';
var marker2 = new mapboxgl.Marker(img2, {
offset: [-50, -142]
})
.setLngLat([151.20555818080902, -33.85412098182466])
.addTo(map);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment