feat: Add icon + make sure to fly to icon upon click

This commit is contained in:
moanos [he/him] 2024-09-27 13:07:43 +02:00
parent 9d5f2462e6
commit d66bb11695

View File

@ -12,7 +12,50 @@
container: 'map', container: 'map',
style: 'https://tiles.versatiles.org/assets/styles/colorful.json' style: 'https://tiles.versatiles.org/assets/styles/colorful.json'
}).addControl(new maplibregl.NavigationControl()); }).addControl(new maplibregl.NavigationControl());
const marker = new maplibregl.Marker()
.setLngLat([9.545, 48.105835]) map.on('load', async () => {
.addTo(map); image = await map.loadImage("{% static "fellchensammlung/img/logo_transparent.png" %}");
map.addImage('rat', image.data);
map.addSource('point', {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [9.545, 48.105835]
}
}
]
}
});
map.addLayer({
'id': 'points',
'type': 'symbol',
'source': 'point',
'layout': {
'icon-image': 'rat',
'icon-size': 0.1
}
});
// Center the map on the coordinates of any clicked symbol from the 'symbols' layer.
map.on('click', 'points', (e) => {
map.flyTo({
center: e.features[0].geometry.coordinates
});
});
// Change the cursor to a pointer when the it enters a feature in the 'symbols' layer.
map.on('mouseenter', 'symbols', () => {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'symbols', () => {
map.getCanvas().style.cursor = '';
});
});
</script> </script>