|
| 1 | +import React from 'react'; |
| 2 | +import {storiesOf} from '@storybook/react'; |
| 3 | +import {withInfo} from '@storybook/addon-info'; |
| 4 | +import {Map, TileLayer, Marker, Popup} from 'react-leaflet'; |
| 5 | +import L from 'leaflet'; |
| 6 | + |
| 7 | +const position = [41.9, 12.49]; |
| 8 | +const icon = L.divIcon({ |
| 9 | + html: |
| 10 | + '<div style="background: blue; width: 55px; padding-left: 2px;"><img src="https://italia.github.io/design-web-toolkit/theme/docs/logo-it.svg" height="42" width="42"/></div>', |
| 11 | +}); |
| 12 | + |
| 13 | +const NiceMap = ({attribution, tilesUrl}) => ( |
| 14 | + <Map center={position} zoom={10} style={{height: 500}}> |
| 15 | + <TileLayer attribution={attribution} url={tilesUrl} /> |
| 16 | + <Marker position={position} icon={icon}> |
| 17 | + <Popup> |
| 18 | + <span> |
| 19 | + I'm here and I'm a component.<br /> With OpenStreet Map |
| 20 | + tiles. |
| 21 | + </span> |
| 22 | + </Popup> |
| 23 | + </Marker> |
| 24 | + </Map> |
| 25 | +); |
| 26 | + |
| 27 | +storiesOf('Map', module) |
| 28 | + .add( |
| 29 | + 'OpenStreet Layer', |
| 30 | + withInfo('OpenStreet Layer')(() => ( |
| 31 | + <NiceMap |
| 32 | + tilesUrl={'http://{s}.tile.osm.org/{z}/{x}/{y}.png'} |
| 33 | + attribution={ |
| 34 | + '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' |
| 35 | + } |
| 36 | + /> |
| 37 | + )) |
| 38 | + ) |
| 39 | + .add( |
| 40 | + 'Stamen.Toner', |
| 41 | + withInfo('Stamen.Toner')(() => ( |
| 42 | + <NiceMap |
| 43 | + attribution={ |
| 44 | + 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' |
| 45 | + } |
| 46 | + tilesUrl={ |
| 47 | + 'https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png' |
| 48 | + } |
| 49 | + /> |
| 50 | + )) |
| 51 | + ) |
| 52 | + .add( |
| 53 | + 'CartoDB Positron', |
| 54 | + withInfo('CartoDB Positron')(() => ( |
| 55 | + <NiceMap |
| 56 | + attribution={ |
| 57 | + '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>' |
| 58 | + } |
| 59 | + tilesUrl={ |
| 60 | + 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png' |
| 61 | + } |
| 62 | + /> |
| 63 | + )) |
| 64 | + ) |
| 65 | + .add( |
| 66 | + 'Stamen Watercolor', |
| 67 | + withInfo('Stamen Watercolor')(() => ( |
| 68 | + <NiceMap |
| 69 | + attribution={ |
| 70 | + 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' |
| 71 | + } |
| 72 | + tilesUrl={ |
| 73 | + 'https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png' |
| 74 | + } |
| 75 | + /> |
| 76 | + )) |
| 77 | + ); |
0 commit comments