Code coverage report for lib/Map.js

Statements: 81.44% (79 / 97)      Branches: 61.54% (32 / 52)      Functions: 93.75% (15 / 16)      Lines: 94.23% (49 / 52)      Ignored: none     

All files » lib/ » Map.js
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128    2       12   9   14   5   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2 6     2 2 5   5 5         2   2     4 4 4         3 3 3 3         5 5 5   5 1 4                         10 10 1     10                                         2     2 2
'use strict';
 
Object.defineProperty(exports, '__esModule', {
  value: true
});
 
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Eif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
 
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; var desc = Object.getOwnPropertyDescriptor(object, property); Iif (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else Eif ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
 
function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) subClass.__proto__ = superClass; }
 
var _lodashLangIsArray = require('lodash/lang/isArray');
 
var _lodashLangIsArray2 = _interopRequireDefault(_lodashLangIsArray);
 
var _lodashUtilityUniqueId = require('lodash/utility/uniqueId');
 
var _lodashUtilityUniqueId2 = _interopRequireDefault(_lodashUtilityUniqueId);
 
var _react = require('react');
 
var _react2 = _interopRequireDefault(_react);
 
var _leaflet = require('leaflet');
 
var _leaflet2 = _interopRequireDefault(_leaflet);
 
var _typesBounds = require('./types/bounds');
 
var _typesBounds2 = _interopRequireDefault(_typesBounds);
 
var _typesLatlng = require('./types/latlng');
 
var _typesLatlng2 = _interopRequireDefault(_typesLatlng);
 
var _MapComponent2 = require('./MapComponent');
 
var _MapComponent3 = _interopRequireDefault(_MapComponent2);
 
var normalizeCenter = function normalizeCenter(pos) {
  return (0, _lodashLangIsArray2['default'])(pos) ? pos : [pos.lat, pos.lng || pos.lon];
};
 
var Map = (function (_MapComponent) {
  function Map(props) {
    _classCallCheck(this, Map);
 
    _get(Object.getPrototypeOf(Map.prototype), 'constructor', this).call(this, props);
    this.state = {
      id: props.id || (0, _lodashUtilityUniqueId2['default'])('map')
    };
  }
 
  _inherits(Map, _MapComponent);
 
  _createClass(Map, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.leafletElement = _leaflet2['default'].map(this.state.id, this.props);
      _get(Object.getPrototypeOf(Map.prototype), 'componentDidMount', this).call(this);
      this.setState({ map: this.leafletElement });
    }
  }, {
    key: 'shouldUpdateCenter',
    value: function shouldUpdateCenter(next, prev) {
      Iif (!prev) return true;
      next = normalizeCenter(next);
      prev = normalizeCenter(prev);
      return next[0] !== prev[0] || next[1] !== prev[1];
    }
  }, {
    key: 'componentDidUpdate',
    value: function componentDidUpdate(prevProps) {
      var _props = this.props;
      var center = _props.center;
      var zoom = _props.zoom;
 
      if (center && this.shouldUpdateCenter(center, prevProps.center)) {
        this.leafletElement.setView(center, zoom, { animate: false });
      } else Iif (zoom && zoom !== prevProps.zoom) {
        this.leafletElement.setZoom(zoom);
      }
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      _get(Object.getPrototypeOf(Map.prototype), 'componentWillUnmount', this).call(this);
      this.leafletElement.remove();
    }
  }, {
    key: 'render',
    value: function render() {
      var map = this.leafletElement;
      var children = map ? _react2['default'].Children.map(this.props.children, function (child) {
        return child ? _react2['default'].cloneElement(child, { map: map }) : null;
      }) : null;
 
      return _react2['default'].createElement(
        'div',
        { className: this.props.className, id: this.state.id, style: this.props.style },
        children
      );
    }
  }], [{
    key: 'propTypes',
    value: {
      center: _typesLatlng2['default'],
      className: _react.PropTypes.string,
      id: _react.PropTypes.string,
      maxBounds: _typesBounds2['default'],
      maxZoom: _react.PropTypes.number,
      minZoom: _react.PropTypes.number,
      style: _react.PropTypes.object,
      zoom: _react.PropTypes.number
    },
    enumerable: true
  }]);
 
  return Map;
})(_MapComponent3['default']);
 
exports['default'] = Map;
module.exports = exports['default'];