UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

58 lines (48 loc) 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.clearMapSource = exports.getMapSource = exports.unregisterMapSource = exports.registerMapSource = exports.geoSourceMap = void 0; const vdataset_1 = require("@visactor/vdataset"), debug_1 = require("../../util/debug"), register_1 = require("../../data/register"), vutils_1 = require("@visactor/vutils"); let mapDataSet; function initMapDataSet() { mapDataSet || (mapDataSet = new vdataset_1.DataSet, (0, register_1.registerDataSetInstanceParser)(mapDataSet, "geojson", vdataset_1.geoJSONParser), (0, register_1.registerDataSetInstanceParser)(mapDataSet, "topojson", vdataset_1.topoJSONParser), (0, register_1.registerDataSetInstanceTransform)(mapDataSet, "simplify", vdataset_1.simplify)); } function registerMapSource(key, source, option = { type: "geojson", centroid: !0 }) { exports.geoSourceMap.has(key) && (0, debug_1.warn)(`map type of '${key}' already exists, will be overwritten.`), initMapDataSet(); const dataView = new vdataset_1.DataView(mapDataSet), options = (0, vutils_1.merge)({}, { centroid: !0, simplify: !1 }, option); "topojson" === option.type ? dataView.parse(source, { type: "topojson", options: options }) : dataView.parse(source, { type: "geojson", options: options }); const {simplify: simplify} = option; !0 === simplify ? dataView.transform({ type: "simplify" }) : (0, vutils_1.isObject)(simplify) && dataView.transform({ type: "simplify", options: simplify }), exports.geoSourceMap.set(key, dataView); } function unregisterMapSource(key) { exports.geoSourceMap.has(key) ? exports.geoSourceMap.delete(key) : (0, debug_1.warn)(`map type of '${key}' does not exists.`); } function getMapSource(type) { return exports.geoSourceMap.get(type); } function clearMapSource() { exports.geoSourceMap.clear(), mapDataSet = null; } exports.geoSourceMap = new Map, exports.registerMapSource = registerMapSource, exports.unregisterMapSource = unregisterMapSource, exports.getMapSource = getMapSource, exports.clearMapSource = clearMapSource; //# sourceMappingURL=geo-source.js.map