import React from 'react'; import { Portal } from 'react-portal'; class MapEvents extends React.Component { projectPoint(location) { const latLng = new L.LatLng(location[0], location[1]); return { x: this.props.map.latLngToLayerPoint(latLng).x + this.props.mapTransformX, y: this.props.map.latLngToLayerPoint(latLng).y + this.props.mapTransformY }; } getLocationEventsDistribution(location) { const eventCount = {}; const categories = this.props.categories; categories.forEach(cat => { eventCount[cat.category] = []; }); location.events.forEach((event) => {; eventCount[event.category].push(event); }); return eventCount; } renderCategory(events, category) { return ( this.props.onSelect(events)} > ); } renderLocation(location) { const { x, y } = this.projectPoint([location.latitude, location.longitude]); const eventsByCategory = this.getLocationEventsDistribution(location); return ( {Object.keys(eventsByCategory).map(cat => { return this.renderCategory(eventsByCategory[cat], cat) })} ) } render() { return ( {this.props.locations.map(loc => this.renderLocation(loc))} ); } } export default MapEvents;