mapboxgl.accessToken = 'pk.eyJ1IjoiY2FtcGluZ3VzYSIsImEiOiJjandpMWsyNGkwMjY2NDNueHZhZ3Z0b21xIn0.hQKb9hCnbSKYutgkALutZQ'; const map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/campingusa/cjwih2cn85etj1co7ln44sr3z', center: [-97.154, 37.764], zoom: 3.5 });
map.on('click', function(e) { var features = map.queryRenderedFeatures(e.point, { layers: ['all-campgrounds'] // replace this with the name of the layer });
if (!features.length) { return; }
var feature = features[0];
var popup = new mapboxgl.Popup({ offset: [0, -15] }) .setLngLat(feature.geometry.coordinates) .setHTML('
' + feature.properties.name + '
' + '
' + feature.properties.type + '
') .setLngLat(feature.geometry.coordinates) .addTo(map); });
map.addControl(new mapboxgl.NavigationControl());