var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};

// packages/plugins/roadnet-layer/src/roadNetLayer.ts
import { Element } from "@ktmap/map";
import { BufferGeometry, Line, LineBasicMaterial, Vector3 } from "three";
var RoadNetLayer = class extends Element {
  constructor(options) {
    super();
    this.options = options;
  }
  __init() {
    console.log("RoadNetLayer init success");
    this.initData(this.drawRoadNet.bind(this));
  }
  initData(cb) {
    return __async(this, null, function* () {
      const { data } = this.options;
      if (typeof data === "function") {
        try {
          const res = yield data();
          console.log("resresresres :>> ", res);
          cb == null ? void 0 : cb(res);
        } catch (_) {
        }
      } else {
        cb == null ? void 0 : cb(data);
      }
    });
  }
  drawRoadNet(data) {
    const { map } = this;
    for (const item of data) {
      item.begin[0] = +item.begin[0];
      item.begin[1] = +item.begin[1];
      item.end[0] = +item.end[0];
      item.end[1] = +item.end[1];
      const { begin, end, id } = item;
      this.drawNormalLine(
        [new Vector3(...begin, 0), new Vector3(...end, 0)],
        {
          name: "ar_roadNetPath",
          color: "red"
        }
      );
    }
    map.reDraw();
  }
  drawNormalLine(points, ext) {
    const { map } = this;
    const line = new Line(
      new BufferGeometry().setFromPoints(points),
      new LineBasicMaterial({
        color: (ext == null ? void 0 : ext.color) || "red",
        opacity: 1,
        transparent: true,
        depthTest: false
      })
    );
    line.name = (ext == null ? void 0 : ext.name) || "";
    line.userData = {};
    map.scene.add(line);
  }
};
__publicField(RoadNetLayer, "NAME", "RoadNetLayer");
export {
  RoadNetLayer
};
//# sourceMappingURL=roadnet-layer.esm-bundler.js.map
