EugeneBosyakov

Untitled

Feb 10th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. export class OrderMap extends Component {
  3.     componentDidMount() {
  4.  
  5.         const {markers} = this.props;
  6.         const markerCount = markers.length;
  7.         const centralMarker = Math.round(markerCount / 2);
  8.  
  9.         let map = this.map = L.map(ReactDOM.findDOMNode(this), {
  10.             minZoom: 2,
  11.             maxZoom: 20,
  12.             layers: [
  13.                 L.tileLayer(
  14.                     'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  15.                     {
  16.                         attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
  17.                         '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
  18.                     })
  19.             ],
  20.             attributionControl: false,
  21.         }).setView([markers[centralMarker].lat, markers[centralMarker].lng], 4);
  22.  
  23.         for (var i in markers) {
  24.             const alphabet = ['A', 'B', 'C', 'D', 'E', 'F'];
  25.  
  26.             let markerIcon = L.icon.glyph({prefix: '', cssClass: 'sans-serif', glyph: alphabet[i]});
  27.             // getColor(i, markerCount)
  28.  
  29.             var marker = L.marker([markers[i].lat, markers[i].lng], {icon: markerIcon}).addTo(map);
  30.         }
  31.  
  32.         map.on('click', this.onMapClick);
  33.         //map.fitWorld();
  34.     }
  35.  
  36.     componentWillUnmount() {
  37.         this.map.off('click', this.onMapClick);
  38.         this.map = null;
  39.     }
  40.  
  41.     onMapClick() {
  42.         // Do some wonderful map things...
  43.     }
  44.  
  45.     render() {
  46.         return (
  47.             <div className='ordermap'></div>
  48.         );
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment