all files / candela/components/Geo/ index.js

73.77% Statements 45/61
84.62% Branches 33/39
61.54% Functions 8/13
29.41% Lines 5/17
11 statements, 2 functions, 18 branches Ignored     
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 47 48 49 50 51                                                                                              
import geojs from 'geojs/geo.js';
import VisComponent from '../../VisComponent';
 
export default class Geo extends VisComponent {
  constructor (el, {map = {}, layers = []}) {
    super(el);
 
    // Construct a GeoJS map object based on the requested options.
    this.plot = geojs.map(Object.assign({
      node: el
    }, map));
 
    // Process the requested layers.
    layers.forEach(layer => {
      switch (layer.type) {
        case 'osm':
          this.plot.createLayer('osm', layer);
          break;
 
        case 'feature':
          layer.features.forEach(spec => {
            let feature = this.plot.createLayer('feature', {
              renderer: 'd3'
            })
              .createFeature(spec.type)
              .data(spec.data)
              .position(d => ({
                x: d[spec.x],
                y: d[spec.y]
              }));
 
            const style = Object.assign({
              fillColor: 'red',
              strokeColor: 'darkred'
            }, spec.style);
 
            feature.style(style);
          });
          break;
      }
    });
 
    this.render();
  }
 
  render () {
    this.plot.draw();
  }
}