93 lines
2.7 KiB
HTML
93 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Pop-ups with embed video | CARTO</title>
|
|
<meta name="viewport" content="initial-scale=1.0">
|
|
<meta charset="utf-8">
|
|
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,600,700|Open+Sans:300,400,600" rel="stylesheet">
|
|
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
|
|
<!-- Include Leaflet -->
|
|
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
|
<link href="https://unpkg.com/leaflet/dist/leaflet.css" rel="stylesheet">
|
|
<!-- Include CARTO.js -->
|
|
<script src="../../../dist/public/carto.js"></script>
|
|
<link href="../style.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<div id="map"></div>
|
|
<aside class="toolbox">
|
|
<div class="box">
|
|
<header>
|
|
<h1>Pop-Ups with embed video</h1>
|
|
<button class="github-logo js-source-link"></button>
|
|
</header>
|
|
<section>
|
|
<p class="description open-sans">Create pop-up information windows with embed videos.</p>
|
|
|
|
</section>
|
|
<footer class="js-footer"></footer>
|
|
</div>
|
|
</aside>
|
|
|
|
<script>
|
|
const map = L.map('map').setView([0, 0], 5);
|
|
map.scrollWheelZoom.disable();
|
|
|
|
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png', {
|
|
maxZoom: 18
|
|
}).addTo(map);
|
|
|
|
const client = new carto.Client({
|
|
apiKey: 'default_public',
|
|
username: 'cartojs-test'
|
|
});
|
|
|
|
const cartoSource = new carto.source.Dataset(`
|
|
example_video
|
|
`);
|
|
const cartoStyle = new carto.style.CartoCSS(`
|
|
#layer {
|
|
marker-width: 20;
|
|
marker-fill: #EE4D5A;
|
|
marker-line-color: #FFFFFF;
|
|
}
|
|
`);
|
|
const cartoLayer = new carto.layer.Layer(cartoSource, cartoStyle, {
|
|
featureClickColumns: ['youtube_url']
|
|
});
|
|
|
|
client.addLayer(cartoLayer);
|
|
client.getLeafletLayer().addTo(map);
|
|
|
|
const popup = L.popup({ closeButton: false });
|
|
|
|
function openPopup(featureEvent) {
|
|
let content = '<div class="widget">';
|
|
|
|
if (featureEvent.data.youtube_url) {
|
|
content += `<iframe width="240" src= ${featureEvent.data.youtube_url} frameborder="0" allowfullscreen></iframe>`
|
|
}
|
|
|
|
content += `</div>`;
|
|
|
|
popup.setContent(content);
|
|
popup.setLatLng(featureEvent.latLng);
|
|
|
|
if (!popup.isOpen()) {
|
|
popup.openOn(map);
|
|
}
|
|
}
|
|
|
|
function closePopUp(featureEvent) {
|
|
// remove popup from map object
|
|
popup.removeFrom(map)
|
|
}
|
|
|
|
|
|
cartoLayer.on('featureClicked', openPopup);
|
|
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|