Implements Custom Tile Layer

#1121 adds default tile layer and allows user to pass a tile object to map
This commit is contained in:
William Lima 2024-05-13 12:51:28 -01:00
parent a4e60540ae
commit a6047a9341
2 changed files with 18 additions and 4 deletions

View File

@ -14,6 +14,11 @@ import 'leaflet/dist/leaflet.css';
import * as L from 'leaflet'; import * as L from 'leaflet';
export type MapProps = { export type MapProps = {
tile?: {
attribution?: string;
url: string;
data?: any;
};
layers: { layers: {
data: GeospatialData; data: GeospatialData;
name: string; name: string;
@ -37,6 +42,11 @@ export type MapProps = {
}; };
export function Map({ export function Map({
tile = {
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
},
layers = [ layers = [
{ {
data: null, data: null,
@ -144,10 +154,7 @@ export function Map({
map.target.fitBounds(layerToZoomBounds); map.target.fitBounds(layerToZoomBounds);
}} }}
> >
<TileLayer <TileLayer url={tile.url} attribution={tile.attribution} {...tile.data} />
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<LayersControl position="bottomright"> <LayersControl position="bottomright">
{layers.map((layer) => { {layers.map((layer) => {
const data = layersData.find( const data = layersData.find(

View File

@ -43,6 +43,13 @@ type Story = StoryObj<MapProps>;
export const GeoJSONPolygons: Story = { export const GeoJSONPolygons: Story = {
name: 'GeoJSON polygons map', name: 'GeoJSON polygons map',
args: { args: {
tile : {
url : 'https://tiles.stadiamaps.com/tiles/alidade_satellite/{z}/{x}/{y}{r}.{ext}',
attribution:'&copy; CNES, Distribution Airbus DS, © Airbus DS, © PlanetObserver (Contains Copernicus Data) | &copy; <a href="https://www.stadiamaps.com/" target="_blank">Stadia Maps</a> &copy; <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
data: {
ext: 'jpg'
}
},
layers: [ layers: [
{ {
data: { data: {