I'm not very used to JavaScript, and I don't understand how to adapt my code to this tutorial : https://docs.mapbox.com/mapbox-gl-js/example/popup-on-hover/
Indeed, in my code, the text information is from a layer made in Mapbox studio :
<body>
<style>
.mapboxgl-popup {
max-width: 400px;
}
</style>
<div id='map' style='width: 100%; height: 100%;'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZm9hbHkiLCJhIjoiY2sydzNrbDdhMDMwNDNibGdreHZ3cDl///////';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles///////ck2xjgdxh2kxk1cp5s//////',
center: [1.85, 50.9575],
zoom: 14
});
map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, {
layers: ['test']
});
if (!features.length) {
return;
}
var feature = features[0];
var popup = new mapboxgl.Popup({ offset: [0, -7] })
.setLngLat(feature.geometry.coordinates)
.setHTML('<h3>' + feature.properties.title + '</h3><p>' + feature.properties.description + '</p>' + '<h3>' + feature.properties.title2 + '</h3><p>' + feature.properties.description2 + '</p>' )
.addTo(map);
});
map.on('mouseenter', 'test', function() {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'test', function() {
map.getCanvas().style.cursor = '';
});
</script>
</body>