import React from 'react';
import PropTypes from 'prop-types';
import {MapContainer,Polyline,TileLayer} from 'react-leaflet';

/*JS module import (vs cdn or style link)*/
import 'leaflet/dist/leaflet.css'
import './entities-map.css';

import EntitiesMarker from './entities-marker';

export default function EntitiesMap({entities}) {
    /*lat and lon of Braunschweig,DE*/
    const position = [52.26594, 10.52673]
    return (
	<>
	    <MapContainer
		center={position}
		zoom={8}
		minZoom={2}
		scrollWheelZoom={false}
	    >
		<TileLayer
		    attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
		    url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
		/>
		{
		    entities.map(function(value,key) {
			//console.log(`key: ${key}, tripId: ${value.tripId}`);
			return <EntitiesMarker
				   key={value[0]}
				   index={value[0]}
				   name={value[1]}
				   lat={value[2]}
				   lon={value[3]}
			       />;
                    })
		}
	    </MapContainer>
	</>
    );
}
EntitiesMap.propTypes = {
    entities: PropTypes.array
};
