mirror of
https://github.com/visgl/react-map-gl.git
synced 2026-01-25 16:02:50 +00:00
- Add geojson example - Add introduction, credit and link to source to all examples - CSS bug fixes - Remove unused website components - Header image
80 lines
1.8 KiB
JavaScript
80 lines
1.8 KiB
JavaScript
/* global window */
|
|
import React, {Component} from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import {connect} from 'react-redux';
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import MarkdownPage from './markdown-page';
|
|
import {loadContent, updateMap} from '../actions/app-actions';
|
|
|
|
class Page extends Component {
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
mapHasFocus: true,
|
|
content: this._loadContent(props.route.content)
|
|
};
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
const {route} = nextProps;
|
|
if (this.props.route !== route) {
|
|
this.setState({
|
|
content: this._loadContent(route.content)
|
|
});
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
window.onresize = null;
|
|
}
|
|
|
|
_loadContent(content) {
|
|
if (typeof content === 'string') {
|
|
this.props.loadContent(content);
|
|
}
|
|
return content;
|
|
}
|
|
|
|
// replaces the current query string in react-router
|
|
@autobind _updateQueryString(queryString) {
|
|
const {location: {pathname, search}} = this.props;
|
|
if (search !== queryString) {
|
|
this.context.router.replace({
|
|
pathname,
|
|
search: queryString
|
|
});
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const {contents, location: {query}} = this.props;
|
|
const {content} = this.state;
|
|
|
|
let child;
|
|
|
|
if (content.demo) {
|
|
child = this._renderDemo(content.demo, content.code);
|
|
} else if (typeof content === 'string') {
|
|
child = (<MarkdownPage content={contents[content]}
|
|
query={query}
|
|
updateQueryString={this._updateQueryString} />);
|
|
}
|
|
|
|
return <div className="page">{child}</div>;
|
|
}
|
|
}
|
|
|
|
Page.contextTypes = {
|
|
router: PropTypes.object
|
|
};
|
|
|
|
function mapStateToProps(state) {
|
|
return {
|
|
contents: state.contents
|
|
};
|
|
}
|
|
|
|
export default connect(mapStateToProps, {loadContent, updateMap})(Page);
|