2019-01-07 15:35:14 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { Modal, ModalBody, ModalHeader } from 'reactstrap';
|
|
|
|
import { Map, TileLayer, Marker, Popup } from 'react-leaflet';
|
|
|
|
import * as PropTypes from 'prop-types';
|
|
|
|
import './MapModal.scss';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
toggle: PropTypes.func,
|
|
|
|
isOpen: PropTypes.bool,
|
|
|
|
title: PropTypes.string,
|
2019-01-07 23:00:28 +03:00
|
|
|
locations: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
city: PropTypes.string.isRequired,
|
|
|
|
latLong: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
|
|
count: PropTypes.number.isRequired,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
const defaultProps = {
|
|
|
|
locations: [],
|
2019-01-07 15:35:14 +03:00
|
|
|
};
|
|
|
|
|
2019-01-07 23:00:28 +03:00
|
|
|
const OpenStreetMapTile = () => (
|
|
|
|
<TileLayer
|
|
|
|
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
|
|
|
/>
|
|
|
|
);
|
2019-01-07 15:35:14 +03:00
|
|
|
|
2019-01-07 23:00:28 +03:00
|
|
|
const MapModal = ({ toggle, isOpen, title, locations }) => (
|
|
|
|
<Modal toggle={toggle} isOpen={isOpen} className="map-modal__modal" contentClassName="map-modal__modal-content">
|
|
|
|
<ModalHeader toggle={toggle}>{title}</ModalHeader>
|
|
|
|
<ModalBody className="map-modal__modal-body">
|
|
|
|
<Map center={[ 0, 0 ]} zoom="3">
|
|
|
|
<OpenStreetMapTile />
|
|
|
|
{locations.map(({ city, latLong, count }, index) => (
|
|
|
|
<Marker key={index} position={latLong}>
|
|
|
|
<Popup><b>{count}</b> visit{count > 1 ? 's' : ''} from <b>{city}</b></Popup>
|
2019-01-07 21:43:25 +03:00
|
|
|
</Marker>
|
2019-01-07 23:00:28 +03:00
|
|
|
))}
|
|
|
|
</Map>
|
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
|
|
|
);
|
2019-01-07 15:35:14 +03:00
|
|
|
|
|
|
|
MapModal.propTypes = propTypes;
|
2019-01-07 23:00:28 +03:00
|
|
|
MapModal.defaultProps = defaultProps;
|
2019-01-07 15:35:14 +03:00
|
|
|
|
|
|
|
export default MapModal;
|