Skip to content

Instantly share code, notes, and snippets.

@tristen
Created February 7, 2017 20:53
Show Gist options
  • Save tristen/3a433a1c7fb4bc0b01031a88ba5961da to your computer and use it in GitHub Desktop.
Save tristen/3a433a1c7fb4bc0b01031a88ba5961da to your computer and use it in GitHub Desktop.
Remove a marker
<!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.32.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.css' rel='stylesheet' />
<link href='https://api.mapbox.com/mapbox-assembly/v0.6.0/assembly.min.css' rel='stylesheet'>
<script async defer src='https://api.mapbox.com/mapbox-assembly/v0.6.0/assembly.js'></script>
<style>
.marker {
background-color:#F86767;
width:40px;
height:40px;
border-radius:50%;
box-shadow:0 0 2px rgba(0,0,0,0.25);
border:3px solid #fff;
cursor:pointer;
}
</style>
</head>
<body>
<div id='map' class='bg-darken10 viewport-twothirds viewport-full-ml absolute top left right bottom'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoidHJpc3RlbiIsImEiOiJiUzBYOEJzIn0.VyXs9qNWgTfABLzSI3YcrQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-74.50, 40],
zoom: 9
});
var markerEl = document.createElement('div');
markerEl.className = 'marker';
var marker = new mapboxgl.Marker(markerEl, {
offset: [-20, -20]
});
markerEl.addEventListener('click', function() {
marker.remove();
});
marker.setLngLat([-74.50, 40]).addTo(map);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment