PathSimplifier.js 4.33 KB
Newer Older
DarkForst's avatar
DarkForst committed
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 129 130 131 132 133 134 135 136 137
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Base = require('../../Base');

var _Base2 = _interopRequireDefault(_Base);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var PathSimplifier = function (_UIBase) {
  (0, _inherits3.default)(PathSimplifier, _UIBase);

  function PathSimplifier() {
    (0, _classCallCheck3.default)(this, PathSimplifier);
    return (0, _possibleConstructorReturn3.default)(this, (PathSimplifier.__proto__ || Object.getPrototypeOf(PathSimplifier)).apply(this, arguments));
  }

  (0, _createClass3.default)(PathSimplifier, [{
    key: 'componentWillMount',
    value: function componentWillMount() {
      this.instanceName = 'pathSimplifier';
    }
  }, {
    key: 'initialInstance',
    value: function initialInstance() {
      var _this2 = this;

      var _props$eventSupport = this.props.eventSupport,
          eventSupport = _props$eventSupport === undefined ? false : _props$eventSupport;

      if (this[this.instanceName]) {
        return new Promise(function (resolve) {
          resolve(_this2[_this2.instanceName]);
        });
      } else {
        return new Promise(function (resolve) {

          _this2.amapui.load(['ui/misc/PathSimplifier'], function (PathSimplifier) {

            _this2[_this2.instanceName] = new PathSimplifier({
              zIndex: 100,
              map: _this2.map, //所属的地图实例
              getPath: function getPath(pathData, pathIndex) {
                //返回轨迹数据中的节点坐标信息,[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
                return pathData.path;
              },
              getHoverTitle: function getHoverTitle(pathData, pathIndex, pointIndex) {
                //返回鼠标悬停时显示的信息
                if (pointIndex >= 0) {
                  //鼠标悬停在某个轨迹节点上
                  return pathData.name + ',点:' + pointIndex + '/' + pathData.path.length;
                }
                //鼠标悬停在节点之间的连线上
                return pathData.name + ',点数量' + pathData.path.length;
              },
              renderOptions: {
                //轨迹线的样式
                pathLineStyle: {
                  strokeStyle: 'red',
                  lineWidth: 6,
                  dirArrowStyle: true
                }
              }
            });

            var events = _this2.exposeInstance(_this2.props);
            events && _this2.bindEvents(events);

            _this2.initPage(PathSimplifier);
            resolve(_this2[_this2.instanceName]);
          });
        });
      }
    }

    // render AllPage

  }, {
    key: 'initPage',
    value: function initPage(PathSimplifier) {

      this.pathSimplifier.setData([{
        name: '轨迹0',
        path: [[100.340417, 27.376994], [108.426354, 37.827452], [113.392174, 31.208439], [124.905846, 42.232876]]
      }, {
        name: '大地线',
        //创建一条包括500个插值点的大地线
        path: PathSimplifier.getGeodesicPath([116.405289, 39.904987], [87.61792, 43.793308], 500)
      }]);

      //创建一个巡航器
      var navg0 = this.pathSimplifier.createPathNavigator(0, //关联第1条轨迹
      {
        loop: true, //循环播放
        speed: 1000000
      });

      navg0.start();
    }
    // render accoding to areaNode

  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      console.log(this.instanceName + ' unmount');
      this[this.instanceName].hide();
      delete this[this.instanceName];
    }
  }]);
  return PathSimplifier;
}(_Base2.default);

exports.default = PathSimplifier;
module.exports = exports['default'];