forked from italia/design-react-kit
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {Map, TileLayer} from 'react-leaflet'; | ||
export { | ||
LayersControl, | ||
MapLayer, | ||
GridLayer, | ||
WMSTileLayer, | ||
ImageOverlay, | ||
LayerGroup, | ||
Marker, | ||
Path, | ||
Circle, | ||
CircleMarker, | ||
FeatureGroup, | ||
GeoJSON, | ||
Polygon, | ||
Polyline, | ||
Rectangle, | ||
Popup, | ||
Tooltip, | ||
} from 'react-leaflet'; | ||
|
||
class OSMap extends React.Component { | ||
state = { | ||
isLoaded: false, | ||
}; | ||
componentDidMount() { | ||
this.setState({loaded: true}); | ||
} | ||
|
||
render() { | ||
// Avoid to load Leaflet on SSR or in NodeJS | ||
if (!this.state.loaded) { | ||
return null; | ||
} | ||
|
||
const {children, height, ...rest} = this.props; | ||
|
||
return ( | ||
<Map {...rest} style={{height: `${height}px`}}> | ||
<TileLayer | ||
attribution="&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors" | ||
url="http://{s}.tile.osm.org/{z}/{x}/{y}.png" | ||
/> | ||
{children} | ||
</Map> | ||
); | ||
} | ||
} | ||
|
||
OSMap.propTypes = { | ||
children: PropTypes.node, | ||
height: PropTypes.number, | ||
}; | ||
|
||
export default OSMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react'; | ||
import {storiesOf} from '@storybook/react'; | ||
import {withInfo} from '@storybook/addon-info'; | ||
import {Map, TileLayer, Marker, Popup} from 'react-leaflet'; | ||
import L from 'leaflet'; | ||
|
||
const position = [41.9, 12.49]; | ||
const icon = L.divIcon({ | ||
html: | ||
'<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>', | ||
}); | ||
|
||
const NiceMap = ({attribution, tilesUrl}) => ( | ||
<Map center={position} zoom={10} style={{height: 500}}> | ||
<TileLayer attribution={attribution} url={tilesUrl} /> | ||
<Marker position={position} icon={icon}> | ||
<Popup> | ||
<span> | ||
I'm here and I'm a component.<br /> With OpenStreet Map | ||
tiles. | ||
</span> | ||
</Popup> | ||
</Marker> | ||
</Map> | ||
); | ||
|
||
storiesOf('Map', module) | ||
.add( | ||
'OpenStreet Layer', | ||
withInfo('OpenStreet Layer')(() => ( | ||
<NiceMap | ||
tilesUrl={'http://{s}.tile.osm.org/{z}/{x}/{y}.png'} | ||
attribution={ | ||
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
} | ||
/> | ||
)) | ||
) | ||
.add( | ||
'Stamen.Toner', | ||
withInfo('Stamen.Toner')(() => ( | ||
<NiceMap | ||
attribution={ | ||
'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>' | ||
} | ||
tilesUrl={ | ||
'https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png' | ||
} | ||
/> | ||
)) | ||
) | ||
.add( | ||
'CartoDB Positron', | ||
withInfo('CartoDB Positron')(() => ( | ||
<NiceMap | ||
attribution={ | ||
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>' | ||
} | ||
tilesUrl={ | ||
'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png' | ||
} | ||
/> | ||
)) | ||
) | ||
.add( | ||
'Stamen Watercolor', | ||
withInfo('Stamen Watercolor')(() => ( | ||
<NiceMap | ||
attribution={ | ||
'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>' | ||
} | ||
tilesUrl={ | ||
'https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png' | ||
} | ||
/> | ||
)) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
@import './styles/build.css'; | ||
@import '~leaflet/dist/leaflet.css'; | ||
@import './styles/build.css'; | ||
|
||
.leaflet-container { | ||
width: 100%; | ||
} |