Skip to content

Commit fb33bcc

Browse files
author
Savina Shen (Manpower Services Taiwan Co Ltd)
committed
add tile layer example
1 parent 573515c commit fb33bcc

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Source, Meta } from '@storybook/blocks';
2+
3+
import TileLayer from './TileLayer';
4+
5+
<Meta title="Tile Layer"/>
6+
7+
# Tile Layer
8+
9+
Tile layers allow you to superimpose images on top of Azure Maps base map tiles.
10+
Following code shows how to add a simple tile layer. A thorough tutorial can be found [here](https://learn.microsoft.com/en-us/azure/azure-maps/map-add-tile-layer)<br/>
11+
For more available properties, see the documentation [TileLayerOptions](https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas.tilelayeroptions?view=azure-maps-typescript-latest)
12+
13+
<TileLayer/>
14+
15+
<Source code={`
16+
<AzureMapLayerProvider
17+
type="TileLayer"
18+
options={{
19+
tileUrl: 'path/to/tile',
20+
tileSize: 256,
21+
}}
22+
/>
23+
`}/>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import TileLayer from './TileLayer';
3+
4+
const meta: Meta<typeof TileLayer> = {
5+
title: 'Tile Layer',
6+
component: TileLayer,
7+
parameters: {
8+
storySource: {
9+
source: `
10+
import { AzureMap, AzureMapsProvider, AzureMapDataSourceProvider, AzureMapLayerProvider } from 'react-azure-maps';
11+
12+
const TileLayer = () => {
13+
14+
return (
15+
<AzureMapsProvider>
16+
<div className="defaultMap">
17+
<AzureMap options={{ ...your_options, style: 'night' }}>
18+
<AzureMapDataSourceProvider id="TileLayer DataSourceProvider">
19+
<AzureMapLayerProvider
20+
type="TileLayer"
21+
options={{
22+
tileUrl:
23+
'https://mrdata.usgs.gov/services/gscworld?FORMAT=image/png&HEIGHT=1024&LAYERS=geology&REQUEST=GetMap&STYLES=default&TILED=true&TRANSPARENT=true&WIDTH=1024&VERSION=1.3.0&SERVICE=WMS&CRS=EPSG:3857&BBOX={bbox-epsg-3857}',
24+
bounds: [-50, -20, 50, 20], //[west, south, east, north]
25+
tileSize: 50,
26+
}}
27+
/>
28+
</AzureMapDataSourceProvider>
29+
</AzureMap>
30+
</div>
31+
</AzureMapsProvider>
32+
);
33+
};
34+
35+
export default TileLayer;
36+
37+
`,
38+
},
39+
},
40+
args: {
41+
bounds: [-50, -20, 50, 20],
42+
tileSize: 50,
43+
},
44+
};
45+
export default meta;
46+
47+
type Story = StoryObj<typeof TileLayer>;
48+
export const Example: Story = {};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { mapOptions } from '../../key';
2+
import { AzureMap, AzureMapsProvider, AzureMapDataSourceProvider, AzureMapLayerProvider } from 'react-azure-maps';
3+
import { TileLayerOptions } from 'azure-maps-control';
4+
5+
const TileLayer = ({ bounds = [-50, -20, 50, 20], tileSize = 50 }: TileLayerOptions) => {
6+
return (
7+
<AzureMapsProvider>
8+
<div className="defaultMap sb-unstyled">
9+
<AzureMap options={{ ...mapOptions, style: 'night' }}>
10+
<AzureMapDataSourceProvider id="TileLayer DataSourceProvider">
11+
<AzureMapLayerProvider
12+
type="TileLayer"
13+
options={{
14+
tileUrl:
15+
'https://mrdata.usgs.gov/services/gscworld?FORMAT=image/png&HEIGHT=1024&LAYERS=geology&REQUEST=GetMap&STYLES=default&TILED=true&TRANSPARENT=true&WIDTH=1024&VERSION=1.3.0&SERVICE=WMS&CRS=EPSG:3857&BBOX={bbox-epsg-3857}',
16+
bounds, //[west, south, east, north]
17+
tileSize,
18+
}}
19+
/>
20+
</AzureMapDataSourceProvider>
21+
</AzureMap>
22+
</div>
23+
</AzureMapsProvider>
24+
);
25+
};
26+
27+
export default TileLayer;

0 commit comments

Comments
 (0)