@wayz/react-gl
Version:
React Component for DeckGL, Base on AMap, Mapbox GL
42 lines (41 loc) • 1.4 kB
JavaScript
// @ts-nocheck
var Tag = /** @class */ (function () {
function Tag(label) {
this.label = label;
this.coords = [];
// center of coords
this.center = [0, 0];
this.weight = 0;
// size of bounding box
this.width = 0;
this.height = 0;
}
// loc: screen coords [x, y]
Tag.prototype.add = function (loc, weight) {
var _a = this, coords = _a.coords, center = _a.center;
coords.push(loc);
var len = coords.length;
// update center
center[0] = (center[0] * (len - 1) + loc[0]) / len;
center[1] = (center[1] * (len - 1) + loc[1]) / len;
// update weight
this.weight += weight;
};
Tag.prototype.setCenter = function (pt) {
// force set center in the overlap removal loop
this.center = pt;
};
Tag.prototype.setSize = function (width, height) {
this.width = width;
this.height = height;
};
Tag.prototype.dist = function (loc) {
return Math.sqrt(Math.pow(this.center[0] - loc[0], 2) + Math.pow(this.center[1] - loc[1], 2));
};
Tag.prototype.overlap = function (tag) {
return (Math.abs(tag.center[0] - this.center[0]) <= (tag.width + this.width) * 0.5 &&
Math.abs(tag.center[1] - this.center[1]) <= (tag.height + this.height) * 0.5);
};
return Tag;
}());
export default Tag;