"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _arrow = _interopRequireDefault(require("../assets/arrow.png"));
var _geom = require("ol/geom");
var _style = require("ol/style");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var _default = exports["default"] = function _default(_ref) {
  var feature = _ref.feature,
    resolution = _ref.resolution,
    arrowStyle = _ref.arrowStyle;
  var styles = [];
  var geometry = feature.getGeometry();
  geometry = geometry instanceof _geom.MultiLineString ? geometry.getLineString() : geometry;
  // 获取线段长度
  var length = geometry.getLength();

  // 箭头间隔距离（像素）
  var step = (arrowStyle === null || arrowStyle === void 0 ? void 0 : arrowStyle.step) || 100;

  // 将间隔像素距离转换成地图的真实距离
  var StepLength = step * resolution;

  // 得到一共需要绘制多少个 箭头
  var arrowNum = Math.floor(length / StepLength);
  var rotations = [];
  var distances = [0];
  geometry.forEachSegment(function (start, end) {
    var dx = end[0] - start[0];
    var dy = end[1] - start[1];
    var rotation = Math.atan2(dy, dx);
    distances.unshift(Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)) + distances[0]);
    rotations.push(rotation);
  });

  // 利用之前计算得到的线段矢量信息，生成对应的点样式塞入默认样式中
  // 从而绘制内部箭头
  var _loop = function _loop() {
    var arrowCoord = geometry.getCoordinateAt(i / arrowNum);
    var d = i * StepLength;
    var grid = distances.findIndex(function (x) {
      return x <= d;
    });
    styles.push(new _style.Style({
      geometry: new _geom.Point(arrowCoord),
      image: new _style.Icon(_objectSpread({
        src: _arrow["default"],
        opacity: 1,
        anchor: [0.5, 0.5],
        rotateWithView: false,
        // 读取 rotations 中计算存放的方向信息
        rotation: -rotations[distances.length - grid - 1],
        scale: 1
      }, arrowStyle))
    }));
  };
  for (var i = 1; i < arrowNum; ++i) {
    _loop();
  }
  return styles;
};
//# sourceMappingURL=getPathLineStyles.js.map
