aboutsummaryrefslogtreecommitdiff
path: root/modern/src/MainMap.js
blob: ff51b56ed23b75c967722f6b9a3c5d1a29c976e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'ol/ol.css';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Map, View } from 'ol';
import { fromLonLat } from 'ol/proj';
import olms from 'ol-mapbox-style';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';

const mapStateToProps = state => ({
  positions: state.positions
});

class MainMap extends Component {
  componentDidMount() {
    this.map = new Map({
      target: this.el,
      view: new View({
        constrainResolution: true,
        center: fromLonLat([25.65, 60.98]),
        zoom: 9
      })
    });
    if (location.hostname === 'localhost') {
      olms(this.map, 'https://cdn.traccar.com/map/basic.json');
    } else {
      this.map.addLayer(
        new TileLayer({
          source: new OSM()
        })
      );
    }
  }

  render() {
    const style = {
      position: 'relative',
      overflow: 'hidden',
      width: '100%',
      height: '100%'
    };
    return <div style={style} ref={el => this.el = el} />;
  }
}

export default connect(mapStateToProps)(MainMap);