glcvdv-lite-api-map
Version:
A lightweight API for interactive hotel maps with Mapbox integration
41 lines • 1.24 kB
JavaScript
export const setupHotelSource = (map, hotels, options) => {
const addSourceOptions = {
type: 'geojson',
generateId: true,
cluster: true,
clusterMaxZoom: 14,
clusterRadius: 50,
data: {
type: 'FeatureCollection',
features: hotels.map((hotel) => ({
type: 'Feature',
properties: {
...hotel
},
geometry: {
type: 'Point',
coordinates: [hotel.coordinates.lng, hotel.coordinates.lat]
}
}))
}
};
const existingSource = map.getSource('hotels');
if (existingSource) {
existingSource.setData(addSourceOptions.data);
}
else {
map.addSource('hotels', addSourceOptions);
map.addLayer({
'id': 'hotels',
'source': 'hotels',
'type': 'circle',
'paint': {
'circle-color': options.markerColor || '#4264fb',
'circle-radius': 10,
'circle-stroke-width': 2,
'circle-stroke-color': '#ffffff'
}
});
}
};
//# sourceMappingURL=setup-hotel-source.js.map