Embed Soundcloud clip
Embed a Soundcloud clip with an iframe.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Embed Soundcloud clip</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.3.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.3.1/mapbox.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>
L.mapbox.accessToken = '<your access token here>';
var map = L.mapbox.map('map')
.addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));
// The GeoJSON representing a point feature with a property of 'sounds'
var geoJson = {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: {
title: 'Friendly Fires - Paris (Aeroplane Remix Feat. Au Revoir Simone)',
'marker-color': '#f00',
'marker-size': 'large',
'marker-symbol': 'star',
url: 'http://en.wikipedia.org/wiki/Paris',
sounds: '<iframe width="100%" height="300" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/34849808&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true"></iframe>'
},
geometry: {
type: 'Point',
coordinates: [2.3486709594726562,48.85703523304221]
}
}]
};
var myLayer = L.mapbox.featureLayer().addTo(map);
// Add the iframe in a custom popup using the custom feature properties
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
// Create custom popup content
var popupContent = '<a target="_blank" class="popup" href="' +
feature.properties.url + '">' +
feature.properties.sounds +
'<h2>' + feature.properties.title + '</h2>' + '</a>';
// http://leafletjs.com/reference.html#popup
marker.bindPopup(popupContent,{
closeButton: false,
minWidth: 320
});
});
// Add features to the map
myLayer.setGeoJSON(geoJson);
map.setView([48.85703523304221,2.3486709594726562], 12);
</script>
Get a free Mapbox account to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and
replacing the Map ID
with
one of your own from your projects.
Having trouble with JavaScript? Try out Codecademy
or contact our support team.