So I am trying to make a link and for this specific link i need the markers id but I cant figure out why all properties of the marker are defined but the id isn't. When I write marker.id it will output undefined.
import mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
const initMapbox = () => {
const mapElement = document.getElementById('map');
const fitMapToMarkers = (map, markers) => {
const bounds = new mapboxgl.LngLatBounds();
markers.forEach(marker => bounds.extend([marker.lng, marker.lat]));
map.fitBounds(bounds, { padding: 70, maxZoom: 15, duration: 0 });
};
if (mapElement) {
mapboxgl.accessToken = mapElement.dataset.mapboxApiKey;
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v10'
});
const markers = JSON.parse(mapElement.dataset.markers);
markers.forEach((marker) => {
const popup = new mapboxgl.Popup().setHTML(`
<h6>${marker.name}</h6>
<p>${marker.price}£/month</p>
<h6>${marker.id}</h6>
`);
new mapboxgl.Marker()
.setLngLat([marker.lng, marker.lat])
.setPopup(popup)
.addTo(map);
});
fitMapToMarkers(map, markers);
}
};
export { initMapbox };