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({
|
2019-01-07 23:11:09 +03:00
|
|
|
cityName: PropTypes.string.isRequired,
|
2019-01-07 23:00:28 +03:00
|
|
|
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 />
|
2019-01-07 23:11:09 +03:00
|
|
|
{locations.map(({ cityName, latLong, count }, index) => (
|
2019-01-07 23:00:28 +03:00
|
|
|
<Marker key={index} position={latLong}>
|
2019-01-07 23:11:09 +03:00
|
|
|
<Popup><b>{count}</b> visit{count > 1 ? 's' : ''} from <b>{cityName}</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;
|