@wayz/react-gl
Version:
React Component for DeckGL, Base on AMap, Mapbox GL
89 lines (88 loc) • 4.28 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// @ts-nocheck
import Tag from './tag';
import TagMap from './tagmap';
import ClusterTree from 'hdbscanjs';
var DEFAULT_MAX_DIST = 20;
var CustomTagMap = /** @class */ (function (_super) {
__extends(CustomTagMap, _super);
function CustomTagMap() {
return _super.call(this) || this;
}
CustomTagMap.prototype.buildHierarchy = function (data, _a) {
var _b = _a.getLabel, getLabel = _b === void 0 ? function (val) { return val.label; } : _b, _c = _a.getPosition, getPosition = _c === void 0 ? function (val) { return val.position; } : _c, _d = _a.getWeight, getWeight = _d === void 0 ? function (val) { return val.weight; } : _d;
// clear tree
this.tagTree = {};
var _e = this, tagTree = _e.tagTree, distFunc = _e.distFunc;
// group tags based on the content
for (var _i = 0, _f = Object.entries(data); _i < _f.length; _i++) {
var _g = _f[_i], val = _g[1];
var label = getLabel(val);
// 相同label只添加一次
if (!tagTree.hasOwnProperty(label)) {
tagTree[label] = [];
tagTree[label].push({ data: getPosition(val), opt: getWeight(val) });
tagTree[label].originValue = val;
}
}
for (var _h = 0, _j = Object.entries(tagTree); _h < _j.length; _h++) {
var _k = _j[_h], key = _k[0], tag = _k[1];
var cluster = new ClusterTree(tag, distFunc);
tagTree[key] = cluster.getTree();
tagTree[key].originValue = tag.originValue;
}
};
CustomTagMap.prototype.extractCluster = function (_a) {
var _b = _a.project, project = _b === void 0 ? function (val) { return val; } : _b, _c = _a.bbox, bbox = _c === void 0 ? null : _c, _d = _a.weightThreshold, weightThreshold = _d === void 0 ? 0 : _d, _e = _a.maxDist, maxDist = _e === void 0 ? DEFAULT_MAX_DIST : _e;
// clear tagList
this.tagList = [];
var _f = this, tagTree = _f.tagTree, tagList = _f.tagList;
var maxDistSq = maxDist * maxDist;
for (var _i = 0, _g = Object.entries(tagTree); _i < _g.length; _i++) {
var _h = _g[_i], key = _h[0], tree = _h[1];
var flagCluster = tree.filter(function (val) {
// a cluster of a single point
if (val.isLeaf) {
return true;
}
// test the cluster does not split under the current zoom level
var cp0 = project(val.edge[0]);
var cp1 = project(val.edge[1]);
var dx = cp0[0] - cp1[0];
var dy = cp0[1] - cp1[1];
return dx * dx + dy * dy < maxDistSq;
}, bbox);
var _loop_1 = function (val) {
var tag = new Tag(key);
val.data.forEach(function (p, i) { return tag.add(p, val.opt[i]); });
if (tag.weight >= weightThreshold) {
tag.setCenter(project(tag.center));
Object.assign(tag, { originValue: val.originValue });
tagList.push(tag);
}
};
// generate tags which passed the test and weightThreshold
for (var _j = 0, _k = Object.entries(flagCluster); _j < _k.length; _j++) {
var _l = _k[_j], val = _l[1];
_loop_1(val);
}
}
return tagList;
};
return CustomTagMap;
}(TagMap));
export default CustomTagMap;