Возможное решение состоит в том, чтобы добавить этот необходимый слой .. как этот
Я немного изменил ваш код, чтобы сгенерировать похожий объект слоя, как показано в примере из документов
map.on("load", function() {
const starImage = '<img class="star-image" style="height:20px;width:20px;">';
const layer = {
"id": "places",
"type": "symbol",
"layout": {
"icon-image": "{icon}-15",
"icon-allow-overlap": true
},
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": json.map(function(item){
return {
"type": "Feature",
"properties": {
"description": `<div class="map-card__wrapper">
<div class="map-card__image-container">
<div class="map-card__image" style="background: url(${item.pictures[0].url});"></div>
</div>
<div class ="map-card__content-container ">
<div class ="map-card__title">${item.name}</div>
<p class="map-card__address">${item.address1}</p>
<div class ="map-card__review">${starImage.repeat(item.rating)}</div>
</div>
</div>`,
"icon": "star" //probably want to change
},
"geometry": {
"type": "Point",
"coordinates": [item.lng, item.lat]
}
}
})
}
}
};
map.addLayer(layer);
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false,
offset: 5
});
map.on('mouseenter', 'places', function(e) {
console.log(e)
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
var coordinates = e.features[0].geometry.coordinates.slice();
var description = e.features[0].properties.description;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
map.on('mouseleave', 'places', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});
});