@tuoyuan/map-adapter-lib
Version:
地图适配器库
175 lines (174 loc) • 4.61 kB
JavaScript
var P = Object.defineProperty;
var S = (l, s, e) => s in l ? P(l, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[s] = e;
var i = (l, s, e) => S(l, typeof s != "symbol" ? s + "" : s, e);
import { deepAssign as o } from "../utils/deep-assign.js";
import { isPointInPolygon as x } from "../utils/is-pointIn-polygon.js";
import { EventBus as B } from "./MapEvent.js";
import { Position as f } from "./Position.js";
import { Label as g } from "./Label.js";
class A extends B {
constructor(e, t, a) {
var h, n, b, _, r, d, m, c, p, w, y, L, u;
super();
i(this, "_top");
/** ID */
i(this, "_id");
/** 名称 */
i(this, "_name");
/** 路径 */
i(this, "_path");
/** 样式 */
i(this, "_style");
/** 图标 */
i(this, "_icon");
/** 文本标签 */
i(this, "_label");
/** 业务数据 */
i(this, "_data");
/** 是否可见 */
i(this, "_visible");
/** label基础方位 */
i(this, "_labelBasePlacement", "center");
this._top = e, this._labelBasePlacement = a.labelBasePlacement ?? "center", this._id = t.id, this._name = t.name, this._path = t.path.map((v) => new f(...v)), this._visible = t.visible ?? !0, this._data = t.data, this._style = o({}, e.options.style.polygon, {
line: {
style: (n = (h = t.style) == null ? void 0 : h.line) == null ? void 0 : n.style,
color: (_ = (b = t.style) == null ? void 0 : b.line) == null ? void 0 : _.color,
width: (d = (r = t.style) == null ? void 0 : r.line) == null ? void 0 : d.width,
opacity: (c = (m = t.style) == null ? void 0 : m.line) == null ? void 0 : c.opacity
},
fill: {
color: (w = (p = t.style) == null ? void 0 : p.fill) == null ? void 0 : w.color,
opacity: (L = (y = t.style) == null ? void 0 : y.fill) == null ? void 0 : L.opacity
}
}), this._label = this.genLabel(
this._top,
o(
{},
this._top.options.label,
this._top.options.style.polygon.label,
t.label,
(u = t.style) == null ? void 0 : u.label
)
), this._label.listenAndUpdateVisible({
showLabel: this.showLabel.bind(this),
hiddenLabel: this.hiddenLabel.bind(this)
});
}
genLabel(e, t) {
return new g(e, {
canShow: t.visible !== !1,
minShowZoom: t.minShowZoom,
color: t.color,
backgroundColor: t.backgroundColor,
fontSize: t.fontSize,
placement: t.placement,
visible: t.visible,
text: t.text,
basePlacement: this._labelBasePlacement
});
}
/** ID */
get id() {
return this._id;
}
/** 名称 */
get name() {
return this._name;
}
/** 位置 */
get path() {
return this._path;
}
/** 图标 */
get icon() {
return this._icon;
}
/** 业务数据 */
get data() {
return this._data;
}
/**
* 设置名称
* @param name 名称
*/
setName(e) {
this._name = e;
}
/**
* 设置路径
* @param path 路径
*/
setPath(e) {
this._path = e.map((t) => new f(...t));
}
/**
* 设置样式
* @param style 样式
*/
setStyle(e) {
var t, a, h, n;
this._style = o({}, this._style, e), this._label = this.genLabel(
this._top,
o(
{},
this._top.options.label,
this._top.options.style.polygon.label,
{
text: (t = this._label) == null ? void 0 : t.text,
minShowZoom: (a = this._label) == null ? void 0 : a.minShowZoom,
visible: (h = this._label) == null ? void 0 : h.visible
},
(n = this._style) == null ? void 0 : n.label
)
), this._label.listenAndUpdateVisible({
showLabel: this.showLabel.bind(this),
hiddenLabel: this.hiddenLabel.bind(this)
});
}
/**
* 设置业务数据
* @param data 业务数据
*/
setData(e) {
this._data = e;
}
/**
* 显示,icon、label
*/
show() {
var e;
this._visible = !0, (e = this._label) != null && e.canShow && this.showLabel();
}
/**
* 隐藏,icon、label
*/
hidden() {
this._visible = !1, this.hiddenLabel();
}
/**
* 显示label
*/
showLabel() {
var e, t;
(t = (e = this._label) == null ? void 0 : e.setVisible) == null || t.call(e, !0);
}
/**
* 隐藏label
*/
hiddenLabel() {
var e, t;
(t = (e = this._label) == null ? void 0 : e.setVisible) == null || t.call(e, !1);
}
/**
* 判断坐标是否在多边形内
*/
contains(e) {
return x(e, this._path);
}
}
class D extends A {
}
export {
D as AbstractPolygon,
A as BasePolygon
};